]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Make sure multiple image definitions can parse the same include 2580/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 3 Apr 2024 08:24:05 +0000 (10:24 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 3 Apr 2024 09:32:58 +0000 (11:32 +0200)
mkosi/config.py
tests/test_config.py

index 019c0410c1c2694dc3967c2682f0f8153bd618b7..54554e07425a6192814a22ab7e49d8730649a55a 100644 (file)
@@ -3460,6 +3460,7 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu
 
                 ns_copy = copy.deepcopy(namespace)
                 defaults_copy = copy.deepcopy(defaults)
+                parsed_includes_copy = copy.deepcopy(parsed_includes)
 
                 setattr(namespace, "image", name)
 
@@ -3472,6 +3473,7 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu
 
                 namespace = ns_copy
                 defaults = defaults_copy
+                parsed_includes = parsed_includes_copy
 
     if not images:
         setattr(namespace, "image", None)
index dc90d6e2ce7abae6983993bf493bc70604404dd1..10e389b9cb1145b62e7d4e46376a4b55b5fb95c7 100644 (file)
@@ -221,6 +221,43 @@ def test_parse_config(tmp_path: Path) -> None:
         assert config.split_artifacts is False
 
 
+def test_parse_includes_once(tmp_path: Path) -> None:
+    d = tmp_path
+
+    (d / "mkosi.conf").write_text(
+        """\
+        [Content]
+        Bootable=yes
+        BuildPackages=abc
+        """
+    )
+    (d / "abc.conf").write_text(
+        """\
+        [Content]
+        BuildPackages=def
+        """
+    )
+
+    with chdir(d):
+        _, [config] = parse_config(["--include", "abc.conf", "--include", "abc.conf"])
+        assert config.build_packages == ["def", "abc"]
+
+    (d / "mkosi.images").mkdir()
+
+    for n in ("one", "two"):
+        (d / "mkosi.images" / f"{n}.conf").write_text(
+            """\
+            [Config]
+            Include=abc.conf
+            """
+        )
+
+    with chdir(d):
+        _, [one, two] = parse_config([])
+        assert one.build_packages == ["abc", "def"]
+        assert two.build_packages == ["abc", "def"]
+
+
 def test_profiles(tmp_path: Path) -> None:
     d = tmp_path