summaryrefslogtreecommitdiffstats
path: root/Source/cmCMakePresetsGraphReadJSONBuildPresets.cxx
diff options
context:
space:
mode:
authorMartin Duffy <martin.duffy@kitware.com>2023-03-22 17:11:21 (GMT)
committerBrad King <brad.king@kitware.com>2023-03-29 14:41:19 (GMT)
commit19305afd8a2a46925b1a880de68f7be0ad1f3091 (patch)
treecdef4417cd852c2a5dd85886df4ff61d7fd2e653 /Source/cmCMakePresetsGraphReadJSONBuildPresets.cxx
parent6b08358e17f5b85ad04ab512e4b6e39e989cea35 (diff)
downloadCMake-19305afd8a2a46925b1a880de68f7be0ad1f3091.zip
CMake-19305afd8a2a46925b1a880de68f7be0ad1f3091.tar.gz
CMake-19305afd8a2a46925b1a880de68f7be0ad1f3091.tar.bz2
presets: Improve JSON parser and error messages
Diffstat (limited to 'Source/cmCMakePresetsGraphReadJSONBuildPresets.cxx')
-rw-r--r--Source/cmCMakePresetsGraphReadJSONBuildPresets.cxx45
1 files changed, 24 insertions, 21 deletions
diff --git a/Source/cmCMakePresetsGraphReadJSONBuildPresets.cxx b/Source/cmCMakePresetsGraphReadJSONBuildPresets.cxx
index 430d7ee..07f2bc3 100644
--- a/Source/cmCMakePresetsGraphReadJSONBuildPresets.cxx
+++ b/Source/cmCMakePresetsGraphReadJSONBuildPresets.cxx
@@ -13,25 +13,27 @@
#include <cm3p/json/value.h>
#include "cmBuildOptions.h"
+#include "cmCMakePresetErrors.h"
#include "cmCMakePresetsGraph.h"
#include "cmCMakePresetsGraphInternal.h"
#include "cmJSONHelpers.h"
+class cmJSONState;
namespace {
-using ReadFileResult = cmCMakePresetsGraph::ReadFileResult;
using BuildPreset = cmCMakePresetsGraph::BuildPreset;
-using JSONHelperBuilder = cmJSONHelperBuilder<ReadFileResult>;
+using JSONHelperBuilder = cmJSONHelperBuilder;
-ReadFileResult PackageResolveModeHelper(cm::optional<PackageResolveMode>& out,
- const Json::Value* value)
+bool PackageResolveModeHelper(cm::optional<PackageResolveMode>& out,
+ const Json::Value* value, cmJSONState* state)
{
if (!value) {
out = cm::nullopt;
- return ReadFileResult::READ_OK;
+ return true;
}
if (!value->isString()) {
- return ReadFileResult::INVALID_PRESET;
+ cmCMakePresetErrors::INVALID_PRESET(value, state);
+ return false;
}
if (value->asString() == "on") {
@@ -41,23 +43,25 @@ ReadFileResult PackageResolveModeHelper(cm::optional<PackageResolveMode>& out,
} else if (value->asString() == "only") {
out = PackageResolveMode::OnlyResolve;
} else {
- return ReadFileResult::INVALID_PRESET;
+ cmCMakePresetErrors::INVALID_PRESET(value, state);
+ return false;
}
- return ReadFileResult::READ_OK;
+ return true;
}
-std::function<ReadFileResult(BuildPreset&, const Json::Value*)> const
- ResolvePackageReferencesHelper =
- [](BuildPreset& out, const Json::Value* value) -> ReadFileResult {
- return PackageResolveModeHelper(out.ResolvePackageReferences, value);
+std::function<bool(BuildPreset&, const Json::Value*, cmJSONState*)> const
+ ResolvePackageReferencesHelper = [](BuildPreset& out,
+ const Json::Value* value,
+ cmJSONState* state) -> bool {
+ return PackageResolveModeHelper(out.ResolvePackageReferences, value, state);
};
auto const BuildPresetHelper =
- JSONHelperBuilder::Object<BuildPreset>(ReadFileResult::READ_OK,
- ReadFileResult::INVALID_PRESET, false)
+ JSONHelperBuilder::Object<BuildPreset>(
+ cmCMakePresetErrors::INVALID_PRESET_OBJECT, false)
.Bind("name"_s, &BuildPreset::Name,
- cmCMakePresetsGraphInternal::PresetStringHelper)
+ cmCMakePresetsGraphInternal::PresetNameHelper)
.Bind("inherits"_s, &BuildPreset::Inherits,
cmCMakePresetsGraphInternal::PresetVectorOneOrMoreStringHelper,
false)
@@ -65,7 +69,7 @@ auto const BuildPresetHelper =
cmCMakePresetsGraphInternal::PresetBoolHelper, false)
.Bind<std::nullptr_t>("vendor"_s, nullptr,
cmCMakePresetsGraphInternal::VendorHelper(
- ReadFileResult::INVALID_PRESET),
+ cmCMakePresetErrors::INVALID_PRESET),
false)
.Bind("displayName"_s, &BuildPreset::DisplayName,
cmCMakePresetsGraphInternal::PresetStringHelper, false)
@@ -97,13 +101,12 @@ auto const BuildPresetHelper =
}
namespace cmCMakePresetsGraphInternal {
-ReadFileResult BuildPresetsHelper(std::vector<BuildPreset>& out,
- const Json::Value* value)
+bool BuildPresetsHelper(std::vector<BuildPreset>& out,
+ const Json::Value* value, cmJSONState* state)
{
static auto const helper = JSONHelperBuilder::Vector<BuildPreset>(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_PRESETS,
- BuildPresetHelper);
+ cmCMakePresetErrors::INVALID_PRESETS, BuildPresetHelper);
- return helper(out, value);
+ return helper(out, value, state);
}
}