summaryrefslogtreecommitdiffstats
path: root/Source/cmCMakePresetsGraphReadJSON.cxx
diff options
context:
space:
mode:
authorAlex Turbov <i.zaufi@gmail.com>2024-08-13 18:39:21 (GMT)
committerAlex Turbov <i.zaufi@gmail.com>2024-08-15 18:01:34 (GMT)
commit0b334e5bfb6bca7411b75cb0dd0715bc85bc68eb (patch)
tree2211558444609e4f8d07cac3c5abb7cd99da7766 /Source/cmCMakePresetsGraphReadJSON.cxx
parent503a73b1832dde9685a44c2ee9cc904e39aeaee4 (diff)
downloadCMake-0b334e5bfb6bca7411b75cb0dd0715bc85bc68eb.zip
CMake-0b334e5bfb6bca7411b75cb0dd0715bc85bc68eb.tar.gz
CMake-0b334e5bfb6bca7411b75cb0dd0715bc85bc68eb.tar.bz2
cmJSONHelpers.h: Add generic predicate checking helper
And use it in the `cmCMakePresetsGraphReadJSON.cxx` to check presets schema version in the declarative way. Co-authored-by: Martin Duffy <martin.duffy@kitware.com>
Diffstat (limited to 'Source/cmCMakePresetsGraphReadJSON.cxx')
-rw-r--r--Source/cmCMakePresetsGraphReadJSON.cxx12
1 files changed, 6 insertions, 6 deletions
diff --git a/Source/cmCMakePresetsGraphReadJSON.cxx b/Source/cmCMakePresetsGraphReadJSON.cxx
index df6482d..18ae9af 100644
--- a/Source/cmCMakePresetsGraphReadJSON.cxx
+++ b/Source/cmCMakePresetsGraphReadJSON.cxx
@@ -256,9 +256,14 @@ auto const VersionIntHelper =
auto const VersionHelper = JSONHelperBuilder::Required<int>(
cmCMakePresetsErrors::NO_VERSION, VersionIntHelper);
+auto const VersionRangeHelper = JSONHelperBuilder::Checked<int>(
+ cmCMakePresetsErrors::UNRECOGNIZED_VERSION_RANGE(MIN_VERSION, MAX_VERSION),
+ VersionHelper,
+ [](const int v) -> bool { return v >= MIN_VERSION && v <= MAX_VERSION; });
+
auto const RootVersionHelper =
JSONHelperBuilder::Object<int>(cmCMakePresetsErrors::INVALID_ROOT_OBJECT)
- .Bind("version"_s, VersionHelper, false);
+ .Bind("version"_s, VersionRangeHelper, false);
auto const CMakeVersionUIntHelper =
JSONHelperBuilder::UInt(cmCMakePresetsErrors::INVALID_VERSION);
@@ -481,11 +486,6 @@ bool cmCMakePresetsGraph::ReadJSONFile(const std::string& filename,
if ((result = RootVersionHelper(v, &root, &parseState)) != true) {
return result;
}
- if (v < MIN_VERSION || v > MAX_VERSION) {
- cmCMakePresetsErrors::UNRECOGNIZED_VERSION(&root["version"],
- &this->parseState);
- return false;
- }
// Support for build and test presets added in version 2.
if (v < 2) {