From: Daan De Meyer Date: Wed, 15 Jan 2025 11:14:01 +0000 (+0100) Subject: sandbox: Drop tools tree in run_verb() instead of when parsing config X-Git-Tag: v25~52^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a14443d236144299455ba9711cf458e814ee90c8;p=thirdparty%2Fmkosi.git sandbox: Drop tools tree in run_verb() instead of when parsing config Another change to make mkosi sandbox in and outside the sandbox identical. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index a653a1900..01ffbe3c5 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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] diff --git a/mkosi/config.py b/mkosi/config.py index 525a73a35..ba788c107 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -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="?",