From: Antonio Alvarez Feijoo Date: Fri, 28 Mar 2025 14:53:10 +0000 (+0100) Subject: mkosi: pass DEBUG enviroment variable to scripts X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F3634%2Fhead;p=thirdparty%2Fmkosi.git mkosi: pass DEBUG enviroment variable to scripts So scripts can run debugging code if mkosi is running with `--debug`. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index dc01dbd06..4493d7bd3 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -599,6 +599,7 @@ def run_configure_scripts(config: Config) -> Config: SRCDIR="/work/src", MKOSI_UID=str(os.getuid()), MKOSI_GID=str(os.getgid()), + DEBUG=one_zero(ARG_DEBUG.get()), ) if config.profiles: @@ -641,6 +642,7 @@ def run_sync_scripts(config: Config) -> None: MKOSI_GID=str(os.getgid()), MKOSI_CONFIG="/work/config.json", CACHED=one_zero(have_cache(config)), + DEBUG=one_zero(ARG_DEBUG.get()), ) if config.profiles: @@ -761,6 +763,7 @@ def run_prepare_scripts(context: Context, build: bool) -> None: WITH_DOCS=one_zero(context.config.with_docs), WITH_NETWORK=one_zero(context.config.with_network), WITH_TESTS=one_zero(context.config.with_tests), + DEBUG=one_zero(ARG_DEBUG.get()), ) if context.config.profiles: @@ -830,6 +833,7 @@ def run_build_scripts(context: Context) -> None: WITH_DOCS=one_zero(context.config.with_docs), WITH_NETWORK=one_zero(context.config.with_network), WITH_TESTS=one_zero(context.config.with_tests), + DEBUG=one_zero(ARG_DEBUG.get()), ) if context.config.profiles: @@ -902,6 +906,7 @@ def run_postinst_scripts(context: Context) -> None: MKOSI_GID=str(os.getgid()), MKOSI_CONFIG="/work/config.json", WITH_NETWORK=one_zero(context.config.with_network), + DEBUG=one_zero(ARG_DEBUG.get()), ) if context.config.profiles: @@ -970,6 +975,7 @@ def run_finalize_scripts(context: Context) -> None: MKOSI_GID=str(os.getgid()), MKOSI_CONFIG="/work/config.json", WITH_NETWORK=one_zero(context.config.with_network), + DEBUG=one_zero(ARG_DEBUG.get()), ) if context.config.profiles: @@ -1030,6 +1036,7 @@ def run_postoutput_scripts(context: Context) -> None: MKOSI_UID=str(os.getuid()), MKOSI_GID=str(os.getgid()), MKOSI_CONFIG="/work/config.json", + DEBUG=one_zero(ARG_DEBUG.get()), ) if context.config.profiles: @@ -4587,6 +4594,7 @@ def run_clean_scripts(config: Config) -> None: MKOSI_UID=str(os.getuid()), MKOSI_GID=str(os.getgid()), MKOSI_CONFIG="/work/config.json", + DEBUG=one_zero(ARG_DEBUG.get()), ) if config.profiles: diff --git a/mkosi/resources/man/mkosi.1.md b/mkosi/resources/man/mkosi.1.md index 9c9425ba4..30396a725 100644 --- a/mkosi/resources/man/mkosi.1.md +++ b/mkosi/resources/man/mkosi.1.md @@ -2579,6 +2579,9 @@ Scripts executed by **mkosi** receive the following environment variables: * `$IMAGE_VERSION` contains the version from the `ImageVersion=` or `--image-version=` setting. +* `$DEBUG` is either `0` or `1` depending on whether debugging output is + enabled. + Consult this table for which script receives which environment variables: | Variable | `configure` | `sync` | `prepare` | `build` | `postinst` | `finalize` | `postoutput` | `clean` | @@ -2593,6 +2596,7 @@ Consult this table for which script receives which environment variables: | `CHROOT_OUTPUTDIR` | | | | | ✓ | ✓ | | | | `CHROOT_SCRIPT` | | | ✓ | ✓ | ✓ | ✓ | | | | `CHROOT_SRCDIR` | | | ✓ | ✓ | ✓ | ✓ | | | +| `DEBUG` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | `DESTDIR` | | | | ✓ | | | | | | `DISTRIBUTION` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | `DISTRIBUTION_ARCHITECTURE` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |