mkosi: Allow clearing meson cache with WIPE=1
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 1 Jun 2024 12:45:22 +0000 (14:45 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 3 Jun 2024 11:47:33 +0000 (13:47 +0200)
meson does not support changing compilation flags on the fly, when
doing so, the entire build directory has to be cleared explicitly, so
let's add a way to do that by setting WIPE=1.

Let's also allow developers to specify their own meson options via
$MESON_OPTIONS.

mkosi.images/system/mkosi.conf.d/10-arch/mkosi.build.chroot
mkosi.images/system/mkosi.conf.d/10-centos-fedora/mkosi.build.chroot
mkosi.images/system/mkosi.conf.d/10-debian-ubuntu/mkosi.build.chroot
mkosi.images/system/mkosi.conf.d/10-opensuse/mkosi.build.chroot

index 0085bb1166b870d14ed1397c5118611ddbcef99a..e3c694ba930f2ffa6dd3b8c02261fcd148097fe1 100755 (executable)
@@ -35,6 +35,11 @@ if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then
     MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(clang --print-file-name="")lib/linux"
 fi
 
+MKOSI_MESON_OPTIONS="-D mode=developer -D b_sanitize=${SANITIZERS:-none}"
+if ((WIPE)); then
+    MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS --wipe"
+fi
+
 # Override the default options. Disable FORTIFY_SOURCE because it doesn't work with O0. We specifically
 # disable "strip", "zipman" and "lto" as they slow down builds significantly. OPTIONS= cannot be overridden
 # on the makepkg command line so we append to /etc/makepkg.conf instead. The rootfs is overlaid with a
@@ -86,6 +91,6 @@ env --chdir="pkg/$ID" \
     BUILDDIR="$PWD/pkg/$ID" \
     PKGDEST="$OUTPUTDIR" \
     PKGEXT=".pkg.tar" \
-    MESON_EXTRA_CONFIGURE_OPTIONS="-D mode=developer -D b_sanitize=${SANITIZERS:-none}"
+    MESON_EXTRA_CONFIGURE_OPTIONS="$MKOSI_MESON_OPTIONS $MESON_OPTIONS"
 
 cp "$OUTPUTDIR"/*.pkg.tar "$PACKAGEDIR"
index bd55e4d971bda680b114439fd7ef808bacdcb1ad..8c7c413cfccbce886a72774691f858bfc7b6a8a9 100755 (executable)
@@ -61,6 +61,11 @@ if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then
     MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(dirname "$(clang --print-file-name=libclang_rt.asan.so)")"
 fi
 
+MKOSI_MESON_OPTIONS="-D mode=developer -D b_sanitize=${SANITIZERS:-none}"
+if ((WIPE)); then
+    MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS --wipe"
+fi
+
 IFS=
 # TODO: Replace meson_build and meson_install overrides with "--undefine __meson_verbose" once
 # https://github.com/mesonbuild/meson/pull/12835 is available.
@@ -93,7 +98,7 @@ CXX_LD="$( ((LLVM)) && echo lld)" \
     --define "build_ldflags $(rpm "${COMMON_MACRO_OVERRIDES[@]}" --eval "%{?build_ldflags}") $MKOSI_LDFLAGS $LDFLAGS" \
     --define "meson_build %{shrink:%{__meson} compile -C %{_vpath_builddir} -j %{_smp_build_ncpus} %{nil}}" \
     --define "meson_install %{shrink:DESTDIR=%{buildroot} %{__meson} install -C %{_vpath_builddir} --no-rebuild --quiet %{nil}}" \
-    --define "meson_extra_configure_options -D mode=developer -D b_sanitize=${SANITIZERS:-none}" \
+    --define "meson_extra_configure_options $MKOSI_MESON_OPTIONS $MESON_OPTIONS" \
     $( ((WITH_DEBUG)) || echo "--define=__brp_strip %{nil}") \
     --define "__brp_compress %{nil}" \
     --define "__brp_mangle_shebangs %{nil}" \
index 1db5b7afa964437d9280d031c61a9d5a21caf8cb..8e5c25b2298b8720d91ff795960cc95f341aa325 100755 (executable)
@@ -55,6 +55,11 @@ if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then
     MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(clang --print-file-name="")lib/linux"
 fi
 
+MKOSI_MESON_OPTIONS="-D mode=developer -D b_sanitize=${SANITIZERS:-none}"
+if ((WIPE)); then
+    MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS --wipe"
+fi
+
 # TODO: Drop GENSYMBOLS_LEVEL once https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=986746 is fixed.
 build() {
     env \
@@ -81,12 +86,19 @@ build() {
     DPKG_FORCE="unsafe-io" \
     DPKG_DEB_COMPRESSOR_TYPE="none" \
     DH_MISSING="--fail-missing" \
-    CONFFLAGS_UPSTREAM="-D mode=developer -D b_sanitize=${SANITIZERS:-none}" \
+    CONFFLAGS_UPSTREAM="$MKOSI_MESON_OPTIONS $MESON_OPTIONS" \
     GENSYMBOLS_LEVEL="$( ((LLVM)) && echo 0 || echo 1)" \
         dpkg-buildpackage \
         --no-pre-clean \
         --unsigned-changes \
         --build=binary
+
+    EXIT_STATUS=$?
+
+    # Make sure we don't reconfigure twice.
+    MKOSI_MESON_OPTIONS="${MKOSI_MESON_OPTIONS//"--wipe"/}"
+
+    return $EXIT_STATUS
 }
 
 if ! build; then
index c6f4155f95e581ffcfcf7e24b25dca67da76b779..8351200d9990db3341ed230a73f04246feac782c 100755 (executable)
@@ -62,6 +62,11 @@ if [[ -z "${MKOSI_LDFLAGS// }" ]]; then
     MKOSI_LDFLAGS="%{nil}"
 fi
 
+MKOSI_MESON_OPTIONS="-D mode=developer -D b_sanitize=${SANITIZERS:-none}"
+if ((WIPE)); then
+    MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS --wipe"
+fi
+
 build() {
     IFS=
     # TODO: Replace meson_build and meson_install overrides with "--undefine __meson_verbose" once
@@ -98,7 +103,7 @@ build() {
         --define "build_ldflags $MKOSI_LDFLAGS $LDFLAGS" \
         --define "meson_build %{shrink:%{__meson} compile -C %{_vpath_builddir} -j %{_smp_build_ncpus} %{nil}}" \
         --define "meson_install %{shrink:DESTDIR=%{buildroot} %{__meson} install -C %{_vpath_builddir} --no-rebuild --quiet %{nil}}" \
-        --define "__meson_auto_features auto -D mode=developer -D b_sanitize=${SANITIZERS:-none}" \
+        --define "__meson_auto_features auto $MKOSI_MESON_OPTIONS $MESON_OPTIONS" \
         --define "__os_install_post /usr/lib/rpm/brp-suse %{nil}" \
         --define "__elf_exclude_path ^/usr/lib/systemd/tests/unit-tests/.*$" \
         --define "__script_requires %{nil}" \
@@ -107,6 +112,13 @@ build() {
         --noclean \
         "$@" \
         "pkg/$ID/systemd.spec"
+
+    EXIT_STATUS=$?
+
+    # Make sure we don't reconfigure twice.
+    MKOSI_MESON_OPTIONS="${MKOSI_MESON_OPTIONS//"--wipe"/}"
+
+    return $EXIT_STATUS
 }
 
 if ! build; then