Skip to content

Commit

Permalink
fix [system_tools] profile composition (#13468)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored Mar 17, 2023
1 parent 427dc7a commit 63132c9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
11 changes: 9 additions & 2 deletions conans/client/profile_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,19 @@ def get_profile(profile_text, base_profile=None):

# Create or update the profile
base_profile = base_profile or Profile()
base_profile.system_tools = system_tools
current_system_tools = {r.name: r for r in base_profile.system_tools}
current_system_tools.update({r.name: r for r in system_tools})
base_profile.system_tools = list(current_system_tools.values())

base_profile.settings.update(settings)
for pkg_name, values_dict in package_settings.items():
base_profile.package_settings[pkg_name].update(values_dict)
for pattern, refs in tool_requires.items():
base_profile.tool_requires.setdefault(pattern, []).extend(refs)
# If the same package, different version is added, the latest version prevail
current = base_profile.tool_requires.setdefault(pattern, [])
current_dict = {r.name: r for r in current}
current_dict.update({r.name: r for r in refs})
current[:] = list(current_dict.values())
if options is not None:
base_profile.options.update_options(options)
if conf is not None:
Expand Down
41 changes: 41 additions & 0 deletions conans/test/unittests/client/profile_loader/profile_loader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,47 @@ def save_profile(txt, name):
RecipeReference.loads("two/1.2@lasote/stable")]}


def test_profile_compose_system_tools():
tmp = temp_folder()
save(os.path.join(tmp, "profile0"), "[system_tools]\ntool1/1.0")
save(os.path.join(tmp, "profile1"), "[system_tools]\ntool2/2.0")
save(os.path.join(tmp, "profile2"), "include(./profile0)\n[system_tools]\ntool3/3.0")
save(os.path.join(tmp, "profile3"), "include(./profile0)\n[system_tools]\ntool1/1.1")

profile_loader = ProfileLoader(cache=None) # If not used cache, will not error
profile2 = profile_loader.load_profile("./profile2", tmp)
assert profile2.system_tools == [RecipeReference.loads("tool1/1.0"),
RecipeReference.loads("tool3/3.0")]
profile3 = profile_loader.load_profile("./profile3", tmp)
assert profile3.system_tools == [RecipeReference.loads("tool1/1.1")]
profile0 = profile_loader.load_profile("./profile0", tmp)
profile1 = profile_loader.load_profile("./profile1", tmp)
profile0.compose_profile(profile1)
assert profile0.system_tools == [RecipeReference.loads("tool1/1.0"),
RecipeReference.loads("tool2/2.0")]


def test_profile_compose_tool_requires():
tmp = temp_folder()
save(os.path.join(tmp, "profile0"), "[tool_requires]\ntool1/1.0")
save(os.path.join(tmp, "profile1"), "[tool_requires]\ntool2/2.0")
save(os.path.join(tmp, "profile2"), "include(./profile0)\n[tool_requires]\ntool3/3.0")
save(os.path.join(tmp, "profile3"), "include(./profile0)\n[tool_requires]\ntool1/1.1")

profile_loader = ProfileLoader(cache=None) # If not used cache, will not error
profile2 = profile_loader.load_profile("./profile2", tmp)
assert profile2.tool_requires == {"*": [RecipeReference.loads("tool1/1.0"),
RecipeReference.loads("tool3/3.0")]}
profile3 = profile_loader.load_profile("./profile3", tmp)
assert profile3.tool_requires == {"*": [RecipeReference.loads("tool1/1.1")]}

profile0 = profile_loader.load_profile("./profile0", tmp)
profile1 = profile_loader.load_profile("./profile1", tmp)
profile0.compose_profile(profile1)
assert profile0.tool_requires == {"*": [RecipeReference.loads("tool1/1.0"),
RecipeReference.loads("tool2/2.0")]}


def test_profile_include_order():
tmp = temp_folder()

Expand Down

0 comments on commit 63132c9

Please sign in to comment.