From 716c934076f8c84f0f37e088a2e9246ac3d55329 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 3 Apr 2024 10:24:05 +0200 Subject: [PATCH] Make sure multiple image definitions can parse the same include --- mkosi/config.py | 2 ++ tests/test_config.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/mkosi/config.py b/mkosi/config.py index 019c0410c..54554e074 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -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) diff --git a/tests/test_config.py b/tests/test_config.py index dc90d6e2c..10e389b9c 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -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 -- 2.47.2