summaryrefslogtreecommitdiffstats
path: root/Source/cmCMakePresetsGraphReadJSON.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmCMakePresetsGraphReadJSON.cxx')
-rw-r--r--Source/cmCMakePresetsGraphReadJSON.cxx426
1 files changed, 228 insertions, 198 deletions
diff --git a/Source/cmCMakePresetsGraphReadJSON.cxx b/Source/cmCMakePresetsGraphReadJSON.cxx
index a96ab58..93c5f7d 100644
--- a/Source/cmCMakePresetsGraphReadJSON.cxx
+++ b/Source/cmCMakePresetsGraphReadJSON.cxx
@@ -1,6 +1,7 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include <algorithm>
+#include <fstream>
#include <functional>
#include <map>
#include <string>
@@ -12,20 +13,18 @@
#include <cm/optional>
#include <cmext/string_view>
-#include <cm3p/json/reader.h>
#include <cm3p/json/value.h>
-#include "cmsys/FStream.hxx"
-
+#include "cmCMakePresetErrors.h"
#include "cmCMakePresetsGraph.h"
#include "cmCMakePresetsGraphInternal.h"
#include "cmJSONHelpers.h"
+#include "cmJSONState.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmVersion.h"
namespace {
-using ReadFileResult = cmCMakePresetsGraph::ReadFileResult;
using CacheVariable = cmCMakePresetsGraph::CacheVariable;
using ConfigurePreset = cmCMakePresetsGraph::ConfigurePreset;
using BuildPreset = cmCMakePresetsGraph::BuildPreset;
@@ -33,7 +32,7 @@ using TestPreset = cmCMakePresetsGraph::TestPreset;
using PackagePreset = cmCMakePresetsGraph::PackagePreset;
using WorkflowPreset = cmCMakePresetsGraph::WorkflowPreset;
using ArchToolsetStrategy = cmCMakePresetsGraph::ArchToolsetStrategy;
-using JSONHelperBuilder = cmJSONHelperBuilder<ReadFileResult>;
+using JSONHelperBuilder = cmJSONHelperBuilder;
constexpr int MIN_VERSION = 1;
constexpr int MAX_VERSION = 6;
@@ -64,26 +63,23 @@ std::unique_ptr<cmCMakePresetsGraphInternal::NotCondition> InvertCondition(
return retval;
}
-auto const ConditionStringHelper = JSONHelperBuilder::String(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_CONDITION);
+auto const ConditionStringHelper = JSONHelperBuilder::String();
-auto const ConditionBoolHelper = JSONHelperBuilder::Bool(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_CONDITION);
+auto const ConditionBoolHelper = JSONHelperBuilder::Bool();
auto const ConditionStringListHelper = JSONHelperBuilder::Vector<std::string>(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_CONDITION,
- ConditionStringHelper);
+ cmCMakePresetErrors::INVALID_CONDITION, ConditionStringHelper);
auto const ConstConditionHelper =
JSONHelperBuilder::Object<cmCMakePresetsGraphInternal::ConstCondition>(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_CONDITION, false)
+ cmCMakePresetErrors::INVALID_CONDITION_OBJECT, false)
.Bind<std::string>("type"_s, nullptr, ConditionStringHelper, true)
.Bind("value"_s, &cmCMakePresetsGraphInternal::ConstCondition::Value,
ConditionBoolHelper, true);
auto const EqualsConditionHelper =
JSONHelperBuilder::Object<cmCMakePresetsGraphInternal::EqualsCondition>(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_CONDITION, false)
+ cmCMakePresetErrors::INVALID_CONDITION_OBJECT, false)
.Bind<std::string>("type"_s, nullptr, ConditionStringHelper, true)
.Bind("lhs"_s, &cmCMakePresetsGraphInternal::EqualsCondition::Lhs,
ConditionStringHelper, true)
@@ -92,7 +88,7 @@ auto const EqualsConditionHelper =
auto const InListConditionHelper =
JSONHelperBuilder::Object<cmCMakePresetsGraphInternal::InListCondition>(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_CONDITION, false)
+ cmCMakePresetErrors::INVALID_CONDITION_OBJECT, false)
.Bind<std::string>("type"_s, nullptr, ConditionStringHelper, true)
.Bind("string"_s, &cmCMakePresetsGraphInternal::InListCondition::String,
ConditionStringHelper, true)
@@ -101,24 +97,22 @@ auto const InListConditionHelper =
auto const MatchesConditionHelper =
JSONHelperBuilder::Object<cmCMakePresetsGraphInternal::MatchesCondition>(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_CONDITION, false)
+ cmCMakePresetErrors::INVALID_CONDITION_OBJECT, false)
.Bind<std::string>("type"_s, nullptr, ConditionStringHelper, true)
.Bind("string"_s, &cmCMakePresetsGraphInternal::MatchesCondition::String,
ConditionStringHelper, true)
.Bind("regex"_s, &cmCMakePresetsGraphInternal::MatchesCondition::Regex,
ConditionStringHelper, true);
-ReadFileResult SubConditionHelper(
- std::unique_ptr<cmCMakePresetsGraph::Condition>& out,
- const Json::Value* value);
+bool SubConditionHelper(std::unique_ptr<cmCMakePresetsGraph::Condition>& out,
+ const Json::Value* value, cmJSONState* state);
auto const ListConditionVectorHelper =
JSONHelperBuilder::Vector<std::unique_ptr<cmCMakePresetsGraph::Condition>>(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_CONDITION,
- SubConditionHelper);
+ cmCMakePresetErrors::INVALID_CONDITION, SubConditionHelper);
auto const AnyAllOfConditionHelper =
JSONHelperBuilder::Object<cmCMakePresetsGraphInternal::AnyAllOfCondition>(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_CONDITION, false)
+ cmCMakePresetErrors::INVALID_CONDITION_OBJECT, false)
.Bind<std::string>("type"_s, nullptr, ConditionStringHelper, true)
.Bind("conditions"_s,
&cmCMakePresetsGraphInternal::AnyAllOfCondition::Conditions,
@@ -126,158 +120,160 @@ auto const AnyAllOfConditionHelper =
auto const NotConditionHelper =
JSONHelperBuilder::Object<cmCMakePresetsGraphInternal::NotCondition>(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_CONDITION, false)
+ cmCMakePresetErrors::INVALID_CONDITION_OBJECT, false)
.Bind<std::string>("type"_s, nullptr, ConditionStringHelper, true)
.Bind("condition"_s,
&cmCMakePresetsGraphInternal::NotCondition::SubCondition,
SubConditionHelper);
-ReadFileResult ConditionHelper(
- std::unique_ptr<cmCMakePresetsGraph::Condition>& out,
- const Json::Value* value)
+bool ConditionHelper(std::unique_ptr<cmCMakePresetsGraph::Condition>& out,
+ const Json::Value* value, cmJSONState* state)
{
if (!value) {
out.reset();
- return ReadFileResult::READ_OK;
+ return true;
}
if (value->isBool()) {
auto c = cm::make_unique<cmCMakePresetsGraphInternal::ConstCondition>();
c->Value = value->asBool();
out = std::move(c);
- return ReadFileResult::READ_OK;
+ return true;
}
if (value->isNull()) {
out = cm::make_unique<cmCMakePresetsGraphInternal::NullCondition>();
- return ReadFileResult::READ_OK;
+ return true;
}
if (value->isObject()) {
if (!value->isMember("type")) {
- return ReadFileResult::INVALID_CONDITION;
+ cmCMakePresetErrors::INVALID_CONDITION(value, state);
+ return false;
}
if (!(*value)["type"].isString()) {
- return ReadFileResult::INVALID_CONDITION;
+ cmCMakePresetErrors::INVALID_CONDITION(value, state);
+ return false;
}
auto type = (*value)["type"].asString();
if (type == "const") {
auto c = cm::make_unique<cmCMakePresetsGraphInternal::ConstCondition>();
- CHECK_OK(ConstConditionHelper(*c, value));
+ CHECK_OK(ConstConditionHelper(*c, value, state));
out = std::move(c);
- return ReadFileResult::READ_OK;
+ return true;
}
if (type == "equals" || type == "notEquals") {
auto c = cm::make_unique<cmCMakePresetsGraphInternal::EqualsCondition>();
- CHECK_OK(EqualsConditionHelper(*c, value));
+ CHECK_OK(EqualsConditionHelper(*c, value, state));
out = std::move(c);
if (type == "notEquals") {
out = InvertCondition(std::move(out));
}
- return ReadFileResult::READ_OK;
+ return true;
}
if (type == "inList" || type == "notInList") {
auto c = cm::make_unique<cmCMakePresetsGraphInternal::InListCondition>();
- CHECK_OK(InListConditionHelper(*c, value));
+ CHECK_OK(InListConditionHelper(*c, value, state));
out = std::move(c);
if (type == "notInList") {
out = InvertCondition(std::move(out));
}
- return ReadFileResult::READ_OK;
+ return true;
}
if (type == "matches" || type == "notMatches") {
auto c =
cm::make_unique<cmCMakePresetsGraphInternal::MatchesCondition>();
- CHECK_OK(MatchesConditionHelper(*c, value));
+ CHECK_OK(MatchesConditionHelper(*c, value, state));
out = std::move(c);
if (type == "notMatches") {
out = InvertCondition(std::move(out));
}
- return ReadFileResult::READ_OK;
+ return true;
}
if (type == "anyOf" || type == "allOf") {
auto c =
cm::make_unique<cmCMakePresetsGraphInternal::AnyAllOfCondition>();
c->StopValue = (type == "anyOf");
- CHECK_OK(AnyAllOfConditionHelper(*c, value));
+ CHECK_OK(AnyAllOfConditionHelper(*c, value, state));
out = std::move(c);
- return ReadFileResult::READ_OK;
+ return true;
}
if (type == "not") {
auto c = cm::make_unique<cmCMakePresetsGraphInternal::NotCondition>();
- CHECK_OK(NotConditionHelper(*c, value));
+ CHECK_OK(NotConditionHelper(*c, value, state));
out = std::move(c);
- return ReadFileResult::READ_OK;
+ return true;
}
}
- return ReadFileResult::INVALID_CONDITION;
+ cmCMakePresetErrors::INVALID_CONDITION(value, state);
+ return false;
}
-ReadFileResult SubConditionHelper(
- std::unique_ptr<cmCMakePresetsGraph::Condition>& out,
- const Json::Value* value)
+bool SubConditionHelper(std::unique_ptr<cmCMakePresetsGraph::Condition>& out,
+ const Json::Value* value, cmJSONState* state)
{
std::unique_ptr<cmCMakePresetsGraph::Condition> ptr;
- auto result = ConditionHelper(ptr, value);
+ auto result = ConditionHelper(ptr, value, state);
if (ptr && ptr->IsNull()) {
- return ReadFileResult::INVALID_CONDITION;
+ cmCMakePresetErrors::INVALID_CONDITION(value, state);
+ return false;
}
out = std::move(ptr);
return result;
}
-ReadFileResult EnvironmentHelper(cm::optional<std::string>& out,
- const Json::Value* value)
+bool EnvironmentHelper(cm::optional<std::string>& out,
+ const Json::Value* value, cmJSONState* state)
{
if (!value || value->isNull()) {
out = cm::nullopt;
- return ReadFileResult::READ_OK;
+ return true;
}
if (value->isString()) {
out = value->asString();
- return ReadFileResult::READ_OK;
+ return true;
}
- return ReadFileResult::INVALID_PRESET;
+ cmCMakePresetErrors::INVALID_PRESET(value, state);
+ return false;
}
-auto const VersionIntHelper = JSONHelperBuilder::Int(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_VERSION);
+auto const VersionIntHelper =
+ JSONHelperBuilder::Int(cmCMakePresetErrors::INVALID_VERSION);
auto const VersionHelper = JSONHelperBuilder::Required<int>(
- ReadFileResult::NO_VERSION, VersionIntHelper);
+ cmCMakePresetErrors::NO_VERSION, VersionIntHelper);
auto const RootVersionHelper =
- JSONHelperBuilder::Object<int>(ReadFileResult::READ_OK,
- ReadFileResult::INVALID_ROOT)
+ JSONHelperBuilder::Object<int>(cmCMakePresetErrors::INVALID_ROOT_OBJECT)
.Bind("version"_s, VersionHelper, false);
-auto const CMakeVersionUIntHelper = JSONHelperBuilder::UInt(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_VERSION);
+auto const CMakeVersionUIntHelper =
+ JSONHelperBuilder::UInt(cmCMakePresetErrors::INVALID_VERSION);
auto const CMakeVersionHelper =
- JSONHelperBuilder::Object<CMakeVersion>(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_CMAKE_VERSION, false)
+ JSONHelperBuilder::Object<CMakeVersion>(JsonErrors::INVALID_NAMED_OBJECT_KEY,
+ false)
.Bind("major"_s, &CMakeVersion::Major, CMakeVersionUIntHelper, false)
.Bind("minor"_s, &CMakeVersion::Minor, CMakeVersionUIntHelper, false)
.Bind("patch"_s, &CMakeVersion::Patch, CMakeVersionUIntHelper, false);
-auto const IncludeHelper = JSONHelperBuilder::String(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_INCLUDE);
+auto const IncludeHelper =
+ JSONHelperBuilder::String(cmCMakePresetErrors::INVALID_INCLUDE);
auto const IncludeVectorHelper = JSONHelperBuilder::Vector<std::string>(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_INCLUDE, IncludeHelper);
+ cmCMakePresetErrors::INVALID_INCLUDE, IncludeHelper);
auto const RootPresetsHelper =
- JSONHelperBuilder::Object<RootPresets>(ReadFileResult::READ_OK,
- ReadFileResult::INVALID_ROOT, false)
+ JSONHelperBuilder::Object<RootPresets>(
+ cmCMakePresetErrors::INVALID_ROOT_OBJECT, false)
.Bind<int>("version"_s, nullptr, VersionHelper)
.Bind("configurePresets"_s, &RootPresets::ConfigurePresets,
cmCMakePresetsGraphInternal::ConfigurePresetsHelper, false)
@@ -292,136 +288,137 @@ auto const RootPresetsHelper =
.Bind("cmakeMinimumRequired"_s, &RootPresets::CMakeMinimumRequired,
CMakeVersionHelper, false)
.Bind("include"_s, &RootPresets::Include, IncludeVectorHelper, false)
- .Bind<std::nullptr_t>(
- "vendor"_s, nullptr,
- cmCMakePresetsGraphInternal::VendorHelper(ReadFileResult::INVALID_ROOT),
- false);
+ .Bind<std::nullptr_t>("vendor"_s, nullptr,
+ cmCMakePresetsGraphInternal::VendorHelper(
+ cmCMakePresetErrors::INVALID_ROOT),
+ false);
}
namespace cmCMakePresetsGraphInternal {
-cmCMakePresetsGraph::ReadFileResult PresetStringHelper(
- std::string& out, const Json::Value* value)
+bool PresetStringHelper(std::string& out, const Json::Value* value,
+ cmJSONState* state)
{
- static auto const helper = JSONHelperBuilder::String(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_PRESET);
+ static auto const helper = JSONHelperBuilder::String();
+ return helper(out, value, state);
+}
- return helper(out, value);
+bool PresetNameHelper(std::string& out, const Json::Value* value,
+ cmJSONState* state)
+{
+ if (!value || !value->isString() || value->asString().empty()) {
+ cmCMakePresetErrors::INVALID_PRESET_NAME(value, state);
+ return false;
+ }
+ out = value->asString();
+ return true;
}
-cmCMakePresetsGraph::ReadFileResult PresetVectorStringHelper(
- std::vector<std::string>& out, const Json::Value* value)
+bool PresetVectorStringHelper(std::vector<std::string>& out,
+ const Json::Value* value, cmJSONState* state)
{
static auto const helper = JSONHelperBuilder::Vector<std::string>(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_PRESET,
+ cmCMakePresetErrors::INVALID_PRESET,
cmCMakePresetsGraphInternal::PresetStringHelper);
-
- return helper(out, value);
+ return helper(out, value, state);
}
-cmCMakePresetsGraph::ReadFileResult PresetBoolHelper(bool& out,
- const Json::Value* value)
+bool PresetBoolHelper(bool& out, const Json::Value* value, cmJSONState* state)
{
- static auto const helper = JSONHelperBuilder::Bool(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_PRESET);
-
- return helper(out, value);
+ static auto const helper = JSONHelperBuilder::Bool();
+ return helper(out, value, state);
}
-cmCMakePresetsGraph::ReadFileResult PresetOptionalBoolHelper(
- cm::optional<bool>& out, const Json::Value* value)
+bool PresetOptionalBoolHelper(cm::optional<bool>& out,
+ const Json::Value* value, cmJSONState* state)
{
- static auto const helper = JSONHelperBuilder::Optional<bool>(
- ReadFileResult::READ_OK, PresetBoolHelper);
-
- return helper(out, value);
+ static auto const helper =
+ JSONHelperBuilder::Optional<bool>(PresetBoolHelper);
+ return helper(out, value, state);
}
-cmCMakePresetsGraph::ReadFileResult PresetIntHelper(int& out,
- const Json::Value* value)
+bool PresetIntHelper(int& out, const Json::Value* value, cmJSONState* state)
{
- static auto const helper = JSONHelperBuilder::Int(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_PRESET);
-
- return helper(out, value);
+ static auto const helper = JSONHelperBuilder::Int();
+ return helper(out, value, state);
}
-cmCMakePresetsGraph::ReadFileResult PresetOptionalIntHelper(
- cm::optional<int>& out, const Json::Value* value)
+bool PresetOptionalIntHelper(cm::optional<int>& out, const Json::Value* value,
+ cmJSONState* state)
{
- static auto const helper =
- JSONHelperBuilder::Optional<int>(ReadFileResult::READ_OK, PresetIntHelper);
-
- return helper(out, value);
+ static auto const helper = JSONHelperBuilder::Optional<int>(PresetIntHelper);
+ return helper(out, value, state);
}
-cmCMakePresetsGraph::ReadFileResult PresetVectorIntHelper(
- std::vector<int>& out, const Json::Value* value)
+bool PresetVectorIntHelper(std::vector<int>& out, const Json::Value* value,
+ cmJSONState* state)
{
static auto const helper = JSONHelperBuilder::Vector<int>(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_PRESET, PresetIntHelper);
-
- return helper(out, value);
+ cmCMakePresetErrors::INVALID_PRESET, PresetIntHelper);
+ return helper(out, value, state);
}
-cmJSONHelper<std::nullptr_t, ReadFileResult> VendorHelper(ReadFileResult error)
+cmJSONHelper<std::nullptr_t> VendorHelper(const ErrorGenerator& error)
{
- return [error](std::nullptr_t& /*out*/,
- const Json::Value* value) -> ReadFileResult {
+ return [error](std::nullptr_t& /*out*/, const Json::Value* value,
+ cmJSONState* state) -> bool {
if (!value) {
- return ReadFileResult::READ_OK;
+ return true;
}
if (!value->isObject()) {
- return error;
+ error(value, state);
+ return false;
}
- return ReadFileResult::READ_OK;
+ return true;
};
}
-ReadFileResult PresetConditionHelper(
+bool PresetConditionHelper(
std::shared_ptr<cmCMakePresetsGraph::Condition>& out,
- const Json::Value* value)
+ const Json::Value* value, cmJSONState* state)
{
std::unique_ptr<cmCMakePresetsGraph::Condition> ptr;
- auto result = ConditionHelper(ptr, value);
+ auto result = ConditionHelper(ptr, value, state);
out = std::move(ptr);
return result;
}
-ReadFileResult PresetVectorOneOrMoreStringHelper(std::vector<std::string>& out,
- const Json::Value* value)
+bool PresetVectorOneOrMoreStringHelper(std::vector<std::string>& out,
+ const Json::Value* value,
+ cmJSONState* state)
{
out.clear();
if (!value) {
- return ReadFileResult::READ_OK;
+ return true;
}
if (value->isString()) {
out.push_back(value->asString());
- return ReadFileResult::READ_OK;
+ return true;
}
- return PresetVectorStringHelper(out, value);
+ return PresetVectorStringHelper(out, value, state);
}
-cmCMakePresetsGraph::ReadFileResult EnvironmentMapHelper(
+bool EnvironmentMapHelper(
std::map<std::string, cm::optional<std::string>>& out,
- const Json::Value* value)
+ const Json::Value* value, cmJSONState* state)
{
static auto const helper = JSONHelperBuilder::Map<cm::optional<std::string>>(
- ReadFileResult::READ_OK, ReadFileResult::INVALID_PRESET,
- EnvironmentHelper);
+ cmCMakePresetErrors::INVALID_PRESET, EnvironmentHelper);
- return helper(out, value);
+ return helper(out, value, state);
}
}
-cmCMakePresetsGraph::ReadFileResult cmCMakePresetsGraph::ReadJSONFile(
- const std::string& filename, RootType rootType, ReadReason readReason,
- std::vector<File*>& inProgressFiles, File*& file, std::string& errMsg)
+bool cmCMakePresetsGraph::ReadJSONFile(const std::string& filename,
+ RootType rootType,
+ ReadReason readReason,
+ std::vector<File*>& inProgressFiles,
+ File*& file, std::string& errMsg)
{
- ReadFileResult result;
+ bool result;
for (auto const& f : this->Files) {
if (cmSystemTools::SameFile(filename, f->Filename)) {
@@ -429,61 +426,67 @@ cmCMakePresetsGraph::ReadFileResult cmCMakePresetsGraph::ReadJSONFile(
auto fileIt =
std::find(inProgressFiles.begin(), inProgressFiles.end(), file);
if (fileIt != inProgressFiles.end()) {
- return cmCMakePresetsGraph::ReadFileResult::CYCLIC_INCLUDE;
+ cmCMakePresetErrors::CYCLIC_INCLUDE(filename, &this->parseState);
+ return false;
}
- return cmCMakePresetsGraph::ReadFileResult::READ_OK;
+ return true;
}
}
- cmsys::ifstream fin(filename.c_str());
- if (!fin) {
- errMsg = cmStrCat(filename, ": Failed to read file\n", errMsg);
- return ReadFileResult::FILE_NOT_FOUND;
- }
- // If there's a BOM, toss it.
- cmsys::FStream::ReadBOM(fin);
-
Json::Value root;
- Json::CharReaderBuilder builder;
- Json::CharReaderBuilder::strictMode(&builder.settings_);
- if (!Json::parseFromStream(builder, fin, &root, &errMsg)) {
- errMsg = cmStrCat(filename, ":\n", errMsg);
- return ReadFileResult::JSON_PARSE_ERROR;
+ this->parseState = cmJSONState(filename, &root);
+ if (!this->parseState.errors.empty()) {
+ return false;
}
int v = 0;
- if ((result = RootVersionHelper(v, &root)) != ReadFileResult::READ_OK) {
+ if ((result = RootVersionHelper(v, &root, &parseState)) != true) {
return result;
}
if (v < MIN_VERSION || v > MAX_VERSION) {
- return ReadFileResult::UNRECOGNIZED_VERSION;
+ cmCMakePresetErrors::UNRECOGNIZED_VERSION(&root["version"],
+ &this->parseState);
+ return false;
}
// Support for build and test presets added in version 2.
- if (v < 2 &&
- (root.isMember("buildPresets") || root.isMember("testPresets"))) {
- return ReadFileResult::BUILD_TEST_PRESETS_UNSUPPORTED;
+ if (v < 2) {
+ if (root.isMember("buildPresets")) {
+ cmCMakePresetErrors::BUILD_TEST_PRESETS_UNSUPPORTED(
+ &root["buildPresets"], &this->parseState);
+ return false;
+ }
+ if (root.isMember("testPresets")) {
+ cmCMakePresetErrors::BUILD_TEST_PRESETS_UNSUPPORTED(&root["testPresets"],
+ &this->parseState);
+ return false;
+ }
}
// Support for package presets added in version 6.
if (v < 6 && root.isMember("packagePresets")) {
- return ReadFileResult::PACKAGE_PRESETS_UNSUPPORTED;
+ cmCMakePresetErrors::PACKAGE_PRESETS_UNSUPPORTED(&root["packagePresets"],
+ &this->parseState);
+ return false;
}
// Support for workflow presets added in version 6.
if (v < 6 && root.isMember("workflowPresets")) {
- return ReadFileResult::WORKFLOW_PRESETS_UNSUPPORTED;
+ cmCMakePresetErrors::WORKFLOW_PRESETS_UNSUPPORTED(&root["workflowPresets"],
+ &this->parseState);
+ return false;
}
// Support for include added in version 4.
if (v < 4 && root.isMember("include")) {
- return ReadFileResult::INCLUDE_UNSUPPORTED;
+ cmCMakePresetErrors::INCLUDE_UNSUPPORTED(&root["include"],
+ &this->parseState);
+ return false;
}
RootPresets presets;
- if ((result = RootPresetsHelper(presets, &root)) !=
- ReadFileResult::READ_OK) {
+ if ((result = RootPresetsHelper(presets, &root, &parseState)) != true) {
return result;
}
@@ -491,12 +494,25 @@ cmCMakePresetsGraph::ReadFileResult cmCMakePresetsGraph::ReadJSONFile(
unsigned int currentMinor = cmVersion::GetMinorVersion();
unsigned int currentPatch = cmVersion::GetPatchVersion();
auto const& required = presets.CMakeMinimumRequired;
- if (required.Major > currentMajor ||
- (required.Major == currentMajor &&
- (required.Minor > currentMinor ||
- (required.Minor == currentMinor &&
- (required.Patch > currentPatch))))) {
- return ReadFileResult::UNRECOGNIZED_CMAKE_VERSION;
+ if (required.Major > currentMajor) {
+ ErrorGenerator error = cmCMakePresetErrors::UNRECOGNIZED_CMAKE_VERSION(
+ "major", currentMajor, required.Major);
+ error(&root["cmakeMinimumRequired"]["major"], &this->parseState);
+ return false;
+ }
+ if (required.Major == currentMajor) {
+ if (required.Minor > currentMinor) {
+ ErrorGenerator error = cmCMakePresetErrors::UNRECOGNIZED_CMAKE_VERSION(
+ "minor", currentMinor, required.Minor);
+ error(&root["cmakeMinimumRequired"]["minor"], &this->parseState);
+ return false;
+ }
+ if (required.Minor == currentMinor && required.Patch > currentPatch) {
+ ErrorGenerator error = cmCMakePresetErrors::UNRECOGNIZED_CMAKE_VERSION(
+ "patch", currentPatch, required.Patch);
+ error(&root["cmakeMinimumRequired"]["patch"], &this->parseState);
+ return false;
+ }
}
auto filePtr = cm::make_unique<File>();
@@ -510,31 +526,35 @@ cmCMakePresetsGraph::ReadFileResult cmCMakePresetsGraph::ReadJSONFile(
for (auto& preset : presets.ConfigurePresets) {
preset.OriginFile = file;
if (preset.Name.empty()) {
- errMsg += R"(\n\t)";
- errMsg += filename;
- return ReadFileResult::INVALID_PRESET;
+ // No error, already handled by PresetNameHelper
+ return false;
}
PresetPair<ConfigurePreset> presetPair;
presetPair.Unexpanded = preset;
presetPair.Expanded = cm::nullopt;
if (!this->ConfigurePresets.emplace(preset.Name, presetPair).second) {
- return ReadFileResult::DUPLICATE_PRESETS;
+ cmCMakePresetErrors::DUPLICATE_PRESETS(preset.Name, &this->parseState);
+ return false;
}
// Support for installDir presets added in version 3.
if (v < 3 && !preset.InstallDir.empty()) {
- return ReadFileResult::INSTALL_PREFIX_UNSUPPORTED;
+ cmCMakePresetErrors::INSTALL_PREFIX_UNSUPPORTED(&root["installDir"],
+ &this->parseState);
+ return false;
}
// Support for conditions added in version 3.
if (v < 3 && preset.ConditionEvaluator) {
- return ReadFileResult::CONDITION_UNSUPPORTED;
+ cmCMakePresetErrors::CONDITION_UNSUPPORTED(&this->parseState);
+ return false;
}
// Support for toolchainFile presets added in version 3.
if (v < 3 && !preset.ToolchainFile.empty()) {
- return ReadFileResult::TOOLCHAIN_FILE_UNSUPPORTED;
+ cmCMakePresetErrors::TOOLCHAIN_FILE_UNSUPPORTED(&this->parseState);
+ return false;
}
this->ConfigurePresetOrder.push_back(preset.Name);
@@ -543,21 +563,22 @@ cmCMakePresetsGraph::ReadFileResult cmCMakePresetsGraph::ReadJSONFile(
for (auto& preset : presets.BuildPresets) {
preset.OriginFile = file;
if (preset.Name.empty()) {
- errMsg += R"(\n\t)";
- errMsg += filename;
- return ReadFileResult::INVALID_PRESET;
+ // No error, already handled by PresetNameHelper
+ return false;
}
PresetPair<BuildPreset> presetPair;
presetPair.Unexpanded = preset;
presetPair.Expanded = cm::nullopt;
if (!this->BuildPresets.emplace(preset.Name, presetPair).second) {
- return ReadFileResult::DUPLICATE_PRESETS;
+ cmCMakePresetErrors::DUPLICATE_PRESETS(preset.Name, &this->parseState);
+ return false;
}
// Support for conditions added in version 3.
if (v < 3 && preset.ConditionEvaluator) {
- return ReadFileResult::CONDITION_UNSUPPORTED;
+ cmCMakePresetErrors::CONDITION_UNSUPPORTED(&this->parseState);
+ return false;
}
this->BuildPresetOrder.push_back(preset.Name);
@@ -566,29 +587,35 @@ cmCMakePresetsGraph::ReadFileResult cmCMakePresetsGraph::ReadJSONFile(
for (auto& preset : presets.TestPresets) {
preset.OriginFile = file;
if (preset.Name.empty()) {
- return ReadFileResult::INVALID_PRESET;
+ // No error, already handled by PresetNameHelper
+ return false;
}
PresetPair<TestPreset> presetPair;
presetPair.Unexpanded = preset;
presetPair.Expanded = cm::nullopt;
if (!this->TestPresets.emplace(preset.Name, presetPair).second) {
- return ReadFileResult::DUPLICATE_PRESETS;
+ cmCMakePresetErrors::DUPLICATE_PRESETS(preset.Name, &this->parseState);
+ return false;
}
// Support for conditions added in version 3.
if (v < 3 && preset.ConditionEvaluator) {
- return ReadFileResult::CONDITION_UNSUPPORTED;
+ cmCMakePresetErrors::CONDITION_UNSUPPORTED(&this->parseState);
+ return false;
}
// Support for TestOutputTruncation added in version 5.
if (v < 5 && preset.Output && preset.Output->TestOutputTruncation) {
- return ReadFileResult::TEST_OUTPUT_TRUNCATION_UNSUPPORTED;
+ cmCMakePresetErrors::TEST_OUTPUT_TRUNCATION_UNSUPPORTED(
+ &this->parseState);
+ return false;
}
// Support for outputJUnitFile added in version 6.
if (v < 6 && preset.Output && !preset.Output->OutputJUnitFile.empty()) {
- return ReadFileResult::CTEST_JUNIT_UNSUPPORTED;
+ cmCMakePresetErrors::CTEST_JUNIT_UNSUPPORTED(&this->parseState);
+ return false;
}
this->TestPresetOrder.push_back(preset.Name);
@@ -597,14 +624,16 @@ cmCMakePresetsGraph::ReadFileResult cmCMakePresetsGraph::ReadJSONFile(
for (auto& preset : presets.PackagePresets) {
preset.OriginFile = file;
if (preset.Name.empty()) {
- return ReadFileResult::INVALID_PRESET;
+ // No error, already handled by PresetNameHelper
+ return false;
}
PresetPair<PackagePreset> presetPair;
presetPair.Unexpanded = preset;
presetPair.Expanded = cm::nullopt;
if (!this->PackagePresets.emplace(preset.Name, presetPair).second) {
- return ReadFileResult::DUPLICATE_PRESETS;
+ cmCMakePresetErrors::DUPLICATE_PRESETS(preset.Name, &this->parseState);
+ return false;
}
// Support for conditions added in version 3, but this requires version 5
@@ -616,14 +645,16 @@ cmCMakePresetsGraph::ReadFileResult cmCMakePresetsGraph::ReadJSONFile(
for (auto& preset : presets.WorkflowPresets) {
preset.OriginFile = file;
if (preset.Name.empty()) {
- return ReadFileResult::INVALID_PRESET;
+ // No error, already handled by PresetNameHelper
+ return false;
}
PresetPair<WorkflowPreset> presetPair;
presetPair.Unexpanded = preset;
presetPair.Expanded = cm::nullopt;
if (!this->WorkflowPresets.emplace(preset.Name, presetPair).second) {
- return ReadFileResult::DUPLICATE_PRESETS;
+ cmCMakePresetErrors::DUPLICATE_PRESETS(preset.Name, &this->parseState);
+ return false;
}
// Support for conditions added in version 3, but this requires version 6
@@ -632,21 +663,21 @@ cmCMakePresetsGraph::ReadFileResult cmCMakePresetsGraph::ReadJSONFile(
this->WorkflowPresetOrder.push_back(preset.Name);
}
- auto const includeFile = [this, &inProgressFiles, file](
- const std::string& include, RootType rootType2,
- ReadReason readReason2,
- std::string& FailureMessage) -> ReadFileResult {
- ReadFileResult r;
+ auto const includeFile = [this, &inProgressFiles,
+ file](const std::string& include,
+ RootType rootType2, ReadReason readReason2,
+ std::string& FailureMessage) -> bool {
+ bool r;
File* includedFile;
- if ((r = this->ReadJSONFile(include, rootType2, readReason2,
- inProgressFiles, includedFile,
- FailureMessage)) != ReadFileResult::READ_OK) {
+ if ((r =
+ this->ReadJSONFile(include, rootType2, readReason2, inProgressFiles,
+ includedFile, FailureMessage)) != true) {
return r;
}
file->ReachableFiles.insert(includedFile->ReachableFiles.begin(),
includedFile->ReachableFiles.end());
- return ReadFileResult::READ_OK;
+ return true;
};
for (auto include : presets.Include) {
@@ -656,7 +687,7 @@ cmCMakePresetsGraph::ReadFileResult cmCMakePresetsGraph::ReadJSONFile(
}
if ((result = includeFile(include, rootType, ReadReason::Included,
- errMsg)) != ReadFileResult::READ_OK) {
+ errMsg)) != true) {
return result;
}
}
@@ -665,13 +696,12 @@ cmCMakePresetsGraph::ReadFileResult cmCMakePresetsGraph::ReadJSONFile(
auto cmakePresetsFilename = GetFilename(this->SourceDir);
if (cmSystemTools::FileExists(cmakePresetsFilename)) {
if ((result = includeFile(cmakePresetsFilename, RootType::Project,
- ReadReason::Root, errMsg)) !=
- ReadFileResult::READ_OK) {
+ ReadReason::Root, errMsg)) != true) {
return result;
}
}
}
inProgressFiles.pop_back();
- return ReadFileResult::READ_OK;
+ return true;
}