Skip to content

Commit

Permalink
fix CMakeUserPresets inherits (#14325)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored Jul 19, 2023
1 parent 89f01e1 commit 8920516
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 8 additions & 5 deletions conan/tools/cmake/presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,19 +263,22 @@ def _collect_user_inherits(output_dir, preset_prefix):
# so things doesn't break for multi-platform, when inherits don't exist
collected_targets = {}
types = "configurePresets", "buildPresets", "testPresets"
for file in ("CMakePresets.json", "CMakeUserPresests.json"):
for file in ("CMakePresets.json", "CMakeUserPresets.json"):
user_file = os.path.join(output_dir, file)
if os.path.exists(user_file):
user_json = json.loads(load(user_file))
for preset_type in types:
conan_inherits = []
for preset in user_json.get(preset_type, []):
inherits = preset.get("inherits", [])
if isinstance(inherits, str):
inherits = [inherits]
conan_inherits.extend([i for i in inherits if i.startswith(preset_prefix)])
if len(conan_inherits):
collected_targets.setdefault(preset_type, []).extend(list(set(conan_inherits)))
inherits = [i for i in inherits if i.startswith(preset_prefix)]
if inherits:
existing = collected_targets.setdefault(preset_type, [])
for i in inherits:
if i not in existing:
existing.append(i)

return collected_targets

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ def layout(self):
assert presets["configurePresets"][0]["binaryDir"] == build_dir


def test_cmake_presets_shared_preset():
@pytest.mark.parametrize("presets", ["CMakePresets.json", "CMakeUserPresets.json"])
def test_cmake_presets_shared_preset(presets):
"""valid user preset file is created when multiple project presets inherit
from the same conan presets.
"""
Expand Down Expand Up @@ -456,9 +457,9 @@ def generate(self):
tc.generate()
""")

client.save({"CMakePresets.json": project_presets,
client.save({presets: project_presets,
"conanfile.py": conanfile,
"CMakeLists.txt": "" }) #File must exist for Conan to do Preset things.
"CMakeLists.txt": ""}) # File must exist for Conan to do Preset things.

client.run("install . -s build_type=Debug")

Expand Down

0 comments on commit 8920516

Please sign in to comment.