summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2022-02-02 16:30:56 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2022-02-02 20:17:30 (GMT)
commitc18409cdac4d9a8213201eaec53b3cc2d60c68e3 (patch)
tree27cf6445a79d9d8cb99a08209c6de2844e93f91c
parent92459258108c0036808f29f83a8503fea18ccee9 (diff)
downloadCMake-c18409cdac4d9a8213201eaec53b3cc2d60c68e3.zip
CMake-c18409cdac4d9a8213201eaec53b3cc2d60c68e3.tar.gz
CMake-c18409cdac4d9a8213201eaec53b3cc2d60c68e3.tar.bz2
CMakePresets.json: Ensure configurePreset is reachable from current file
-rw-r--r--Source/cmCMakePresetsGraph.cxx14
-rw-r--r--Source/cmCMakePresetsGraph.h3
-rw-r--r--Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachable-build-x-result.txt1
-rw-r--r--Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachable-build-x-stderr.txt2
-rw-r--r--Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachable.json.in9
-rw-r--r--Tests/RunCMake/CMakePresetsBuild/ConfigurePresetUnreachableUser.json.in8
-rw-r--r--Tests/RunCMake/CMakePresetsBuild/RunCMakeTest.cmake2
-rw-r--r--Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachable-test-x-result.txt1
-rw-r--r--Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachable-test-x-stderr.txt2
-rw-r--r--Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachable.json.in9
-rw-r--r--Tests/RunCMake/CMakePresetsTest/ConfigurePresetUnreachableUser.json.in8
-rw-r--r--Tests/RunCMake/CMakePresetsTest/RunCMakeTest.cmake1
12 files changed, 57 insertions, 3 deletions
diff --git a/Source/cmCMakePresetsGraph.cxx b/Source/cmCMakePresetsGraph.cxx
index 79e8191..705e2b0 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 d3a5cfc..9d6c61a 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 0000000..d00491f
--- /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 0000000..05695d9
--- /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 0000000..f1db4fb
--- /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 0000000..5319af0
--- /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 2fe0407..1ededc1 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 0000000..d00491f
--- /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 0000000..d49148d
--- /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 0000000..cc2f149
--- /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 0000000..5319af0
--- /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 70d25d4..bec0dd94 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)