]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
sandbox: Drop tools tree in run_verb() instead of when parsing config
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 15 Jan 2025 11:14:01 +0000 (12:14 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 15 Jan 2025 11:14:01 +0000 (12:14 +0100)
Another change to make mkosi sandbox in and outside the sandbox identical.

mkosi/__init__.py
mkosi/config.py

index a653a19009541bc77e634aa82114a68ebfe1c5d7..01ffbe3c59e183fc07335177be59f477a0afa757 100644 (file)
@@ -3761,6 +3761,10 @@ def build_image(context: Context) -> None:
     print_output_size(context.config.output_dir_or_cwd() / context.config.output_with_compression)
 
 
+def in_sandbox() -> bool:
+    return parse_boolean(os.getenv("MKOSI_IN_SANDBOX", "0"))
+
+
 def run_sandbox(args: Args, config: Config) -> None:
     if not args.cmdline:
         die("Please specify a command to execute in the sandbox")
@@ -4604,20 +4608,20 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None:
     if (minversion := last.minimum_version) and minversion > __version__:
         die(f"mkosi {minversion} or newer is required by this configuration (found {__version__})")
 
-    if last.tools_tree and last.tools_tree == Path("default"):
+    if not in_sandbox() and last.tools_tree and last.tools_tree == Path("default"):
         tools = finalize_default_tools(last, resources=resources)
     else:
         tools = None
 
     for i, config in enumerate(images):
-        images[i] = dataclasses.replace(
-            config,
-            tools_tree=(
-                tools.output_dir_or_cwd() / tools.output
-                if tools and config.tools_tree == Path("default")
-                else config.tools_tree
-            ),
-        )
+        if in_sandbox():
+            tools_tree = None
+        elif tools and config.tools_tree == Path("default"):
+            tools_tree = tools.output_dir_or_cwd() / tools.output
+        else:
+            tools_tree = config.tools_tree
+
+        images[i] = dataclasses.replace(config, tools_tree=tools_tree)
 
     # The images array has been modified so we need to reevaluate last again.
     last = images[-1]
index 525a73a353780b3f0f6f6a3fc1e60e086c087613..ba788c107230dc53214416fadcbe0d0c92b4aa2a 100644 (file)
@@ -3111,13 +3111,7 @@ SETTINGS: list[ConfigSetting[Any]] = [
         dest="tools_tree",
         metavar="PATH",
         section="Build",
-        parse=(
-            # If we're running inside of mkosi sandbox, the tools tree is already in place so don't pick it
-            # up again.
-            config_make_path_parser(constants=("default",))
-            if not os.getenv("MKOSI_IN_SANDBOX")
-            else lambda value, old: None
-        ),
+        parse=config_make_path_parser(constants=("default",)),
         paths=("mkosi.tools",),
         help="Look up programs to execute inside the given tree",
         nargs="?",