Skip to content

Only generate or modify CMakeUserPresets.json if none existed, or existing was previously generated by conan - #11452

Merged
lasote merged 5 commits into
conan-io:developfrom
jcar87:bugfix/cmake-user-presets-when-it-already-exists
Jun 15, 2022
Merged

lasote merged 5 commits into
conan-io:developfrom
jcar87:bugfix/cmake-user-presets-when-it-already-exists

Conversation

@jcar87

@jcar87 jcar87 commented Jun 14, 2022

Copy link
Copy Markdown
Contributor

Changelog: Bugfix: Fix logic in the generation of CMakeUserPresets.json - Conan will only generate the file if it did not previously exist, and will modify an existing one if the file was previously generated by conan. Existing CMakeUserPresets.json will be left untouched otherwise.

Docs: conan-io/docs#2591

Description

Before this PR: if CMakeUserPresets.json file existed next to CMakeLists.txt, but was empty or did not contain the include section (or was empty) - the generator would fail.

In this PR: conan will only generate CMakeUserPresets.json if the file did not previously exist, or if it existed and was previously generated by conan, which we now identify with an empty conan member in the vendor field (which is reserved by CMake for third-party tooling).

Tests

Modified existing test to cover 3 cases:

  • CMakeUserPresets.json did not exist, and is generated with the correct information after generation (this was already what was being tested)
  • CMakeUserPresets.json exists but does not have the conan member in the vendor field
  • CMakeUserPresets.json exists and it was previously generated by conan (in this case the test also verifies that the correct information is updated).

@jcar87
jcar87 requested a review from lasote June 14, 2022 13:04
@memsharded memsharded added this to the 1.50 milestone Jun 14, 2022
Comment thread conan/tools/cmake/presets.py Outdated
@jcar87 jcar87 changed the title Prevent inspection of dictionary key when it does not previously exist Only generate or modify CMakeUserPresets.json if none existed, or existing was previously generated by conan Jun 14, 2022

@memsharded memsharded left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Comment thread conan/tools/cmake/presets.py Outdated
Co-authored-by: James <james@conan.io>
@jcar87
jcar87 marked this pull request as ready for review June 15, 2022 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants