From bac567a53be1995cc24b6de0c175839f4f57afeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Koutn=C3=BD?= Date: Tue, 21 Apr 2020 18:08:23 +0200 Subject: [PATCH 1/4] mkosi: Use distro-invariant rootprefix Distributions may be build with various configs, e.g. customized rootprefix. It'd be unmaintanable to have specific mkosi.build for each supported distro. Hence, make the build script flexible yet distro oblivious. --- mkosi.build | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mkosi.build b/mkosi.build index 16ac2e9d0d..fc09baeadd 100755 --- a/mkosi.build +++ b/mkosi.build @@ -42,6 +42,14 @@ fi if [ ! -f "$BUILDDIR"/build.ninja ] ; then sysvinit_path=`realpath /etc/init.d` + init_path=`realpath /sbin/init 2>/dev/null` + if [ -z "$init_path" ] ; then + rootprefix="" + else + rootprefix=${init_path%/lib/systemd/systemd} + rootprefix=/${rootprefix#/} + fi + nobody_user=`id -u -n 65534 2> /dev/null` if [ "$nobody_user" != "" ] ; then # Validate that we can translate forth and back @@ -76,7 +84,7 @@ if [ ! -f "$BUILDDIR"/build.ninja ] ; then fi fi - meson "$BUILDDIR" -D "sysvinit-path=$sysvinit_path" -D default-hierarchy=unified -D man=false -D "nobody-user=$nobody_user" -D "nobody-group=$nobody_group" + meson "$BUILDDIR" -D "sysvinit-path=$sysvinit_path" -D "rootprefix=$rootprefix" -D default-hierarchy=unified -D man=false -D "nobody-user=$nobody_user" -D "nobody-group=$nobody_group" fi ninja -C "$BUILDDIR" all From 9acb2964d7798813274dbd5992fb6f370add23b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Koutn=C3=BD?= Date: Wed, 22 Apr 2020 00:31:54 +0200 Subject: [PATCH 2/4] test: Simplify hostname checking Both hostname and uname utilities boil down to uname(2) syscall. Reduce tests dependency footprint by using uname for checking hostname too. --- .mkosi/mkosi.fedora | 1 - test/test-execute/exec-specifier.service | 2 +- test/test-execute/exec-specifier@.service | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.mkosi/mkosi.fedora b/.mkosi/mkosi.fedora index 01bfd2338b..9769b05447 100644 --- a/.mkosi/mkosi.fedora +++ b/.mkosi/mkosi.fedora @@ -31,7 +31,6 @@ BuildPackages= gnu-efi-devel gnutls-devel gperf - hostname iptables-devel kmod-devel libacl-devel diff --git a/test/test-execute/exec-specifier.service b/test/test-execute/exec-specifier.service index 7c3f81f2b5..a58abc68dd 100644 --- a/test/test-execute/exec-specifier.service +++ b/test/test-execute/exec-specifier.service @@ -27,5 +27,5 @@ ExecStart=test %h = /root ExecStart=sh -c 'test %s = /bin/sh' ExecStart=sh -c 'test %m = $$(cat /etc/machine-id)' ExecStart=sh -c 'test %b = $$(cat /proc/sys/kernel/random/boot_id | sed -e 's/-//g')' -ExecStart=sh -c 'test %H = $$(hostname)' +ExecStart=sh -c 'test %H = $$(uname -n)' ExecStart=sh -c 'test %v = $$(uname -r)' diff --git a/test/test-execute/exec-specifier@.service b/test/test-execute/exec-specifier@.service index a388926846..faecbf37bc 100644 --- a/test/test-execute/exec-specifier@.service +++ b/test/test-execute/exec-specifier@.service @@ -25,5 +25,5 @@ ExecStart=test %h = /root ExecStart=sh -c 'test %s = /bin/sh' ExecStart=sh -c 'test %m = $$(cat /etc/machine-id)' ExecStart=sh -c 'test %b = $$(cat /proc/sys/kernel/random/boot_id | sed -e 's/-//g')' -ExecStart=sh -c 'test %H = $$(hostname)' +ExecStart=sh -c 'test %H = $$(uname -n)' ExecStart=sh -c 'test %v = $$(uname -r)' From ff5499824f96a7e7b93ca0b294eec62ad21e6592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Koutn=C3=BD?= Date: Wed, 22 Apr 2020 01:58:44 +0200 Subject: [PATCH 3/4] mkosi: Unify environment for unit tests Some testcases in test-execute rely on existence of user groups with certain gids. However, their existence is not universally granted [1]. Although the test could be skipped in their absence and give up testing some code paths, different approach was chosen -- create dummy groups in the testing image. [1] See how systemd-sysusers allocates gids (e.g. src/test/test-uid-range.c). --- mkosi.build | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mkosi.build b/mkosi.build index fc09baeadd..4a13f1075e 100755 --- a/mkosi.build +++ b/mkosi.build @@ -88,7 +88,13 @@ if [ ! -f "$BUILDDIR"/build.ninja ] ; then fi ninja -C "$BUILDDIR" all -[ "$WITH_TESTS" = 0 ] || ninja -C "$BUILDDIR" test +if [ "$WITH_TESTS" = 1 ] ; then + for id in 1 2 3; do + groupadd -g $id testgroup$id || : + done + + ninja -C "$BUILDDIR" test +fi ninja -C "$BUILDDIR" install mkdir -p "$DESTDIR"/etc From 69d95d64688fa594ad5b7b4f247aafa2eca7851b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Koutn=C3=BD?= Date: Wed, 22 Apr 2020 02:11:18 +0200 Subject: [PATCH 4/4] mkosi: Add openSUSE params file The setup is meant to run against openSUSE Tumbleweed and install minimum packages necessary for successful build and passing tests. To speed up incremental build an external build directory is used. --- .mkosi/mkosi.opensuse | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .mkosi/mkosi.opensuse diff --git a/.mkosi/mkosi.opensuse b/.mkosi/mkosi.opensuse new file mode 100644 index 0000000000..1faf9cc476 --- /dev/null +++ b/.mkosi/mkosi.opensuse @@ -0,0 +1,60 @@ +# SPDX-License-Identifier: LGPL-2.1+ + +# This is a settings file for OS image generation using mkosi (https://github.com/systemd/mkosi). +# Simply invoke "mkosi" in the project directory to build an OS image. + +[Distribution] +Distribution=opensuse +Release=tumbleweed + +[Output] +Format=raw_btrfs +Bootable=yes + +[Partitions] +RootSize=3G + +[Packages] +# Uncomment to share system RPM cache (works only with Tumbleweed) +#Cache=/var/cache/zypp/packages +BuildDirectory=mkosi.builddir +BuildPackages= + docbook-xsl-stylesheets + fdupes + gcc + gnu-efi + gperf + intltool + libacl-devel + libapparmor-devel + libblkid-devel + libbz2-devel + libcap-devel + libcryptsetup-devel + libcurl-devel + libgcrypt-devel + libkmod-devel + liblz4-devel + libmicrohttpd-devel + libmount-devel + libseccomp-devel + libselinux-devel + libxslt-tools + m4 + meson + pam-devel + pciutils-devel + pcre-devel + python3 + python3-lxml + qrencode-devel + zlib-devel +# to satisfy tests + acl + glibc-locale + system-group-obsolete + timezone + +Packages= + # brought in via meson->python3 + libp11-kit0