]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mkosi: Make scripts more generic
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 8 Apr 2024 10:52:56 +0000 (12:52 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 9 Apr 2024 09:57:05 +0000 (11:57 +0200)
We might want to run the build scripts outside of mkosi as well at
some point, e.g. to build an rpm after booting the image, so let's
make them more generic by using /usr/lib/os-release to figure out
which pkg specs we should use instead of $PKG_SUBDIR. To make ubuntu
use the debian pkg spec, we add a symlink pkg/ubuntu which points to
debian/ in the same directory.

15 files changed:
mkosi.images/system/mkosi.conf.d/10-arch/mkosi.build.chroot
mkosi.images/system/mkosi.conf.d/10-arch/mkosi.conf
mkosi.images/system/mkosi.conf.d/10-arch/mkosi.prepare
mkosi.images/system/mkosi.conf.d/10-centos-fedora/mkosi.build.chroot
mkosi.images/system/mkosi.conf.d/10-centos-fedora/mkosi.prepare
mkosi.images/system/mkosi.conf.d/10-centos/mkosi.conf
mkosi.images/system/mkosi.conf.d/10-debian-ubuntu/mkosi.build.chroot
mkosi.images/system/mkosi.conf.d/10-debian-ubuntu/mkosi.conf
mkosi.images/system/mkosi.conf.d/10-debian-ubuntu/mkosi.prepare
mkosi.images/system/mkosi.conf.d/10-fedora/mkosi.conf
mkosi.images/system/mkosi.conf.d/10-opensuse/mkosi.build.chroot
mkosi.images/system/mkosi.conf.d/10-opensuse/mkosi.conf
mkosi.images/system/mkosi.conf.d/10-opensuse/mkosi.prepare
mkosi.images/system/mkosi.sync
pkg/ubuntu [new symlink]

index 9cdee05b185595cb7bb5f1fcea433386072ace64..807823205f16daa1da2542a3c89d45db8ffab734 100755 (executable)
@@ -2,17 +2,20 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 set -ex
 
-if [ ! -f "pkg/$PKG_SUBDIR/PKGBUILD" ]; then
-    echo "PKGBUILD not found at pkg/$PKG_SUBDIR/PKGBUILD, run mkosi once with -ff to make sure the PKGBUILD is cloned" >&2
+# shellcheck source=/dev/null
+. /usr/lib/os-release
+
+if [ ! -f "pkg/$ID/PKGBUILD" ]; then
+    echo "PKGBUILD not found at pkg/$ID/PKGBUILD, run mkosi once with -ff to make sure the PKGBUILD is cloned" >&2
     exit 1
 fi
 
 # We can't configure the source or build directory so we use bind mounts instead to make sure they are in the
 # expected locations.
-mount --mkdir --bind "$SRCDIR" "pkg/$PKG_SUBDIR/systemd-stable/"
-mount --mkdir --bind "$BUILDDIR" "pkg/$PKG_SUBDIR/build/"
+mount --mkdir --bind "$SRCDIR" "pkg/$ID/systemd-stable/"
+mount --mkdir --bind "$BUILDDIR" "pkg/$ID/build/"
 # Because we run with --noextract we are responsible for making sure the source files appear in src/.
-mount --mkdir --rbind "$PWD/pkg/$PKG_SUBDIR" "pkg/$PKG_SUBDIR/src/"
+mount --mkdir --rbind "$PWD/pkg/$ID" "pkg/$ID/src/"
 
 # shellcheck source=/dev/null
 . /etc/makepkg.conf
@@ -35,13 +38,13 @@ else
     TS="${SOURCE_DATE_EPOCH:-$(date +%s)}"
 fi
 
-sed --in-place "pkg/$PKG_SUBDIR/PKGBUILD" \
+sed --in-place "pkg/$ID/PKGBUILD" \
     --expression "s/^_tag=.*/_tag=$(cat meson.version)/" \
     --expression "s/^pkgrel=.*/pkgrel=$(date "+%Y%m%d%H%M%S" --date "@$TS")/"
 
 # We get around makepkg's root check by setting EUID to something else.
 # shellcheck disable=SC2046
-env --chdir="pkg/$PKG_SUBDIR" \
+env --chdir="pkg/$ID" \
     EUID=123 \
     makepkg \
     --noextract \
@@ -49,7 +52,7 @@ env --chdir="pkg/$PKG_SUBDIR" \
     --force \
     _systemd_UPSTREAM=1 \
     _systemd_QUIET=1 \
-    BUILDDIR="$PWD/pkg/$PKG_SUBDIR" \
+    BUILDDIR="$PWD/pkg/$ID" \
     PKGDEST="$OUTPUTDIR" \
     PKGEXT=".pkg.tar" \
     MESON_EXTRA_CONFIGURE_OPTIONS="-D mode=developer -D b_sanitize=${SANITIZERS:-none}"
index d11b932a02734320df6a2699a0cc2357a72a0112..06dec482d25f74822cc97831cc9878d4a49dc5b9 100644 (file)
@@ -10,7 +10,6 @@ InitrdInclude=initrd/
 # https://gitlab.archlinux.org/archlinux/packaging/packages/systemd/-/merge_requests/8 is merged.
 [Content]
 Environment=
-        PKG_SUBDIR="arch"
         SYSTEMD_PACKAGES="systemd systemd-ukify systemd-sysvcompat systemd-resolvconf systemd-tests"
 
 Packages=
index dd4ac96cb9b135be4ccef87cdad188a954abf368..8ed5c7531cb2893f1567e5292e20ade32ffc8b60 100755 (executable)
@@ -6,13 +6,16 @@ if [ "$1" = "build" ]; then
     exit 0
 fi
 
-if [ ! -f "pkg/$PKG_SUBDIR/PKGBUILD" ]; then
-    echo "PKGBUILD not found at pkg/$PKG_SUBDIR/PKGBUILD, run mkosi once with -ff to make sure the PKGBUILD is cloned" >&2
+# shellcheck source=/dev/null
+. "$BUILDROOT/usr/lib/os-release"
+
+if [ ! -f "pkg/$ID/PKGBUILD" ]; then
+    echo "PKGBUILD not found at pkg/$ID/PKGBUILD, run mkosi once with -ff to make sure the PKGBUILD is cloned" >&2
     exit 1
 fi
 
 # We get depends and optdepends from .SRCINFO as getting them from the PKGBUILD is rather complex.
-sed --expression 's/^[ \t]*//' "pkg/$PKG_SUBDIR/.SRCINFO" |
+sed --expression 's/^[ \t]*//' "pkg/$ID/.SRCINFO" |
     grep --regexp '^depends =' --regexp '^optdepends =' |
     sed --expression 's/^depends = //' --expression 's/^optdepends = //' --expression 's/:.*//' |
     xargs --delimiter '\n' mkosi-install
@@ -20,7 +23,7 @@ sed --expression 's/^[ \t]*//' "pkg/$PKG_SUBDIR/.SRCINFO" |
 # We get makedepends from the PKGBUILD as .SRCINFO can't encode conditional dependencies depending on
 # whether some environment variable is set or not.
 # shellcheck source=/dev/null
-_systemd_UPSTREAM=1 . "pkg/$PKG_SUBDIR/PKGBUILD"
+_systemd_UPSTREAM=1 . "pkg/$ID/PKGBUILD"
 
 # shellcheck disable=SC2154
 mkosi-install "${makedepends[@]}"
index 66bcff92d75bd9c892d125413f2c99b2bcc04040..242fc4aa407586aa77b884a35bdf8a3f8af4c6d4 100755 (executable)
@@ -2,8 +2,11 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 set -e
 
-if [ ! -f "pkg/$PKG_SUBDIR/systemd.spec" ]; then
-    echo "spec not found at pkg/$PKG_SUBDIR/systemd.spec, run mkosi once with -ff to make sure the spec is cloned" >&2
+# shellcheck source=/dev/null
+. /usr/lib/os-release
+
+if [ ! -f "pkg/$ID/systemd.spec" ]; then
+    echo "spec not found at pkg/$ID/systemd.spec, run mkosi once with -ff to make sure the spec is cloned" >&2
     exit 1
 fi
 
@@ -23,7 +26,7 @@ rpmbuild \
     $( ((WITH_TESTS)) || echo "--nocheck") \
     $( ((WITH_DOCS))  || echo "--without docs") \
     --define "_topdir /var/tmp" \
-    --define "_sourcedir pkg/$PKG_SUBDIR" \
+    --define "_sourcedir pkg/$ID" \
     --define "_rpmdir $OUTPUTDIR" \
     ${BUILDDIR:+--define} \
     ${BUILDDIR:+"_vpath_builddir $BUILDDIR"} \
@@ -45,6 +48,6 @@ rpmbuild \
     --define "__elf_exclude_path ^/usr/lib/systemd/tests/unit-tests/.*$" \
     --define "__script_requires %{nil}" \
     --undefine _lto_cflags \
-    "pkg/$PKG_SUBDIR/systemd.spec"
+    "pkg/$ID/systemd.spec"
 
 cp "$OUTPUTDIR"/*.rpm "$PACKAGEDIR"
index dd78f730eacd8b99ba6166948bacbcc5d79ecdc4..8b10b242e0e2ee7392425c87b95e2ead83bda167 100755 (executable)
@@ -6,8 +6,11 @@ if [ "$1" = "build" ]; then
     exit 0
 fi
 
-if [ ! -f "pkg/$PKG_SUBDIR/systemd.spec" ]; then
-    echo "spec not found at pkg/$PKG_SUBDIR/systemd.spec, run mkosi with -ff to make sure the spec is cloned" >&2
+# shellcheck source=/dev/null
+. "$BUILDROOT/usr/lib/os-release"
+
+if [ ! -f "pkg/$ID/systemd.spec" ]; then
+    echo "spec not found at pkg/$ID/systemd.spec, run mkosi with -ff to make sure the spec is cloned" >&2
     exit 1
 fi
 
@@ -18,8 +21,8 @@ for DEPS in --requires --buildrequires; do
         --query \
         "$DEPS" \
         --define "_topdir /var/tmp" \
-        --define "_sourcedir pkg/$PKG_SUBDIR" \
-        "pkg/$PKG_SUBDIR/systemd.spec" |
+        --define "_sourcedir pkg/$ID" \
+        "pkg/$ID/systemd.spec" |
             grep --invert-match --regexp systemd --regexp /bin/sh --regexp "rpmlib(" --regexp udev |
             sort --unique |
             tee /tmp/buildrequires |
@@ -29,7 +32,7 @@ done
 # rpmbuild -br tries to build a source package which means all source files have to exist which isn't the
 # case when using --build-in-place so we get rid of the source file that doesn't exist to make it happy.
 # TODO: Use -bd instead of -br and get rid of this once we don't need to build on CentOS Stream 9 anymore.
-sed '/Source0/d' --in-place "pkg/$PKG_SUBDIR/systemd.spec"
+sed '/Source0/d' --in-place "pkg/$ID/systemd.spec"
 
 until mkosi-chroot \
     rpmbuild \
@@ -37,9 +40,9 @@ until mkosi-chroot \
     --build-in-place \
     --with upstream \
     --define "_topdir /var/tmp" \
-    --define "_sourcedir pkg/$PKG_SUBDIR" \
+    --define "_sourcedir pkg/$ID" \
     --define "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
-    "pkg/$PKG_SUBDIR/systemd.spec"
+    "pkg/$ID/systemd.spec"
 do
     EXIT_STATUS=$?
     if [ $EXIT_STATUS -ne 11 ]; then
index 0f57319c2a2f402aaf3e742a9cc7e144bcff36d8..d32eae4952312ecd6e5d0321fb3d525ab67ff11c 100644 (file)
@@ -4,9 +4,6 @@
 Distribution=centos
 
 [Content]
-Environment=
-        PKG_SUBDIR="centos"
-
 Packages=
         kernel-modules # For squashfs support
         rpmautospec-rpm-macros
index e5224b87289587c1d2df77c491d436aa5bfc5790..a811ff05e4b7e73d099667827e5528eb2acc6624 100755 (executable)
@@ -2,13 +2,16 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 set -e
 
-if [ ! -d "pkg/$PKG_SUBDIR/debian" ]; then
-    echo "deb rules not found at pkg/$PKG_SUBDIR/debian, run mkosi once with -ff to make sure the rules are cloned" >&2
+# shellcheck source=/dev/null
+. /usr/lib/os-release
+
+if [ ! -d "pkg/$ID/debian" ]; then
+    echo "deb rules not found at pkg/$ID/debian, run mkosi once with -ff to make sure the rules are cloned" >&2
     exit 1
 fi
 
 # We transplant the debian/ folder from the deb package sources into the upstream sources.
-mount --mkdir --bind "$SRCDIR/pkg/$PKG_SUBDIR/debian" "$SRCDIR"/debian
+mount --mkdir --bind "$SRCDIR/pkg/$ID/debian" "$SRCDIR"/debian
 
 # We hide the patches/ directory by mounting an empty directory on top so they don't get applied.
 TMP=$(mktemp -d)
index 364f7b54ff11d757914ee73f0bcfdcb19030a1ad..9e5ed1e4b4062d6fe9ac15c445604062985f0690 100644 (file)
@@ -9,7 +9,6 @@ InitrdInclude=initrd/
 
 [Content]
 Environment=
-        PKG_SUBDIR="debian"
         SYSTEMD_PACKAGES="systemd
                           systemd-userdbd
                           systemd-oomd
index 47e7f32789df322cfb68e863efd0fcc7127a7e86..c9b69fc2dbbaa87f84e68fcf4525a6bb14185a58 100755 (executable)
@@ -6,10 +6,13 @@ if [ "$1" = "build" ]; then
     exit 0
 fi
 
-if [ ! -d "pkg/$PKG_SUBDIR/debian" ]; then
-    echo "deb rules not found at pkg/$PKG_SUBDIR/debian, run mkosi once with -ff to make sure the rules are cloned" >&2
+# shellcheck source=/dev/null
+. "$BUILDROOT/usr/lib/os-release"
+
+if [ ! -d "pkg/$ID/debian" ]; then
+    echo "deb rules not found at pkg/$ID/debian, run mkosi once with -ff to make sure the rules are cloned" >&2
     exit 1
 fi
 
-cd "pkg/$PKG_SUBDIR"
+cd "pkg/$ID"
 DEB_BUILD_PROFILES="pkg.systemd.upstream" apt-get build-dep .
index e48f9505d74a92176b699917787babab09794d11..8236040c0e230bf9f9784443cb3a28a7c23cc503 100644 (file)
@@ -4,9 +4,6 @@
 Distribution=fedora
 
 [Content]
-Environment=
-        PKG_SUBDIR="fedora"
-
 Packages=
         btrfs-progs
         compsize
index 3d45b43117992820b3beae7b9316f2a6fb9b48d3..62b329998d8f702d912db0edf6a7241e63139530 100755 (executable)
@@ -2,8 +2,12 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 set -e
 
-if [ ! -f "pkg/$PKG_SUBDIR/systemd.spec" ]; then
-    echo "spec not found at pkg/$PKG_SUBDIR/systemd.spec, run mkosi once with -ff to make sure the spec is cloned" >&2
+# shellcheck source=/dev/null
+. /usr/lib/os-release
+ID="${ID%-*}"
+
+if [ ! -f "pkg/$ID/systemd.spec" ]; then
+    echo "spec not found at pkg/$ID/systemd.spec, run mkosi once with -ff to make sure the spec is cloned" >&2
     exit 1
 fi
 
@@ -16,7 +20,7 @@ fi
 # The openSUSE filelists hardcode the manpage compression extension. This causes rpmbuild errors since we
 # disable manpage compression as the files cannot be found. Fix the issue by removing the compression
 # extension.
-find "pkg/$PKG_SUBDIR" -name "files.*" -exec sed --in-place 's/\.gz$//' {} \;
+find "pkg/$ID" -name "files.*" -exec sed --in-place 's/\.gz$//' {} \;
 
 build() {
     # TODO: Replace meson_build and meson_install overrides with "--undefine __meson_verbose" once
@@ -28,7 +32,7 @@ build() {
         --with upstream \
         $( ((WITH_TESTS)) || echo --nocheck) \
         --define "_topdir /var/tmp" \
-        --define "_sourcedir pkg/$PKG_SUBDIR" \
+        --define "_sourcedir pkg/$ID" \
         --define "_rpmdir $OUTPUTDIR" \
         ${BUILDDIR:+--define} \
         ${BUILDDIR:+"_vpath_builddir $BUILDDIR"} \
@@ -46,7 +50,7 @@ build() {
         --define "__elf_exclude_path ^/usr/lib/systemd/tests/unit-tests/.*$" \
         --define "__script_requires %{nil}" \
         "$@" \
-        "pkg/$PKG_SUBDIR/systemd.spec"
+        "pkg/$ID/systemd.spec"
 }
 
 if ! build; then
@@ -58,7 +62,7 @@ if ! build; then
     # warnings.
     rm systemd.lang
 
-    cat /tmp/unpackaged-files >>"pkg/$PKG_SUBDIR/files.systemd"
+    cat /tmp/unpackaged-files >>"pkg/$ID/files.systemd"
     build --noprep --nocheck
 fi
 
index 06f3d2136565fc4f836340fc3a9245e0415cb4c6..56bf8cda8146d4f4b8e7813da2f11d2136e80b05 100644 (file)
@@ -8,7 +8,6 @@ InitrdInclude=initrd/
 
 [Content]
 Environment=
-        PKG_SUBDIR="opensuse"
         SYSTEMD_PACKAGES="systemd
                           udev
                           systemd-experimental
index 42bf05677f65bb08a38abd2fa7f1b91a758a796f..492aa0e45fdd75aa2a9fcf1e90b4c1f513d88af3 100755 (executable)
@@ -6,8 +6,12 @@ if [ "$1" = "build" ]; then
     exit 0
 fi
 
-if [ ! -f "pkg/$PKG_SUBDIR/systemd.spec" ]; then
-    echo "spec not found at pkg/$PKG_SUBDIR/systemd.spec, run mkosi once with -ff to make sure the spec is cloned" >&2
+# shellcheck source=/dev/null
+. "$BUILDROOT/usr/lib/os-release"
+ID="${ID%-*}"
+
+if [ ! -f "pkg/$ID/systemd.spec" ]; then
+    echo "spec not found at pkg/$ID/systemd.spec, run mkosi once with -ff to make sure the spec is cloned" >&2
     exit 1
 fi
 
@@ -18,8 +22,8 @@ for DEPS in --requires --buildrequires; do
         --query \
         "$DEPS" \
         --define "_topdir /var/tmp" \
-        --define "_sourcedir pkg/$PKG_SUBDIR" \
-        "pkg/$PKG_SUBDIR/systemd.spec" |
+        --define "_sourcedir pkg/$ID" \
+        "pkg/$ID/systemd.spec" |
             grep --invert-match --regexp systemd --regexp /bin/sh --regexp "rpmlib(" --regexp udev |
             sort --unique |
             tee /tmp/buildrequires |
@@ -32,9 +36,9 @@ until mkosi-chroot \
     --build-in-place \
     --with upstream \
     --define "_topdir /var/tmp" \
-    --define "_sourcedir pkg/$PKG_SUBDIR" \
+    --define "_sourcedir pkg/$ID" \
     --define "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
-    "pkg/$PKG_SUBDIR/systemd.spec"
+    "pkg/$ID/systemd.spec"
 do
     EXIT_STATUS=$?
     if [ $EXIT_STATUS -ne 11 ]; then
index 72b5cf7c335f66b41ed0bb842a3bbe8ea112fcb4..3e42a09b2c602ec5635b27078ca78ba8fd7ef353 100755 (executable)
@@ -2,7 +2,8 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 set -e
 
-if [ -z "$(ls --almost-all "pkg/$PKG_SUBDIR")" ] || [ -f "pkg/$PKG_SUBDIR/.git" ]; then
-    git submodule sync "pkg/$PKG_SUBDIR"
-    git submodule update --init "pkg/$PKG_SUBDIR"
+if [ -z "$(ls --almost-all "pkg/$DISTRIBUTION")" ] || [ -f "pkg/$DISTRIBUTION/.git" ]; then
+    PKG_SUBDIR="$(realpath "pkg/$DISTRIBUTION" --relative-to "$PWD")"
+    git submodule sync "$PKG_SUBDIR"
+    git submodule update --init "$PKG_SUBDIR"
 fi
diff --git a/pkg/ubuntu b/pkg/ubuntu
new file mode 120000 (symlink)
index 0000000..b2f7fd3
--- /dev/null
@@ -0,0 +1 @@
+debian
\ No newline at end of file