diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2022-02-02 11:30:56 -0500 |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2022-02-02 15:17:30 -0500 |
commit | c18409cdac4d9a8213201eaec53b3cc2d60c68e3 (patch) | |
tree | 27cf6445a79d9d8cb99a08209c6de2844e93f91c | |
parent | 92459258108c0036808f29f83a8503fea18ccee9 (diff) | |
download | cmake-c18409cdac4d9a8213201eaec53b3cc2d60c68e3.tar.gz |
CMakePresets.json: Ensure configurePreset is reachable from current file
12 files changed, 57 insertions, 3 deletions
diff --git a/Source/cmCMakePresetsGraph.cxx b/Source/cmCMakePresetsGraph.cxx index 79e8191b55..705e2b022e 100644 --- a/Source/cmCMakePresetsGraph.cxx +++ b/Source/cmCMakePresetsGraph.cxx @@ -108,7 +108,7 @@ ReadFileResult VisitPreset( auto& parentPreset = parent->second.Unexpanded; if (!preset.OriginFile->ReachableFiles.count(parentPreset.OriginFile)) { - return ReadFileResult::PRESET_UNREACHABLE_FROM_FILE; + return ReadFileResult::INHERITED_PRESET_UNREACHABLE_FROM_FILE; } auto result = VisitPreset(parentPreset, presets, cycleStatus, graph); @@ -925,6 +925,10 @@ cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles) if (configurePreset == this->ConfigurePresets.end()) { return ReadFileResult::INVALID_CONFIGURE_PRESET; } + if (!it.second.Unexpanded.OriginFile->ReachableFiles.count( + configurePreset->second.Unexpanded.OriginFile)) { + return ReadFileResult::CONFIGURE_PRESET_UNREACHABLE_FROM_FILE; + } if (it.second.Unexpanded.InheritConfigureEnvironment.value_or(true)) { it.second.Unexpanded.Environment.insert( @@ -945,6 +949,10 @@ cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles) if (configurePreset == this->ConfigurePresets.end()) { return ReadFileResult::INVALID_CONFIGURE_PRESET; } + if (!it.second.Unexpanded.OriginFile->ReachableFiles.count( + configurePreset->second.Unexpanded.OriginFile)) { + return ReadFileResult::CONFIGURE_PRESET_UNREACHABLE_FROM_FILE; + } if (it.second.Unexpanded.InheritConfigureEnvironment.value_or(true)) { it.second.Unexpanded.Environment.insert( @@ -992,8 +1000,10 @@ const char* cmCMakePresetsGraph::ResultToString(ReadFileResult result) return "Duplicate presets"; case ReadFileResult::CYCLIC_PRESET_INHERITANCE: return "Cyclic preset inheritance"; - case ReadFileResult::PRESET_UNREACHABLE_FROM_FILE: + case ReadFileResult::INHERITED_PRESET_UNREACHABLE_FROM_FILE: return "Inherited preset is unreachable from preset's file"; + case ReadFileResult::CONFIGURE_PRESET_UNREACHABLE_FROM_FILE: + return "Configure preset is unreachable from preset's file"; case ReadFileResult::INVALID_MACRO_EXPANSION: return "Invalid macro expansion"; case ReadFileResult::BUILD_TEST_PRESETS_UNSUPPORTED: diff --git a/Source/cmCMakePresetsGraph.h b/Source/cmCMakePresetsGraph.h index d3a5cfc0ea..9d6c61a99d 100644 --- a/Source/cmCMakePresetsGraph.h +++ b/Source/cmCMakePresetsGraph.h @@ -35,7 +35,8 @@ public: INVALID_VARIABLE, DUPLICATE_PRESETS, CYCLIC_PRESET_INHERITANCE, - PRESET_UNREACHABLE_FROM_FILE, + INHERITED_PRESET_UNREACHABLE_FROM_FILE, + CONFIGURE_PRESET_UNREACHABLE_FROM_FILE, INVALID_MACRO_EXPANSION, BUILD_TEST_PRESETS_UNSUPPORTED, INCLUDE_UNSUPPORTED, diff --git a/Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachable-build-x-result.txt b/Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachable-build-x-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachable-build-x-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachable-build-x-stderr.txt b/Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachable-build-x-stderr.txt new file mode 100644 index 0000000000..05695d9f75 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachable-build-x-stderr.txt @@ -0,0 +1,2 @@ +^CMake Error: Could not read presets from [^ +]*/Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachable: Configure preset is unreachable from preset's file$ diff --git a/Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachable.json.in b/Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachable.json.in new file mode 100644 index 0000000000..f1db4fb48f --- /dev/null +++ b/Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachable.json.in @@ -0,0 +1,9 @@ +{ + "version": 4, + "buildPresets": [ + { + "name": "x", + "configurePreset": "x" + } + ] +} diff --git a/Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachableUser.json.in b/Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachableUser.json.in new file mode 100644 index 0000000000..5319af098a --- /dev/null +++ b/Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachableUser.json.in @@ -0,0 +1,8 @@ +{ + "version": 4, + "configurePresets": [ + { + "name": "x" + } + ] +} diff --git a/Tests/RunCMake/CMakePresetsBuild/RunCMakeTest.cmake b/Tests/RunCMake/CMakePresetsBuild/RunCMakeTest.cmake index 2fe0407a2b..1ededc1a60 100644 --- a/Tests/RunCMake/CMakePresetsBuild/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMakePresetsBuild/RunCMakeTest.cmake @@ -83,4 +83,6 @@ set(CMakePresets_SCHEMA_EXPECTED_RESULT 1) run_cmake_build_presets(PresetsUnsupported "x" "x") run_cmake_build_presets(ConditionFuture "x" "conditionFuture") set(CMakePresets_SCHEMA_EXPECTED_RESULT 0) + +run_cmake_build_presets(ConfigurePresetUnreachable "x" "x") set(CMakePresetsBuild_BUILD_ONLY 0) diff --git a/Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachable-test-x-result.txt b/Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachable-test-x-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachable-test-x-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachable-test-x-stderr.txt b/Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachable-test-x-stderr.txt new file mode 100644 index 0000000000..d49148deb8 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachable-test-x-stderr.txt @@ -0,0 +1,2 @@ +^CMake Error: Could not read presets from [^ +]*/Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachable: Configure preset is unreachable from preset's file$ diff --git a/Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachable.json.in b/Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachable.json.in new file mode 100644 index 0000000000..cc2f149148 --- /dev/null +++ b/Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachable.json.in @@ -0,0 +1,9 @@ +{ + "version": 4, + "testPresets": [ + { + "name": "x", + "configurePreset": "x" + } + ] +} diff --git a/Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachableUser.json.in b/Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachableUser.json.in new file mode 100644 index 0000000000..5319af098a --- /dev/null +++ b/Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachableUser.json.in @@ -0,0 +1,8 @@ +{ + "version": 4, + "configurePresets": [ + { + "name": "x" + } + ] +} diff --git a/Tests/RunCMake/CMakePresetsTest/RunCMakeTest.cmake b/Tests/RunCMake/CMakePresetsTest/RunCMakeTest.cmake index 70d25d4ec1..bec0dd9464 100644 --- a/Tests/RunCMake/CMakePresetsTest/RunCMakeTest.cmake +++ b/Tests/RunCMake/CMakePresetsTest/RunCMakeTest.cmake @@ -106,6 +106,7 @@ set(CMakePresets_SCHEMA_EXPECTED_RESULT 1) run_cmake_test_presets(PresetsUnsupported "" "" "x") run_cmake_test_presets(ConditionFuture "" "" "x") set(CMakePresets_SCHEMA_EXPECTED_RESULT 0) +run_cmake_test_presets(ConfigurePresetUnreachable "" "" "x") set(CMakePresetsTest_NO_CONFIGURE 0) set(CMakePresetsTest_NO_BUILD 0) |