]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Don't pass down empty lists to subimages unless explicitly configured 2944/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 6 Aug 2024 07:57:46 +0000 (09:57 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 6 Aug 2024 10:19:37 +0000 (12:19 +0200)
This makes sure that subimages use default values for list based
settings unless they were explicitly configured in configuration or
on the command line or have a non-empty default value in the main
image.

Fixes #2874

mkosi/config.py
tests/test_config.py

index c919a3473c1c26d0faa19b0d9f897eac67e637f6..18c6a8ae5af398a528fa3d91aad96486df725aaf 100644 (file)
@@ -3824,7 +3824,18 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu
         # were specified on the CLI by copying them to the CLI namespace. Any settings
         # that are not marked as "universal" are deleted from the CLI namespace.
         for s in SETTINGS:
-            if s.scope == SettingScope.universal:
+            if (
+                s.scope == SettingScope.universal and (
+                    # For list-based settings, don't pass down empty lists unless it came
+                    # explicitly from the config file or the CLI. This makes sure that default
+                    # values from subimages are still used if no value is explicitly configured
+                    # in the main image or on the CLI.
+                    not isinstance(getattr(config, s.dest), (list, dict, set)) or
+                    getattr(config, s.dest) or
+                    hasattr(context.cli, s.dest) or
+                    hasattr(context.config, s.dest)
+                )
+            ):
                 setattr(context.cli, s.dest, copy.deepcopy(getattr(config, s.dest)))
             elif hasattr(context.cli, s.dest):
                 delattr(context.cli, s.dest)
index abd70805cf45e36855285723e7504b5d1ae25c6c..20db168af1c8f0d5add419e19dae2059f0077466 100644 (file)
@@ -262,6 +262,7 @@ def test_parse_config(tmp_path: Path) -> None:
     )
 
     (d / "mkosi.images/two").mkdir()
+    (d / "mkosi.images/two/mkosi.skeleton").mkdir()
     (d / "mkosi.images/two/mkosi.conf").write_text(
         """
         [Distribution]
@@ -302,6 +303,10 @@ def test_parse_config(tmp_path: Path) -> None:
     assert one.image_version == "1.2.3"
     assert two.image_version == "4.5.6"
 
+    # Default values from subimages should be picked up.
+    assert len(one.package_manager_trees) == 0
+    assert len(two.package_manager_trees) == 1 and two.package_manager_trees[0].source.name == "mkosi.skeleton"
+
     with chdir(d):
         _, [one, two, config] = parse_config(["--image-version", "7.8.9"])