From: Daan De Meyer Date: Mon, 30 Dec 2024 16:10:53 +0000 (+0100) Subject: Parse profiles in subimages as well X-Git-Tag: v25~91 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23b17713f4446ca5a9c78eb3e7c99e17afaff408;p=thirdparty%2Fmkosi.git Parse profiles in subimages as well Let's parse from mkosi.profiles in subimages as well. We'll still insist that the profiles used are set in the main image though. To make this work we have to remove the check to see if a profile exists or not, since it might not exist in every mkosi.profiles/ directory that we parse. At the same time we remove the restriction that profiles are set before we parse mkosi.conf.d/ since this isn't really useful anymore now that we parse profiles last and not first anymore. This allows us to get rid of the concept of immutable settings. Fixes #3307 --- diff --git a/mkosi/config.py b/mkosi/config.py index 99a09a619..6f26f5308 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -4004,7 +4004,6 @@ class ParseContext: self.defaults = argparse.Namespace() # Compare inodes instead of paths so we can't get tricked by bind mounts and such. self.includes: set[tuple[int, int]] = set() - self.immutable: set[str] = set() self.only_sections: tuple[str, ...] = tuple() def expand_specifiers(self, text: str, path: Path) -> str: @@ -4335,8 +4334,6 @@ class ParseContext: and (image := getattr(self.config, "image", None)) is not None ): die(f"{path.absolute()}: Setting {name} cannot be configured in subimage {image}") - if name in self.immutable: - die(f"{path.absolute()}: Setting {name} cannot be modified anymore at this point") if section != s.section: logging.warning( @@ -4354,30 +4351,19 @@ class ParseContext: setattr(self.config, s.dest, s.parse(v, getattr(self.config, s.dest, None))) self.parse_new_includes() - profilepaths = [] - if parse_profiles: - profiles = self.finalize_value(SETTINGS_LOOKUP_BY_DEST["profiles"]) - self.immutable.add("Profiles") - - for profile in profiles or []: - for p in (Path(profile), Path(f"{profile}.conf")): - p = Path("mkosi.profiles") / p - if p.exists(): - break - else: - die(f"Profile '{profile}' not found in mkosi.profiles/") - - profilepaths += [p] - if extras and (path.parent / "mkosi.conf.d").exists(): for p in sorted((path.parent / "mkosi.conf.d").iterdir()): if p.is_dir() or p.suffix == ".conf": with chdir(p if p.is_dir() else Path.cwd()): self.parse_config_one(p if p.is_file() else Path(".")) - for p in profilepaths: - with chdir(p if p.is_dir() else Path.cwd()): - self.parse_config_one(p if p.is_file() else Path(".")) + if parse_profiles: + for profile in self.finalize_value(SETTINGS_LOOKUP_BY_DEST["profiles"]) or []: + for p in (Path(profile), Path(f"{profile}.conf")): + p = Path("mkosi.profiles") / p + if p.exists(): + with chdir(p if p.is_dir() else Path.cwd()): + self.parse_config_one(p if p.is_file() else Path(".")) return True @@ -4551,7 +4537,11 @@ def parse_config( context.defaults = argparse.Namespace() with chdir(p if p.is_dir() else Path.cwd()): - if not context.parse_config_one(p if p.is_file() else Path("."), parse_local=True): + if not context.parse_config_one( + p if p.is_file() else Path("."), + parse_profiles=True, + parse_local=True, + ): continue # Consolidate all settings into one namespace again. diff --git a/tests/test_config.py b/tests/test_config.py index aca3e189f..075d7da96 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -417,6 +417,20 @@ def test_profiles(tmp_path: Path) -> None: assert config.profiles == ["profile", "abc"] assert config.distribution == Distribution.opensuse + # Check that mkosi.profiles/ is parsed in subimages as well. + (d / "mkosi.images/subimage/mkosi.profiles").mkdir(parents=True) + (d / "mkosi.images/subimage/mkosi.profiles/abc.conf").write_text( + """ + [Build] + Environment=Image=%I + """ + ) + + with chdir(d): + _, [subimage, config] = parse_config() + + assert subimage.environment["Image"] == "subimage" + def test_override_default(tmp_path: Path) -> None: d = tmp_path