From cd7f0bed6977e9441102e1f5e64d8a40f69f28fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Wed, 18 Dec 2024 17:29:20 +0100 Subject: [PATCH] Don't use a reference for new component properties lists when merging (#17503) * Don't use a reference for new component properties lists when merging * Add test * Cleanup tests --- conans/model/build_info.py | 2 +- test/integration/test_components.py | 40 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/conans/model/build_info.py b/conans/model/build_info.py index 98ea5aae6ac..57b619dabd8 100644 --- a/conans/model/build_info.py +++ b/conans/model/build_info.py @@ -451,7 +451,7 @@ def merge_list(o, d): if existing is not None and isinstance(existing, list) and not overwrite: existing.extend(v) else: - current_values[k] = v + current_values[k] = copy.copy(v) def set_relative_base_folder(self, folder): for varname in _DIRS_VAR_NAMES: diff --git a/test/integration/test_components.py b/test/integration/test_components.py index 5506fd276c9..cbe29f118ab 100644 --- a/test/integration/test_components.py +++ b/test/integration/test_components.py @@ -149,3 +149,43 @@ def package_info(self): # This used to crash, because override was not correctly excluded c.run("create app") assert "app/0.1: Created package" in c.out + +def test_duplication_component_properties(): + """ Regression for PR 17503 - component lists would be incorrectly aggregated """ + tc = TestClient(light=True) + + dep = textwrap.dedent(""" + from conan import ConanFile + + class Dep(ConanFile): + name = "dep" + version = "0.1" + + def package_info(self): + self.cpp_info.components["acomp"].set_property("prop_list", ["value1"]) + self.cpp_info.components["bcomp"].set_property("prop_list", ["value2"]) + self.cpp_info.components["ccomp"].set_property("prop_list", ["value3"]) + """) + + conanfile = textwrap.dedent(""" + from conan import ConanFile + + class Pkg(ConanFile): + name = "pkg" + version = "0.1" + requires = "dep/0.1" + + def generate(self): + # Calling this would break property lists of the last lex sorted component + aggregated_components = self.dependencies["dep"].cpp_info.aggregated_components() + ccomp = self.dependencies["dep"].cpp_info.components["ccomp"] + self.output.info("ccomp list: " + str(ccomp.get_property("prop_list"))) + """) + + tc.save({"dep/conanfile.py": dep, + "conanfile.py": conanfile}) + tc.run("create dep") + tc.run("create .") + # The bug would give ccomp the prop_list values of the other two components + assert "pkg/0.1: ccomp list: ['value3', 'value2', 'value1']" not in tc.out + assert "pkg/0.1: ccomp list: ['value3']" in tc.out