Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix CMakeUserPresets inherits #14325

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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