]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
building rpms from source doc improvements
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 8 Nov 2023 12:37:33 +0000 (13:37 +0100)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Wed, 8 Nov 2023 14:18:17 +0000 (15:18 +0100)
- Use env --chdir= instead of spawning a shell
- Document that scripts are executed in the same directory that
  mkosi is running in and get rid of all uses of $SRCDIR and
  $CHROOT_SRCDIR in favor of relative paths. We have to use $PWD
  when actually building the rpm as some macros expect the topdir
  to be an absolute path.

docs/building-rpms-from-source.md
mkosi/resources/mkosi.md

index 7a84d4912710955814d46912cb7214567abb021f..ebcfc72449232958e4112a92e90fef849e434090 100644 (file)
@@ -65,30 +65,30 @@ mkosi-chroot \
     rpmspec \
     --query \
     "$DEPS" \
-    --define "_topdir $CHROOT_SRCDIR/mkosi" \
-    --define "_sourcedir $CHROOT_SRCDIR/mkosi/rpm" \
-    "$CHROOT_SRCDIR/mkosi/rpm/mkosi.spec" |
+    --define "_topdir mkosi" \
+    --define "_sourcedir mkosi/rpm" \
+    mkosi/rpm/mkosi.spec |
         grep -E -v "mkosi" |
         xargs -d '\n' dnf install --best
 
 if [ "$1" = "build" ]; then
     until mkosi-chroot \
-        sh -c 'cd $CHROOT_SRCDIR/mkosi && exec $0 "$@"' \
+        env --chdir=mkosi \
         rpmbuild \
         -bd \
         --build-in-place \
-        --define "_topdir $CHROOT_SRCDIR/mkosi" \
-        --define "_sourcedir $CHROOT_SRCDIR/mkosi/rpm" \
+        --define "_topdir ." \
+        --define "_sourcedir rpm" \
         --define "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
-        "$CHROOT_SRCDIR/mkosi/rpm/mkosi.spec"
+        rpm/mkosi.spec
     do
         EXIT_STATUS=$?
         if [ $EXIT_STATUS -ne 11 ]; then
             exit $EXIT_STATUS
         fi
 
-        dnf builddep "$SRCDIR"/mkosi/SRPMS/mkosi-*.buildreqs.nosrc.rpm
-        rm "$SRCDIR"/mkosi/SRPMS/mkosi-*.buildreqs.nosrc.rpm
+        dnf builddep mkosi/SRPMS/mkosi-*.buildreqs.nosrc.rpm
+        rm mkosi/SRPMS/mkosi-*.buildreqs.nosrc.rpm
     done
 fi
 ```
@@ -128,19 +128,18 @@ output directory (stored in `$OUTPUTDIR`). The build script
 #!/bin/sh
 set -e
 
-cd "$SRCDIR/mkosi"
-
-rpmbuild \
+env --chdir=mkosi \
+    rpmbuild \
     -bb \
     --build-in-place \
     $([ "$WITH_TESTS" = "0" ] && echo --nocheck) \
-    --define "_topdir $SRCDIR/mkosi" \
-    --define "_sourcedir $SRCDIR/mkosi/rpm" \
+    --define "_topdir $PWD" \
+    --define "_sourcedir rpm" \
     --define "_rpmdir $OUTPUTDIR" \
     ${BUILDDIR:+--define} \
     ${BUILDDIR:+"_vpath_builddir $BUILDDIR"} \
     --define "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
-    "$SRCDIR/mkosi/rpm/mkosi.spec"
+    rpm/mkosi.spec
 ```
 
 The `_vpath_builddir` directory will be used to store out-of-tree build
index 3cb16f2e1b8cb2fc8e26d669eecb4ccb808829f1..94718651d6f2d9a32ccac10277b6552433718800 100644 (file)
@@ -1534,8 +1534,8 @@ root or root within the user namespace that mkosi created when running
 unprivileged) with a customized environment to simplify modifying the
 image. For each script, the configured build sources (`BuildSources=`)
 are mounted into the current working directory before running the script
-and `$SRCDIR` is set to point to the current working directory. The
-following scripts are supported:
+in the current working directory. `$SRCDIR` is set to point to the
+current working directory. The following scripts are supported:
 
 * If **`mkosi.prepare`** (`PrepareScripts=`) exists, it is first called
   with the `final` argument, right after the software packages are