Просмотр исходного кода

Merge topic 'cmake-presets-errors-functions'

94241e243d cmJSONHelpers: Make error generators proper functions
2588bf090c CMakePresets: Make error generators proper functions

Acked-by: Kitware Robot <[email protected]>
Tested-by: buildbot <[email protected]>
Merge-request: !8727
Kyle Edwards 2 лет назад
Родитель
Сommit
4653f80260

+ 3 - 1
Source/CMakeLists.txt

@@ -128,7 +128,8 @@ add_library(
   cmCLocaleEnvironmentScope.cxx
   cmCMakePath.h
   cmCMakePath.cxx
-  cmCMakePresetErrors.h
+  cmCMakePresetsErrors.cxx
+  cmCMakePresetsErrors.h
   cmCMakePresetsGraph.cxx
   cmCMakePresetsGraph.h
   cmCMakePresetsGraphInternal.h
@@ -323,6 +324,7 @@ add_library(
   cmInstallTargetGenerator.cxx
   cmInstallDirectoryGenerator.h
   cmInstallDirectoryGenerator.cxx
+  cmJSONHelpers.cxx
   cmJSONHelpers.h
   cmJSONState.cxx
   cmJSONState.h

+ 0 - 245
Source/cmCMakePresetErrors.h

@@ -1,245 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#pragma once
-
-#include "cmConfigure.h" // IWYU pragma: keep
-
-#include <cm3p/json/value.h>
-
-#include "cmJSONHelpers.h"
-#include "cmJSONState.h"
-#include "cmStringAlgorithms.h"
-
-namespace cmCMakePresetErrors {
-const auto getPreset = [](cmJSONState* state) -> const Json::Value* {
-  if (state->parseStack.size() < 2) {
-    return nullptr;
-  }
-  std::string firstKey = state->parseStack[0].first;
-  if (firstKey == "configurePresets" || firstKey == "packagePresets" ||
-      firstKey == "buildPresets" || firstKey == "testPresets") {
-    return state->parseStack[1].second;
-  }
-  return nullptr;
-};
-const auto getPresetName = [](cmJSONState* state) -> std::string {
-#if !defined(CMAKE_BOOTSTRAP)
-  const Json::Value* preset = getPreset(state);
-  if (preset != nullptr && preset->isMember("name")) {
-    return preset->operator[]("name").asString();
-  }
-#endif
-  return "";
-};
-const auto getVariableName = [](cmJSONState* state) -> std::string {
-  std::string var = state->key_after("cacheVariables");
-  std::string errMsg = cmStrCat("variable \"", var, "\"");
-  errMsg = cmStrCat(errMsg, " for preset \"", getPresetName(state), "\"");
-  return errMsg;
-};
-const auto FILE_NOT_FOUND = [](const std::string& filename,
-                               cmJSONState* state) -> void {
-  state->AddError(cmStrCat("File not found: ", filename));
-};
-const auto INVALID_ROOT = [](const Json::Value* value,
-                             cmJSONState* state) -> void {
-  state->AddErrorAtValue("Invalid root object", value);
-};
-const auto NO_VERSION = [](const Json::Value* value,
-                           cmJSONState* state) -> void {
-  state->AddErrorAtValue("No \"version\" field", value);
-};
-const auto INVALID_VERSION = [](const Json::Value* value,
-                                cmJSONState* state) -> void {
-  state->AddErrorAtValue("Invalid \"version\" field", value);
-};
-const auto UNRECOGNIZED_VERSION = [](const Json::Value* value,
-                                     cmJSONState* state) -> void {
-  state->AddErrorAtValue("Unrecognized \"version\" field", value);
-};
-const auto INVALID_PRESETS = [](const Json::Value* value,
-                                cmJSONState* state) -> void {
-  state->AddErrorAtValue("Invalid \"configurePresets\" field", value);
-};
-const auto INVALID_PRESET = [](const Json::Value* value,
-                               cmJSONState* state) -> void {
-  state->AddErrorAtValue("Invalid preset", value);
-};
-const auto INVALID_PRESET_NAMED = [](const std::string& presetName,
-                                     cmJSONState* state) -> void {
-  state->AddError(cmStrCat("Invalid preset: \"", presetName, "\""));
-};
-const auto INVALID_VARIABLE = [](const Json::Value* value,
-                                 cmJSONState* state) -> void {
-  std::string var = cmCMakePresetErrors::getVariableName(state);
-  state->AddErrorAtValue(cmStrCat("Invalid CMake ", var), value);
-};
-const auto DUPLICATE_PRESETS = [](const std::string& presetName,
-                                  cmJSONState* state) -> void {
-  state->AddError(cmStrCat("Duplicate preset: \"", presetName, "\""));
-};
-const auto CYCLIC_PRESET_INHERITANCE = [](const std::string& presetName,
-                                          cmJSONState* state) -> void {
-  state->AddError(
-    cmStrCat("Cyclic preset inheritance for preset \"", presetName, "\""));
-};
-const auto INHERITED_PRESET_UNREACHABLE_FROM_FILE =
-  [](const std::string& presetName, cmJSONState* state) -> void {
-  state->AddError(cmStrCat("Inherited preset \"", presetName,
-                           "\" is unreachable from preset's file"));
-};
-const auto CONFIGURE_PRESET_UNREACHABLE_FROM_FILE =
-  [](const std::string& presetName, cmJSONState* state) -> void {
-  state->AddError(cmStrCat("Configure preset \"", presetName,
-                           "\" is unreachable from preset's file"));
-};
-const auto INVALID_MACRO_EXPANSION = [](const std::string& presetName,
-                                        cmJSONState* state) -> void {
-  state->AddError(cmStrCat("Invalid macro expansion in \"", presetName, "\""));
-};
-const auto BUILD_TEST_PRESETS_UNSUPPORTED = [](const Json::Value*,
-                                               cmJSONState* state) -> void {
-  state->AddError("File version must be 2 or higher for build and test preset "
-                  "support");
-};
-const auto PACKAGE_PRESETS_UNSUPPORTED = [](const Json::Value*,
-                                            cmJSONState* state) -> void {
-  state->AddError(
-    "File version must be 6 or higher for package preset support");
-};
-const auto WORKFLOW_PRESETS_UNSUPPORTED = [](const Json::Value*,
-                                             cmJSONState* state) -> void {
-  state->AddError(
-    "File version must be 6 or higher for workflow preset support");
-};
-const auto INCLUDE_UNSUPPORTED = [](const Json::Value*,
-                                    cmJSONState* state) -> void {
-  state->AddError("File version must be 4 or higher for include support");
-};
-const auto INVALID_INCLUDE = [](const Json::Value* value,
-                                cmJSONState* state) -> void {
-  state->AddErrorAtValue("Invalid \"include\" field", value);
-};
-const auto INVALID_CONFIGURE_PRESET = [](const std::string& presetName,
-                                         cmJSONState* state) -> void {
-  state->AddError(
-    cmStrCat(R"(Invalid "configurePreset": ")", presetName, "\""));
-};
-const auto INSTALL_PREFIX_UNSUPPORTED = [](const Json::Value* value,
-                                           cmJSONState* state) -> void {
-  state->AddErrorAtValue(
-    "File version must be 3 or higher for installDir preset "
-    "support",
-    value);
-};
-const auto CONDITION_UNSUPPORTED = [](cmJSONState* state) -> void {
-  state->AddError("File version must be 3 or higher for condition support");
-};
-const auto TOOLCHAIN_FILE_UNSUPPORTED = [](cmJSONState* state) -> void {
-  state->AddError("File version must be 3 or higher for toolchainFile preset "
-                  "support");
-};
-const auto CYCLIC_INCLUDE = [](const std::string& file,
-                               cmJSONState* state) -> void {
-  state->AddError(cmStrCat("Cyclic include among preset files: ", file));
-};
-const auto TEST_OUTPUT_TRUNCATION_UNSUPPORTED =
-  [](cmJSONState* state) -> void {
-  state->AddError("File version must be 5 or higher for testOutputTruncation "
-                  "preset support");
-};
-const auto INVALID_WORKFLOW_STEPS = [](const std::string& workflowStep,
-                                       cmJSONState* state) -> void {
-  state->AddError(cmStrCat("Invalid workflow step \"", workflowStep, "\""));
-};
-const auto NO_WORKFLOW_STEPS = [](const std::string& presetName,
-                                  cmJSONState* state) -> void {
-  state->AddError(
-    cmStrCat("No workflow steps specified for \"", presetName, "\""));
-};
-const auto FIRST_WORKFLOW_STEP_NOT_CONFIGURE = [](const std::string& stepName,
-                                                  cmJSONState* state) -> void {
-  state->AddError(cmStrCat("First workflow step \"", stepName,
-                           "\" must be a configure step"));
-};
-const auto CONFIGURE_WORKFLOW_STEP_NOT_FIRST = [](const std::string& stepName,
-                                                  cmJSONState* state) -> void {
-  state->AddError(cmStrCat("Configure workflow step \"", stepName,
-                           "\" must be the first step"));
-};
-const auto WORKFLOW_STEP_UNREACHABLE_FROM_FILE =
-  [](const std::string& workflowStep, cmJSONState* state) -> void {
-  state->AddError(cmStrCat("Workflow step \"", workflowStep,
-                           "\" is unreachable from preset's file"));
-};
-const auto CTEST_JUNIT_UNSUPPORTED = [](cmJSONState* state) -> void {
-  state->AddError(
-    "File version must be 6 or higher for CTest JUnit output support");
-};
-const auto TRACE_UNSUPPORTED = [](cmJSONState* state) -> void {
-  state->AddError("File version must be 7 or higher for trace preset support");
-};
-const auto UNRECOGNIZED_CMAKE_VERSION = [](const std::string& version,
-                                           int current, int required) {
-  return [version, current, required](const Json::Value* value,
-                                      cmJSONState* state) -> void {
-    state->AddErrorAtValue(cmStrCat("\"cmakeMinimumRequired\" ", version,
-                                    " version ", required,
-                                    " must be less than ", current),
-                           value);
-  };
-};
-const auto INVALID_PRESET_NAME = [](const Json::Value* value,
-                                    cmJSONState* state) -> void {
-  std::string errMsg = "Invalid Preset Name";
-  if (value && value->isConvertibleTo(Json::ValueType::stringValue) &&
-      !value->asString().empty()) {
-    errMsg = cmStrCat(errMsg, ": ", value->asString());
-  }
-  state->AddErrorAtValue(errMsg, value);
-};
-const auto INVALID_CONDITION = [](const Json::Value* value,
-                                  cmJSONState* state) -> void {
-  state->AddErrorAtValue(
-    cmStrCat("Invalid condition for preset \"", getPresetName(state), "\""),
-    value);
-};
-const auto INVALID_CONDITION_OBJECT =
-  [](JsonErrors::ObjectError errorType,
-     const Json::Value::Members& extraFields) {
-    return JsonErrors::INVALID_NAMED_OBJECT(
-      [](const Json::Value*, cmJSONState* state) -> std::string {
-        return cmStrCat(" condition for preset \"", getPresetName(state),
-                        "\"");
-      })(errorType, extraFields);
-  };
-const auto INVALID_VARIABLE_OBJECT =
-  [](JsonErrors::ObjectError errorType,
-     const Json::Value::Members& extraFields) {
-    return JsonErrors::INVALID_NAMED_OBJECT(
-      [](const Json::Value*, cmJSONState* state) -> std::string {
-        return getVariableName(state);
-      })(errorType, extraFields);
-  };
-const auto INVALID_PRESET_OBJECT =
-  [](JsonErrors::ObjectError errorType,
-     const Json::Value::Members& extraFields) {
-    return JsonErrors::INVALID_NAMED_OBJECT(
-      [](const Json::Value*, cmJSONState*) -> std::string {
-        return "Preset";
-      })(errorType, extraFields);
-  };
-const auto INVALID_ROOT_OBJECT = [](JsonErrors::ObjectError errorType,
-                                    const Json::Value::Members& extraFields) {
-  return JsonErrors::INVALID_NAMED_OBJECT(
-    [](const Json::Value*, cmJSONState*) -> std::string {
-      return "root object";
-    })(errorType, extraFields);
-};
-const auto PRESET_MISSING_FIELD = [](const std::string& presetName,
-                                     const std::string& missingField,
-                                     cmJSONState* state) {
-  state->AddError(cmStrCat("Preset \"", presetName, "\" missing field \"",
-                           missingField, "\""));
-};
-}

+ 305 - 0
Source/cmCMakePresetsErrors.cxx

@@ -0,0 +1,305 @@
+/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+   file Copyright.txt or https://cmake.org/licensing for details.  */
+#include "cmConfigure.h" // IWYU pragma: keep
+
+#include "cmCMakePresetsErrors.h"
+
+#include <functional>
+#include <utility>
+#include <vector>
+
+#include <cm3p/json/value.h>
+
+#include "cmJSONHelpers.h"
+#include "cmJSONState.h"
+#include "cmStringAlgorithms.h"
+
+namespace cmCMakePresetsErrors {
+const Json::Value* getPreset(cmJSONState* state)
+{
+  if (state->parseStack.size() < 2) {
+    return nullptr;
+  }
+  std::string firstKey = state->parseStack[0].first;
+  if (firstKey == "configurePresets" || firstKey == "packagePresets" ||
+      firstKey == "buildPresets" || firstKey == "testPresets") {
+    return state->parseStack[1].second;
+  }
+  return nullptr;
+}
+
+std::string getPresetName(cmJSONState* state)
+{
+  const Json::Value* preset = getPreset(state);
+  if (preset != nullptr && preset->isMember("name")) {
+    return preset->operator[]("name").asString();
+  }
+  return "";
+}
+
+std::string getVariableName(cmJSONState* state)
+{
+  std::string var = state->key_after("cacheVariables");
+  std::string errMsg = cmStrCat("variable \"", var, "\"");
+  errMsg = cmStrCat(errMsg, " for preset \"", getPresetName(state), "\"");
+  return errMsg;
+}
+
+void FILE_NOT_FOUND(const std::string& filename, cmJSONState* state)
+{
+  state->AddError(cmStrCat("File not found: ", filename));
+}
+
+void INVALID_ROOT(const Json::Value* value, cmJSONState* state)
+{
+  state->AddErrorAtValue("Invalid root object", value);
+}
+
+void NO_VERSION(const Json::Value* value, cmJSONState* state)
+{
+  state->AddErrorAtValue("No \"version\" field", value);
+}
+
+void INVALID_VERSION(const Json::Value* value, cmJSONState* state)
+{
+  state->AddErrorAtValue("Invalid \"version\" field", value);
+}
+
+void UNRECOGNIZED_VERSION(const Json::Value* value, cmJSONState* state)
+{
+  state->AddErrorAtValue("Unrecognized \"version\" field", value);
+}
+
+void INVALID_PRESETS(const Json::Value* value, cmJSONState* state)
+{
+  state->AddErrorAtValue("Invalid \"configurePresets\" field", value);
+}
+
+void INVALID_PRESET(const Json::Value* value, cmJSONState* state)
+{
+  state->AddErrorAtValue("Invalid preset", value);
+}
+
+void INVALID_PRESET_NAMED(const std::string& presetName, cmJSONState* state)
+{
+  state->AddError(cmStrCat("Invalid preset: \"", presetName, "\""));
+}
+
+void INVALID_VARIABLE(const Json::Value* value, cmJSONState* state)
+{
+  std::string var = cmCMakePresetsErrors::getVariableName(state);
+  state->AddErrorAtValue(cmStrCat("Invalid CMake ", var), value);
+}
+
+void DUPLICATE_PRESETS(const std::string& presetName, cmJSONState* state)
+{
+  state->AddError(cmStrCat("Duplicate preset: \"", presetName, "\""));
+}
+
+void CYCLIC_PRESET_INHERITANCE(const std::string& presetName,
+                               cmJSONState* state)
+
+{
+  state->AddError(
+    cmStrCat("Cyclic preset inheritance for preset \"", presetName, "\""));
+}
+
+void INHERITED_PRESET_UNREACHABLE_FROM_FILE(const std::string& presetName,
+                                            cmJSONState* state)
+{
+  state->AddError(cmStrCat("Inherited preset \"", presetName,
+                           "\" is unreachable from preset's file"));
+}
+
+void CONFIGURE_PRESET_UNREACHABLE_FROM_FILE(const std::string& presetName,
+                                            cmJSONState* state)
+{
+  state->AddError(cmStrCat("Configure preset \"", presetName,
+                           "\" is unreachable from preset's file"));
+}
+
+void INVALID_MACRO_EXPANSION(const std::string& presetName, cmJSONState* state)
+{
+  state->AddError(cmStrCat("Invalid macro expansion in \"", presetName, "\""));
+}
+
+void BUILD_TEST_PRESETS_UNSUPPORTED(const Json::Value*, cmJSONState* state)
+{
+  state->AddError("File version must be 2 or higher for build and test preset "
+                  "support");
+}
+
+void PACKAGE_PRESETS_UNSUPPORTED(const Json::Value*, cmJSONState* state)
+{
+  state->AddError(
+    "File version must be 6 or higher for package preset support");
+}
+
+void WORKFLOW_PRESETS_UNSUPPORTED(const Json::Value*, cmJSONState* state)
+{
+  state->AddError(
+    "File version must be 6 or higher for workflow preset support");
+}
+
+void INCLUDE_UNSUPPORTED(const Json::Value*, cmJSONState* state)
+{
+  state->AddError("File version must be 4 or higher for include support");
+}
+
+void INVALID_INCLUDE(const Json::Value* value, cmJSONState* state)
+{
+  state->AddErrorAtValue("Invalid \"include\" field", value);
+}
+
+void INVALID_CONFIGURE_PRESET(const std::string& presetName,
+                              cmJSONState* state)
+{
+  state->AddError(
+    cmStrCat(R"(Invalid "configurePreset": ")", presetName, "\""));
+}
+
+void INSTALL_PREFIX_UNSUPPORTED(const Json::Value* value, cmJSONState* state)
+{
+  state->AddErrorAtValue(
+    "File version must be 3 or higher for installDir preset "
+    "support",
+    value);
+}
+
+void CONDITION_UNSUPPORTED(cmJSONState* state)
+{
+  state->AddError("File version must be 3 or higher for condition support");
+}
+
+void TOOLCHAIN_FILE_UNSUPPORTED(cmJSONState* state)
+{
+  state->AddError("File version must be 3 or higher for toolchainFile preset "
+                  "support");
+}
+
+void CYCLIC_INCLUDE(const std::string& file, cmJSONState* state)
+{
+  state->AddError(cmStrCat("Cyclic include among preset files: ", file));
+}
+
+void TEST_OUTPUT_TRUNCATION_UNSUPPORTED(cmJSONState* state)
+{
+  state->AddError("File version must be 5 or higher for testOutputTruncation "
+                  "preset support");
+}
+
+void INVALID_WORKFLOW_STEPS(const std::string& workflowStep,
+                            cmJSONState* state)
+{
+  state->AddError(cmStrCat("Invalid workflow step \"", workflowStep, "\""));
+}
+
+void NO_WORKFLOW_STEPS(const std::string& presetName, cmJSONState* state)
+{
+  state->AddError(
+    cmStrCat("No workflow steps specified for \"", presetName, "\""));
+}
+
+void FIRST_WORKFLOW_STEP_NOT_CONFIGURE(const std::string& stepName,
+                                       cmJSONState* state)
+{
+  state->AddError(cmStrCat("First workflow step \"", stepName,
+                           "\" must be a configure step"));
+}
+
+void CONFIGURE_WORKFLOW_STEP_NOT_FIRST(const std::string& stepName,
+                                       cmJSONState* state)
+{
+  state->AddError(cmStrCat("Configure workflow step \"", stepName,
+                           "\" must be the first step"));
+}
+
+void WORKFLOW_STEP_UNREACHABLE_FROM_FILE(const std::string& workflowStep,
+                                         cmJSONState* state)
+{
+  state->AddError(cmStrCat("Workflow step \"", workflowStep,
+                           "\" is unreachable from preset's file"));
+}
+
+void CTEST_JUNIT_UNSUPPORTED(cmJSONState* state)
+{
+  state->AddError(
+    "File version must be 6 or higher for CTest JUnit output support");
+}
+
+void TRACE_UNSUPPORTED(cmJSONState* state)
+{
+  state->AddError("File version must be 7 or higher for trace preset support");
+}
+
+JsonErrors::ErrorGenerator UNRECOGNIZED_CMAKE_VERSION(
+  const std::string& version, int current, int required)
+{
+  return [version, current, required](const Json::Value* value,
+                                      cmJSONState* state) -> void {
+    state->AddErrorAtValue(cmStrCat("\"cmakeMinimumRequired\" ", version,
+                                    " version ", required,
+                                    " must be less than ", current),
+                           value);
+  };
+}
+
+void INVALID_PRESET_NAME(const Json::Value* value, cmJSONState* state)
+{
+  std::string errMsg = "Invalid Preset Name";
+  if (value && value->isConvertibleTo(Json::ValueType::stringValue) &&
+      !value->asString().empty()) {
+    errMsg = cmStrCat(errMsg, ": ", value->asString());
+  }
+  state->AddErrorAtValue(errMsg, value);
+}
+
+void INVALID_CONDITION(const Json::Value* value, cmJSONState* state)
+{
+  state->AddErrorAtValue(
+    cmStrCat("Invalid condition for preset \"", getPresetName(state), "\""),
+    value);
+}
+
+JsonErrors::ErrorGenerator INVALID_CONDITION_OBJECT(
+  JsonErrors::ObjectError errorType, const Json::Value::Members& extraFields)
+{
+  return JsonErrors::INVALID_NAMED_OBJECT(
+    [](const Json::Value*, cmJSONState* state) -> std::string {
+      return cmStrCat(" condition for preset \"", getPresetName(state), "\"");
+    })(errorType, extraFields);
+}
+
+JsonErrors::ErrorGenerator INVALID_VARIABLE_OBJECT(
+  JsonErrors::ObjectError errorType, const Json::Value::Members& extraFields)
+{
+  return JsonErrors::INVALID_NAMED_OBJECT(
+    [](const Json::Value*, cmJSONState* state) -> std::string {
+      return getVariableName(state);
+    })(errorType, extraFields);
+}
+
+JsonErrors::ErrorGenerator INVALID_PRESET_OBJECT(
+  JsonErrors::ObjectError errorType, const Json::Value::Members& extraFields)
+{
+  return JsonErrors::INVALID_NAMED_OBJECT(
+    [](const Json::Value*, cmJSONState*) -> std::string { return "Preset"; })(
+    errorType, extraFields);
+}
+
+JsonErrors::ErrorGenerator INVALID_ROOT_OBJECT(
+  JsonErrors::ObjectError errorType, const Json::Value::Members& extraFields)
+{
+  return JsonErrors::INVALID_NAMED_OBJECT(
+    [](const Json::Value*, cmJSONState*) -> std::string {
+      return "root object";
+    })(errorType, extraFields);
+}
+
+void PRESET_MISSING_FIELD(const std::string& presetName,
+                          const std::string& missingField, cmJSONState* state)
+{
+  state->AddError(cmStrCat("Preset \"", presetName, "\" missing field \"",
+                           missingField, "\""));
+}
+}

+ 116 - 0
Source/cmCMakePresetsErrors.h

@@ -0,0 +1,116 @@
+/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+   file Copyright.txt or https://cmake.org/licensing for details.  */
+#pragma once
+
+#include "cmConfigure.h" // IWYU pragma: keep
+
+#include <string>
+
+#include <cm3p/json/value.h>
+
+#include "cmJSONHelpers.h"
+
+class cmJSONState;
+
+namespace cmCMakePresetsErrors {
+const Json::Value* getPreset(cmJSONState* state);
+
+std::string getPresetName(cmJSONState* state);
+
+std::string getVariableName(cmJSONState* state);
+
+void FILE_NOT_FOUND(const std::string& filename, cmJSONState* state);
+
+void INVALID_ROOT(const Json::Value* value, cmJSONState* state);
+
+void NO_VERSION(const Json::Value* value, cmJSONState* state);
+
+void INVALID_VERSION(const Json::Value* value, cmJSONState* state);
+
+void UNRECOGNIZED_VERSION(const Json::Value* value, cmJSONState* state);
+
+void INVALID_PRESETS(const Json::Value* value, cmJSONState* state);
+
+void INVALID_PRESET(const Json::Value* value, cmJSONState* state);
+
+void INVALID_PRESET_NAMED(const std::string& presetName, cmJSONState* state);
+
+void INVALID_VARIABLE(const Json::Value* value, cmJSONState* state);
+
+void DUPLICATE_PRESETS(const std::string& presetName, cmJSONState* state);
+
+void CYCLIC_PRESET_INHERITANCE(const std::string& presetName,
+                               cmJSONState* state);
+
+void INHERITED_PRESET_UNREACHABLE_FROM_FILE(const std::string& presetName,
+                                            cmJSONState* state);
+
+void CONFIGURE_PRESET_UNREACHABLE_FROM_FILE(const std::string& presetName,
+                                            cmJSONState* state);
+
+void INVALID_MACRO_EXPANSION(const std::string& presetName,
+                             cmJSONState* state);
+
+void BUILD_TEST_PRESETS_UNSUPPORTED(const Json::Value*, cmJSONState* state);
+
+void PACKAGE_PRESETS_UNSUPPORTED(const Json::Value*, cmJSONState* state);
+
+void WORKFLOW_PRESETS_UNSUPPORTED(const Json::Value*, cmJSONState* state);
+
+void INCLUDE_UNSUPPORTED(const Json::Value*, cmJSONState* state);
+
+void INVALID_INCLUDE(const Json::Value* value, cmJSONState* state);
+
+void INVALID_CONFIGURE_PRESET(const std::string& presetName,
+                              cmJSONState* state);
+
+void INSTALL_PREFIX_UNSUPPORTED(const Json::Value* value, cmJSONState* state);
+
+void CONDITION_UNSUPPORTED(cmJSONState* state);
+
+void TOOLCHAIN_FILE_UNSUPPORTED(cmJSONState* state);
+
+void CYCLIC_INCLUDE(const std::string& file, cmJSONState* state);
+
+void TEST_OUTPUT_TRUNCATION_UNSUPPORTED(cmJSONState* state);
+
+void INVALID_WORKFLOW_STEPS(const std::string& workflowStep,
+                            cmJSONState* state);
+
+void NO_WORKFLOW_STEPS(const std::string& presetName, cmJSONState* state);
+
+void FIRST_WORKFLOW_STEP_NOT_CONFIGURE(const std::string& stepName,
+                                       cmJSONState* state);
+
+void CONFIGURE_WORKFLOW_STEP_NOT_FIRST(const std::string& stepName,
+                                       cmJSONState* state);
+
+void WORKFLOW_STEP_UNREACHABLE_FROM_FILE(const std::string& workflowStep,
+                                         cmJSONState* state);
+
+void CTEST_JUNIT_UNSUPPORTED(cmJSONState* state);
+
+void TRACE_UNSUPPORTED(cmJSONState* state);
+
+JsonErrors::ErrorGenerator UNRECOGNIZED_CMAKE_VERSION(
+  const std::string& version, int current, int required);
+
+void INVALID_PRESET_NAME(const Json::Value* value, cmJSONState* state);
+
+void INVALID_CONDITION(const Json::Value* value, cmJSONState* state);
+
+JsonErrors::ErrorGenerator INVALID_CONDITION_OBJECT(
+  JsonErrors::ObjectError errorType, const Json::Value::Members& extraFields);
+
+JsonErrors::ErrorGenerator INVALID_VARIABLE_OBJECT(
+  JsonErrors::ObjectError errorType, const Json::Value::Members& extraFields);
+
+JsonErrors::ErrorGenerator INVALID_PRESET_OBJECT(
+  JsonErrors::ObjectError errorType, const Json::Value::Members& extraFields);
+
+JsonErrors::ErrorGenerator INVALID_ROOT_OBJECT(
+  JsonErrors::ObjectError errorType, const Json::Value::Members& extraFields);
+
+void PRESET_MISSING_FIELD(const std::string& presetName,
+                          const std::string& missingField, cmJSONState* state);
+}

+ 45 - 45
Source/cmCMakePresetsGraph.cxx

@@ -14,7 +14,7 @@
 
 #include "cmsys/RegularExpression.hxx"
 
-#include "cmCMakePresetErrors.h"
+#include "cmCMakePresetsErrors.h"
 #include "cmCMakePresetsGraphInternal.h"
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
@@ -89,8 +89,8 @@ bool VisitPreset(
 {
   switch (cycleStatus[preset.Name]) {
     case CycleStatus::InProgress:
-      cmCMakePresetErrors::CYCLIC_PRESET_INHERITANCE(preset.Name,
-                                                     &graph.parseState);
+      cmCMakePresetsErrors::CYCLIC_PRESET_INHERITANCE(preset.Name,
+                                                      &graph.parseState);
       return false;
     case CycleStatus::Verified:
       return true;
@@ -101,27 +101,27 @@ bool VisitPreset(
   cycleStatus[preset.Name] = CycleStatus::InProgress;
 
   if (preset.Environment.count("") != 0) {
-    cmCMakePresetErrors::INVALID_PRESET_NAMED(preset.Name, &graph.parseState);
+    cmCMakePresetsErrors::INVALID_PRESET_NAMED(preset.Name, &graph.parseState);
     return false;
   }
 
   bool result = preset.VisitPresetBeforeInherit();
   if (!result) {
-    cmCMakePresetErrors::INVALID_PRESET_NAMED(preset.Name, &graph.parseState);
+    cmCMakePresetsErrors::INVALID_PRESET_NAMED(preset.Name, &graph.parseState);
     return false;
   }
 
   for (auto const& i : preset.Inherits) {
     auto parent = presets.find(i);
     if (parent == presets.end()) {
-      cmCMakePresetErrors::INVALID_PRESET_NAMED(preset.Name,
-                                                &graph.parseState);
+      cmCMakePresetsErrors::INVALID_PRESET_NAMED(preset.Name,
+                                                 &graph.parseState);
       return false;
     }
 
     auto& parentPreset = parent->second.Unexpanded;
     if (!preset.OriginFile->ReachableFiles.count(parentPreset.OriginFile)) {
-      cmCMakePresetErrors::INHERITED_PRESET_UNREACHABLE_FROM_FILE(
+      cmCMakePresetsErrors::INHERITED_PRESET_UNREACHABLE_FROM_FILE(
         preset.Name, &graph.parseState);
       return false;
     }
@@ -132,8 +132,8 @@ bool VisitPreset(
 
     result = preset.VisitPresetInherit(parentPreset);
     if (!result) {
-      cmCMakePresetErrors::INVALID_PRESET_NAMED(preset.Name,
-                                                &graph.parseState);
+      cmCMakePresetsErrors::INVALID_PRESET_NAMED(preset.Name,
+                                                 &graph.parseState);
       return false;
     }
 
@@ -153,7 +153,7 @@ bool VisitPreset(
   result = preset.VisitPresetAfterInherit(graph.GetVersion(preset),
                                           &graph.parseState);
   if (!result) {
-    cmCMakePresetErrors::INVALID_PRESET_NAMED(preset.Name, &graph.parseState);
+    cmCMakePresetsErrors::INVALID_PRESET_NAMED(preset.Name, &graph.parseState);
     return false;
   }
 
@@ -459,8 +459,8 @@ bool ExpandMacros(cmCMakePresetsGraph& graph, const T& preset,
       switch (VisitEnv(*v.second, envCycles[v.first], macroExpanders,
                        graph.GetVersion(preset))) {
         case ExpandMacroResult::Error:
-          cmCMakePresetErrors::INVALID_PRESET_NAMED(preset.Name,
-                                                    &graph.parseState);
+          cmCMakePresetsErrors::INVALID_PRESET_NAMED(preset.Name,
+                                                     &graph.parseState);
           return false;
         case ExpandMacroResult::Ignore:
           out.reset();
@@ -475,8 +475,8 @@ bool ExpandMacros(cmCMakePresetsGraph& graph, const T& preset,
     cm::optional<bool> result;
     if (!preset.ConditionEvaluator->Evaluate(
           macroExpanders, graph.GetVersion(preset), result)) {
-      cmCMakePresetErrors::INVALID_PRESET_NAMED(preset.Name,
-                                                &graph.parseState);
+      cmCMakePresetsErrors::INVALID_PRESET_NAMED(preset.Name,
+                                                 &graph.parseState);
       return false;
     }
     if (!result) {
@@ -615,7 +615,7 @@ bool SetupWorkflowConfigurePreset(const T& preset,
                                   cmJSONState* state)
 {
   if (preset.ConfigurePreset != configurePreset->Name) {
-    cmCMakePresetErrors::INVALID_WORKFLOW_STEPS(configurePreset->Name, state);
+    cmCMakePresetsErrors::INVALID_WORKFLOW_STEPS(configurePreset->Name, state);
     return false;
   }
   return true;
@@ -638,12 +638,12 @@ bool TryReachPresetFromWorkflow(
 {
   auto it = presets.find(name);
   if (it == presets.end()) {
-    cmCMakePresetErrors::INVALID_WORKFLOW_STEPS(name, state);
+    cmCMakePresetsErrors::INVALID_WORKFLOW_STEPS(name, state);
     return false;
   }
   if (!origin.OriginFile->ReachableFiles.count(
         it->second.Unexpanded.OriginFile)) {
-    cmCMakePresetErrors::WORKFLOW_STEP_UNREACHABLE_FROM_FILE(name, state);
+    cmCMakePresetsErrors::WORKFLOW_STEP_UNREACHABLE_FROM_FILE(name, state);
     return false;
   }
   return SetupWorkflowConfigurePreset<T>(it->second.Unexpanded,
@@ -793,13 +793,13 @@ bool cmCMakePresetsGraph::ConfigurePreset::VisitPresetAfterInherit(
   if (!preset.Hidden) {
     if (version < 3) {
       if (preset.Generator.empty()) {
-        cmCMakePresetErrors::PRESET_MISSING_FIELD(preset.Name, "generator",
-                                                  state);
+        cmCMakePresetsErrors::PRESET_MISSING_FIELD(preset.Name, "generator",
+                                                   state);
         return false;
       }
       if (preset.BinaryDir.empty()) {
-        cmCMakePresetErrors::PRESET_MISSING_FIELD(preset.Name, "binaryDir",
-                                                  state);
+        cmCMakePresetsErrors::PRESET_MISSING_FIELD(preset.Name, "binaryDir",
+                                                   state);
         return false;
       }
     }
@@ -1064,7 +1064,7 @@ bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
     if (allowNoFiles) {
       return true;
     }
-    cmCMakePresetErrors::FILE_NOT_FOUND(filename, &this->parseState);
+    cmCMakePresetsErrors::FILE_NOT_FOUND(filename, &this->parseState);
     return false;
   }
 
@@ -1080,8 +1080,8 @@ bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
 
   for (auto& it : this->ConfigurePresets) {
     if (!ExpandMacros(*this, it.second.Unexpanded, it.second.Expanded)) {
-      cmCMakePresetErrors::INVALID_MACRO_EXPANSION(it.first,
-                                                   &this->parseState);
+      cmCMakePresetsErrors::INVALID_MACRO_EXPANSION(it.first,
+                                                    &this->parseState);
       return false;
     }
   }
@@ -1091,13 +1091,13 @@ bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
       const auto configurePreset =
         this->ConfigurePresets.find(it.second.Unexpanded.ConfigurePreset);
       if (configurePreset == this->ConfigurePresets.end()) {
-        cmCMakePresetErrors::INVALID_CONFIGURE_PRESET(it.first,
-                                                      &this->parseState);
+        cmCMakePresetsErrors::INVALID_CONFIGURE_PRESET(it.first,
+                                                       &this->parseState);
         return false;
       }
       if (!it.second.Unexpanded.OriginFile->ReachableFiles.count(
             configurePreset->second.Unexpanded.OriginFile)) {
-        cmCMakePresetErrors::CONFIGURE_PRESET_UNREACHABLE_FROM_FILE(
+        cmCMakePresetsErrors::CONFIGURE_PRESET_UNREACHABLE_FROM_FILE(
           it.first, &this->parseState);
         return false;
       }
@@ -1110,8 +1110,8 @@ bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
     }
 
     if (!ExpandMacros(*this, it.second.Unexpanded, it.second.Expanded)) {
-      cmCMakePresetErrors::INVALID_MACRO_EXPANSION(it.first,
-                                                   &this->parseState);
+      cmCMakePresetsErrors::INVALID_MACRO_EXPANSION(it.first,
+                                                    &this->parseState);
       return false;
     }
   }
@@ -1121,13 +1121,13 @@ bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
       const auto configurePreset =
         this->ConfigurePresets.find(it.second.Unexpanded.ConfigurePreset);
       if (configurePreset == this->ConfigurePresets.end()) {
-        cmCMakePresetErrors::INVALID_CONFIGURE_PRESET(it.first,
-                                                      &this->parseState);
+        cmCMakePresetsErrors::INVALID_CONFIGURE_PRESET(it.first,
+                                                       &this->parseState);
         return false;
       }
       if (!it.second.Unexpanded.OriginFile->ReachableFiles.count(
             configurePreset->second.Unexpanded.OriginFile)) {
-        cmCMakePresetErrors::CONFIGURE_PRESET_UNREACHABLE_FROM_FILE(
+        cmCMakePresetsErrors::CONFIGURE_PRESET_UNREACHABLE_FROM_FILE(
           it.first, &this->parseState);
         return false;
       }
@@ -1140,8 +1140,8 @@ bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
     }
 
     if (!ExpandMacros(*this, it.second.Unexpanded, it.second.Expanded)) {
-      cmCMakePresetErrors::INVALID_MACRO_EXPANSION(it.first,
-                                                   &this->parseState);
+      cmCMakePresetsErrors::INVALID_MACRO_EXPANSION(it.first,
+                                                    &this->parseState);
       return false;
     }
   }
@@ -1151,13 +1151,13 @@ bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
       const auto configurePreset =
         this->ConfigurePresets.find(it.second.Unexpanded.ConfigurePreset);
       if (configurePreset == this->ConfigurePresets.end()) {
-        cmCMakePresetErrors::INVALID_CONFIGURE_PRESET(it.first,
-                                                      &this->parseState);
+        cmCMakePresetsErrors::INVALID_CONFIGURE_PRESET(it.first,
+                                                       &this->parseState);
         return false;
       }
       if (!it.second.Unexpanded.OriginFile->ReachableFiles.count(
             configurePreset->second.Unexpanded.OriginFile)) {
-        cmCMakePresetErrors::CONFIGURE_PRESET_UNREACHABLE_FROM_FILE(
+        cmCMakePresetsErrors::CONFIGURE_PRESET_UNREACHABLE_FROM_FILE(
           it.first, &this->parseState);
         return false;
       }
@@ -1170,8 +1170,8 @@ bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
     }
 
     if (!ExpandMacros(*this, it.second.Unexpanded, it.second.Expanded)) {
-      cmCMakePresetErrors::INVALID_MACRO_EXPANSION(it.first,
-                                                   &this->parseState);
+      cmCMakePresetsErrors::INVALID_MACRO_EXPANSION(it.first,
+                                                    &this->parseState);
       return false;
     }
   }
@@ -1182,12 +1182,12 @@ bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
     const ConfigurePreset* configurePreset = nullptr;
     for (auto const& step : it.second.Unexpanded.Steps) {
       if (configurePreset == nullptr && step.PresetType != Type::Configure) {
-        cmCMakePresetErrors::FIRST_WORKFLOW_STEP_NOT_CONFIGURE(
+        cmCMakePresetsErrors::FIRST_WORKFLOW_STEP_NOT_CONFIGURE(
           step.PresetName, &this->parseState);
         return false;
       }
       if (configurePreset != nullptr && step.PresetType == Type::Configure) {
-        cmCMakePresetErrors::CONFIGURE_WORKFLOW_STEP_NOT_FIRST(
+        cmCMakePresetsErrors::CONFIGURE_WORKFLOW_STEP_NOT_FIRST(
           step.PresetName, &this->parseState);
         return false;
       }
@@ -1220,13 +1220,13 @@ bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
     }
 
     if (configurePreset == nullptr) {
-      cmCMakePresetErrors::NO_WORKFLOW_STEPS(it.first, &this->parseState);
+      cmCMakePresetsErrors::NO_WORKFLOW_STEPS(it.first, &this->parseState);
       return false;
     }
 
     if (!ExpandMacros(*this, it.second.Unexpanded, it.second.Expanded)) {
-      cmCMakePresetErrors::INVALID_MACRO_EXPANSION(it.first,
-                                                   &this->parseState);
+      cmCMakePresetsErrors::INVALID_MACRO_EXPANSION(it.first,
+                                                    &this->parseState);
       return false;
     }
   }

+ 57 - 57
Source/cmCMakePresetsGraphReadJSON.cxx

@@ -15,7 +15,7 @@
 
 #include <cm3p/json/value.h>
 
-#include "cmCMakePresetErrors.h"
+#include "cmCMakePresetsErrors.h"
 #include "cmCMakePresetsGraph.h"
 #include "cmCMakePresetsGraphInternal.h"
 #include "cmJSONHelpers.h"
@@ -71,18 +71,18 @@ auto const ConditionStringHelper = JSONHelperBuilder::String();
 auto const ConditionBoolHelper = JSONHelperBuilder::Bool();
 
 auto const ConditionStringListHelper = JSONHelperBuilder::Vector<std::string>(
-  cmCMakePresetErrors::INVALID_CONDITION, ConditionStringHelper);
+  cmCMakePresetsErrors::INVALID_CONDITION, ConditionStringHelper);
 
 auto const ConstConditionHelper =
   JSONHelperBuilder::Object<cmCMakePresetsGraphInternal::ConstCondition>(
-    cmCMakePresetErrors::INVALID_CONDITION_OBJECT, false)
+    cmCMakePresetsErrors::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>(
-    cmCMakePresetErrors::INVALID_CONDITION_OBJECT, false)
+    cmCMakePresetsErrors::INVALID_CONDITION_OBJECT, false)
     .Bind<std::string>("type"_s, nullptr, ConditionStringHelper, true)
     .Bind("lhs"_s, &cmCMakePresetsGraphInternal::EqualsCondition::Lhs,
           ConditionStringHelper, true)
@@ -91,7 +91,7 @@ auto const EqualsConditionHelper =
 
 auto const InListConditionHelper =
   JSONHelperBuilder::Object<cmCMakePresetsGraphInternal::InListCondition>(
-    cmCMakePresetErrors::INVALID_CONDITION_OBJECT, false)
+    cmCMakePresetsErrors::INVALID_CONDITION_OBJECT, false)
     .Bind<std::string>("type"_s, nullptr, ConditionStringHelper, true)
     .Bind("string"_s, &cmCMakePresetsGraphInternal::InListCondition::String,
           ConditionStringHelper, true)
@@ -100,7 +100,7 @@ auto const InListConditionHelper =
 
 auto const MatchesConditionHelper =
   JSONHelperBuilder::Object<cmCMakePresetsGraphInternal::MatchesCondition>(
-    cmCMakePresetErrors::INVALID_CONDITION_OBJECT, false)
+    cmCMakePresetsErrors::INVALID_CONDITION_OBJECT, false)
     .Bind<std::string>("type"_s, nullptr, ConditionStringHelper, true)
     .Bind("string"_s, &cmCMakePresetsGraphInternal::MatchesCondition::String,
           ConditionStringHelper, true)
@@ -112,10 +112,10 @@ bool SubConditionHelper(std::unique_ptr<cmCMakePresetsGraph::Condition>& out,
 
 auto const ListConditionVectorHelper =
   JSONHelperBuilder::Vector<std::unique_ptr<cmCMakePresetsGraph::Condition>>(
-    cmCMakePresetErrors::INVALID_CONDITION, SubConditionHelper);
+    cmCMakePresetsErrors::INVALID_CONDITION, SubConditionHelper);
 auto const AnyAllOfConditionHelper =
   JSONHelperBuilder::Object<cmCMakePresetsGraphInternal::AnyAllOfCondition>(
-    cmCMakePresetErrors::INVALID_CONDITION_OBJECT, false)
+    cmCMakePresetsErrors::INVALID_CONDITION_OBJECT, false)
     .Bind<std::string>("type"_s, nullptr, ConditionStringHelper, true)
     .Bind("conditions"_s,
           &cmCMakePresetsGraphInternal::AnyAllOfCondition::Conditions,
@@ -123,7 +123,7 @@ auto const AnyAllOfConditionHelper =
 
 auto const NotConditionHelper =
   JSONHelperBuilder::Object<cmCMakePresetsGraphInternal::NotCondition>(
-    cmCMakePresetErrors::INVALID_CONDITION_OBJECT, false)
+    cmCMakePresetsErrors::INVALID_CONDITION_OBJECT, false)
     .Bind<std::string>("type"_s, nullptr, ConditionStringHelper, true)
     .Bind("condition"_s,
           &cmCMakePresetsGraphInternal::NotCondition::SubCondition,
@@ -151,12 +151,12 @@ bool ConditionHelper(std::unique_ptr<cmCMakePresetsGraph::Condition>& out,
 
   if (value->isObject()) {
     if (!value->isMember("type")) {
-      cmCMakePresetErrors::INVALID_CONDITION(value, state);
+      cmCMakePresetsErrors::INVALID_CONDITION(value, state);
       return false;
     }
 
     if (!(*value)["type"].isString()) {
-      cmCMakePresetErrors::INVALID_CONDITION(value, state);
+      cmCMakePresetsErrors::INVALID_CONDITION(value, state);
       return false;
     }
     auto type = (*value)["type"].asString();
@@ -216,7 +216,7 @@ bool ConditionHelper(std::unique_ptr<cmCMakePresetsGraph::Condition>& out,
     }
   }
 
-  cmCMakePresetErrors::INVALID_CONDITION(value, state);
+  cmCMakePresetsErrors::INVALID_CONDITION(value, state);
   return false;
 }
 
@@ -226,7 +226,7 @@ bool SubConditionHelper(std::unique_ptr<cmCMakePresetsGraph::Condition>& out,
   std::unique_ptr<cmCMakePresetsGraph::Condition> ptr;
   auto result = ConditionHelper(ptr, value, state);
   if (ptr && ptr->IsNull()) {
-    cmCMakePresetErrors::INVALID_CONDITION(value, state);
+    cmCMakePresetsErrors::INVALID_CONDITION(value, state);
     return false;
   }
   out = std::move(ptr);
@@ -244,22 +244,22 @@ bool EnvironmentHelper(cm::optional<std::string>& out,
     out = value->asString();
     return true;
   }
-  cmCMakePresetErrors::INVALID_PRESET(value, state);
+  cmCMakePresetsErrors::INVALID_PRESET(value, state);
   return false;
 }
 
 auto const VersionIntHelper =
-  JSONHelperBuilder::Int(cmCMakePresetErrors::INVALID_VERSION);
+  JSONHelperBuilder::Int(cmCMakePresetsErrors::INVALID_VERSION);
 
 auto const VersionHelper = JSONHelperBuilder::Required<int>(
-  cmCMakePresetErrors::NO_VERSION, VersionIntHelper);
+  cmCMakePresetsErrors::NO_VERSION, VersionIntHelper);
 
 auto const RootVersionHelper =
-  JSONHelperBuilder::Object<int>(cmCMakePresetErrors::INVALID_ROOT_OBJECT)
+  JSONHelperBuilder::Object<int>(cmCMakePresetsErrors::INVALID_ROOT_OBJECT)
     .Bind("version"_s, VersionHelper, false);
 
 auto const CMakeVersionUIntHelper =
-  JSONHelperBuilder::UInt(cmCMakePresetErrors::INVALID_VERSION);
+  JSONHelperBuilder::UInt(cmCMakePresetsErrors::INVALID_VERSION);
 
 auto const CMakeVersionHelper =
   JSONHelperBuilder::Object<CMakeVersion>(JsonErrors::INVALID_NAMED_OBJECT_KEY,
@@ -269,14 +269,14 @@ auto const CMakeVersionHelper =
     .Bind("patch"_s, &CMakeVersion::Patch, CMakeVersionUIntHelper, false);
 
 auto const IncludeHelper =
-  JSONHelperBuilder::String(cmCMakePresetErrors::INVALID_INCLUDE);
+  JSONHelperBuilder::String(cmCMakePresetsErrors::INVALID_INCLUDE);
 
 auto const IncludeVectorHelper = JSONHelperBuilder::Vector<std::string>(
-  cmCMakePresetErrors::INVALID_INCLUDE, IncludeHelper);
+  cmCMakePresetsErrors::INVALID_INCLUDE, IncludeHelper);
 
 auto const RootPresetsHelper =
   JSONHelperBuilder::Object<RootPresets>(
-    cmCMakePresetErrors::INVALID_ROOT_OBJECT, false)
+    cmCMakePresetsErrors::INVALID_ROOT_OBJECT, false)
     .Bind<int>("version"_s, nullptr, VersionHelper)
     .Bind("configurePresets"_s, &RootPresets::ConfigurePresets,
           cmCMakePresetsGraphInternal::ConfigurePresetsHelper, false)
@@ -293,7 +293,7 @@ auto const RootPresetsHelper =
     .Bind("include"_s, &RootPresets::Include, IncludeVectorHelper, false)
     .Bind<std::nullptr_t>("vendor"_s, nullptr,
                           cmCMakePresetsGraphInternal::VendorHelper(
-                            cmCMakePresetErrors::INVALID_ROOT),
+                            cmCMakePresetsErrors::INVALID_ROOT),
                           false);
 }
 
@@ -309,7 +309,7 @@ bool PresetNameHelper(std::string& out, const Json::Value* value,
                       cmJSONState* state)
 {
   if (!value || !value->isString() || value->asString().empty()) {
-    cmCMakePresetErrors::INVALID_PRESET_NAME(value, state);
+    cmCMakePresetsErrors::INVALID_PRESET_NAME(value, state);
     return false;
   }
   out = value->asString();
@@ -320,7 +320,7 @@ bool PresetVectorStringHelper(std::vector<std::string>& out,
                               const Json::Value* value, cmJSONState* state)
 {
   static auto const helper = JSONHelperBuilder::Vector<std::string>(
-    cmCMakePresetErrors::INVALID_PRESET,
+    cmCMakePresetsErrors::INVALID_PRESET,
     cmCMakePresetsGraphInternal::PresetStringHelper);
   return helper(out, value, state);
 }
@@ -356,7 +356,7 @@ bool PresetVectorIntHelper(std::vector<int>& out, const Json::Value* value,
                            cmJSONState* state)
 {
   static auto const helper = JSONHelperBuilder::Vector<int>(
-    cmCMakePresetErrors::INVALID_PRESET, PresetIntHelper);
+    cmCMakePresetsErrors::INVALID_PRESET, PresetIntHelper);
   return helper(out, value, state);
 }
 
@@ -409,7 +409,7 @@ bool EnvironmentMapHelper(
   const Json::Value* value, cmJSONState* state)
 {
   static auto const helper = JSONHelperBuilder::Map<cm::optional<std::string>>(
-    cmCMakePresetErrors::INVALID_PRESET, EnvironmentHelper);
+    cmCMakePresetsErrors::INVALID_PRESET, EnvironmentHelper);
 
   return helper(out, value, state);
 }
@@ -429,7 +429,7 @@ bool cmCMakePresetsGraph::ReadJSONFile(const std::string& filename,
       auto fileIt =
         std::find(inProgressFiles.begin(), inProgressFiles.end(), file);
       if (fileIt != inProgressFiles.end()) {
-        cmCMakePresetErrors::CYCLIC_INCLUDE(filename, &this->parseState);
+        cmCMakePresetsErrors::CYCLIC_INCLUDE(filename, &this->parseState);
         return false;
       }
 
@@ -448,43 +448,43 @@ bool cmCMakePresetsGraph::ReadJSONFile(const std::string& filename,
     return result;
   }
   if (v < MIN_VERSION || v > MAX_VERSION) {
-    cmCMakePresetErrors::UNRECOGNIZED_VERSION(&root["version"],
-                                              &this->parseState);
+    cmCMakePresetsErrors::UNRECOGNIZED_VERSION(&root["version"],
+                                               &this->parseState);
     return false;
   }
 
   // Support for build and test presets added in version 2.
   if (v < 2) {
     if (root.isMember("buildPresets")) {
-      cmCMakePresetErrors::BUILD_TEST_PRESETS_UNSUPPORTED(
+      cmCMakePresetsErrors::BUILD_TEST_PRESETS_UNSUPPORTED(
         &root["buildPresets"], &this->parseState);
       return false;
     }
     if (root.isMember("testPresets")) {
-      cmCMakePresetErrors::BUILD_TEST_PRESETS_UNSUPPORTED(&root["testPresets"],
-                                                          &this->parseState);
+      cmCMakePresetsErrors::BUILD_TEST_PRESETS_UNSUPPORTED(
+        &root["testPresets"], &this->parseState);
       return false;
     }
   }
 
   // Support for package presets added in version 6.
   if (v < 6 && root.isMember("packagePresets")) {
-    cmCMakePresetErrors::PACKAGE_PRESETS_UNSUPPORTED(&root["packagePresets"],
-                                                     &this->parseState);
+    cmCMakePresetsErrors::PACKAGE_PRESETS_UNSUPPORTED(&root["packagePresets"],
+                                                      &this->parseState);
     return false;
   }
 
   // Support for workflow presets added in version 6.
   if (v < 6 && root.isMember("workflowPresets")) {
-    cmCMakePresetErrors::WORKFLOW_PRESETS_UNSUPPORTED(&root["workflowPresets"],
-                                                      &this->parseState);
+    cmCMakePresetsErrors::WORKFLOW_PRESETS_UNSUPPORTED(
+      &root["workflowPresets"], &this->parseState);
     return false;
   }
 
   // Support for include added in version 4.
   if (v < 4 && root.isMember("include")) {
-    cmCMakePresetErrors::INCLUDE_UNSUPPORTED(&root["include"],
-                                             &this->parseState);
+    cmCMakePresetsErrors::INCLUDE_UNSUPPORTED(&root["include"],
+                                              &this->parseState);
     return false;
   }
 
@@ -498,20 +498,20 @@ bool cmCMakePresetsGraph::ReadJSONFile(const std::string& filename,
   unsigned int currentPatch = cmVersion::GetPatchVersion();
   auto const& required = presets.CMakeMinimumRequired;
   if (required.Major > currentMajor) {
-    ErrorGenerator error = cmCMakePresetErrors::UNRECOGNIZED_CMAKE_VERSION(
+    ErrorGenerator error = cmCMakePresetsErrors::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(
+      ErrorGenerator error = cmCMakePresetsErrors::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(
+      ErrorGenerator error = cmCMakePresetsErrors::UNRECOGNIZED_CMAKE_VERSION(
         "patch", currentPatch, required.Patch);
       error(&root["cmakeMinimumRequired"]["patch"], &this->parseState);
       return false;
@@ -537,26 +537,26 @@ bool cmCMakePresetsGraph::ReadJSONFile(const std::string& filename,
     presetPair.Unexpanded = preset;
     presetPair.Expanded = cm::nullopt;
     if (!this->ConfigurePresets.emplace(preset.Name, presetPair).second) {
-      cmCMakePresetErrors::DUPLICATE_PRESETS(preset.Name, &this->parseState);
+      cmCMakePresetsErrors::DUPLICATE_PRESETS(preset.Name, &this->parseState);
       return false;
     }
 
     // Support for installDir presets added in version 3.
     if (v < 3 && !preset.InstallDir.empty()) {
-      cmCMakePresetErrors::INSTALL_PREFIX_UNSUPPORTED(&root["installDir"],
-                                                      &this->parseState);
+      cmCMakePresetsErrors::INSTALL_PREFIX_UNSUPPORTED(&root["installDir"],
+                                                       &this->parseState);
       return false;
     }
 
     // Support for conditions added in version 3.
     if (v < 3 && preset.ConditionEvaluator) {
-      cmCMakePresetErrors::CONDITION_UNSUPPORTED(&this->parseState);
+      cmCMakePresetsErrors::CONDITION_UNSUPPORTED(&this->parseState);
       return false;
     }
 
     // Support for toolchainFile presets added in version 3.
     if (v < 3 && !preset.ToolchainFile.empty()) {
-      cmCMakePresetErrors::TOOLCHAIN_FILE_UNSUPPORTED(&this->parseState);
+      cmCMakePresetsErrors::TOOLCHAIN_FILE_UNSUPPORTED(&this->parseState);
       return false;
     }
 
@@ -564,7 +564,7 @@ bool cmCMakePresetsGraph::ReadJSONFile(const std::string& filename,
     if (v < 7 &&
         (preset.TraceMode.has_value() || preset.TraceFormat.has_value() ||
          !preset.TraceRedirect.empty() || !preset.TraceSource.empty())) {
-      cmCMakePresetErrors::TRACE_UNSUPPORTED(&this->parseState);
+      cmCMakePresetsErrors::TRACE_UNSUPPORTED(&this->parseState);
       return false;
     }
 
@@ -582,13 +582,13 @@ bool cmCMakePresetsGraph::ReadJSONFile(const std::string& filename,
     presetPair.Unexpanded = preset;
     presetPair.Expanded = cm::nullopt;
     if (!this->BuildPresets.emplace(preset.Name, presetPair).second) {
-      cmCMakePresetErrors::DUPLICATE_PRESETS(preset.Name, &this->parseState);
+      cmCMakePresetsErrors::DUPLICATE_PRESETS(preset.Name, &this->parseState);
       return false;
     }
 
     // Support for conditions added in version 3.
     if (v < 3 && preset.ConditionEvaluator) {
-      cmCMakePresetErrors::CONDITION_UNSUPPORTED(&this->parseState);
+      cmCMakePresetsErrors::CONDITION_UNSUPPORTED(&this->parseState);
       return false;
     }
 
@@ -606,26 +606,26 @@ bool cmCMakePresetsGraph::ReadJSONFile(const std::string& filename,
     presetPair.Unexpanded = preset;
     presetPair.Expanded = cm::nullopt;
     if (!this->TestPresets.emplace(preset.Name, presetPair).second) {
-      cmCMakePresetErrors::DUPLICATE_PRESETS(preset.Name, &this->parseState);
+      cmCMakePresetsErrors::DUPLICATE_PRESETS(preset.Name, &this->parseState);
       return false;
     }
 
     // Support for conditions added in version 3.
     if (v < 3 && preset.ConditionEvaluator) {
-      cmCMakePresetErrors::CONDITION_UNSUPPORTED(&this->parseState);
+      cmCMakePresetsErrors::CONDITION_UNSUPPORTED(&this->parseState);
       return false;
     }
 
     // Support for TestOutputTruncation added in version 5.
     if (v < 5 && preset.Output && preset.Output->TestOutputTruncation) {
-      cmCMakePresetErrors::TEST_OUTPUT_TRUNCATION_UNSUPPORTED(
+      cmCMakePresetsErrors::TEST_OUTPUT_TRUNCATION_UNSUPPORTED(
         &this->parseState);
       return false;
     }
 
     // Support for outputJUnitFile added in version 6.
     if (v < 6 && preset.Output && !preset.Output->OutputJUnitFile.empty()) {
-      cmCMakePresetErrors::CTEST_JUNIT_UNSUPPORTED(&this->parseState);
+      cmCMakePresetsErrors::CTEST_JUNIT_UNSUPPORTED(&this->parseState);
       return false;
     }
 
@@ -643,7 +643,7 @@ bool cmCMakePresetsGraph::ReadJSONFile(const std::string& filename,
     presetPair.Unexpanded = preset;
     presetPair.Expanded = cm::nullopt;
     if (!this->PackagePresets.emplace(preset.Name, presetPair).second) {
-      cmCMakePresetErrors::DUPLICATE_PRESETS(preset.Name, &this->parseState);
+      cmCMakePresetsErrors::DUPLICATE_PRESETS(preset.Name, &this->parseState);
       return false;
     }
 
@@ -664,7 +664,7 @@ bool cmCMakePresetsGraph::ReadJSONFile(const std::string& filename,
     presetPair.Unexpanded = preset;
     presetPair.Expanded = cm::nullopt;
     if (!this->WorkflowPresets.emplace(preset.Name, presetPair).second) {
-      cmCMakePresetErrors::DUPLICATE_PRESETS(preset.Name, &this->parseState);
+      cmCMakePresetsErrors::DUPLICATE_PRESETS(preset.Name, &this->parseState);
       return false;
     }
 
@@ -718,8 +718,8 @@ bool cmCMakePresetsGraph::ReadJSONFile(const std::string& filename,
     // Support for macro expansion in includes added in version 7
     if (v >= 7) {
       if (ExpandMacros(include, macroExpanders, v) != ExpandMacroResult::Ok) {
-        cmCMakePresetErrors::INVALID_INCLUDE(&root["include"][i],
-                                             &this->parseState);
+        cmCMakePresetsErrors::INVALID_INCLUDE(&root["include"][i],
+                                              &this->parseState);
         return false;
       }
     }

+ 6 - 6
Source/cmCMakePresetsGraphReadJSONBuildPresets.cxx

@@ -13,7 +13,7 @@
 #include <cm3p/json/value.h>
 
 #include "cmBuildOptions.h"
-#include "cmCMakePresetErrors.h"
+#include "cmCMakePresetsErrors.h"
 #include "cmCMakePresetsGraph.h"
 #include "cmCMakePresetsGraphInternal.h"
 #include "cmJSONHelpers.h"
@@ -32,7 +32,7 @@ bool PackageResolveModeHelper(cm::optional<PackageResolveMode>& out,
   }
 
   if (!value->isString()) {
-    cmCMakePresetErrors::INVALID_PRESET(value, state);
+    cmCMakePresetsErrors::INVALID_PRESET(value, state);
     return false;
   }
 
@@ -43,7 +43,7 @@ bool PackageResolveModeHelper(cm::optional<PackageResolveMode>& out,
   } else if (value->asString() == "only") {
     out = PackageResolveMode::OnlyResolve;
   } else {
-    cmCMakePresetErrors::INVALID_PRESET(value, state);
+    cmCMakePresetsErrors::INVALID_PRESET(value, state);
     return false;
   }
 
@@ -59,7 +59,7 @@ std::function<bool(BuildPreset&, const Json::Value*, cmJSONState*)> const
 
 auto const BuildPresetHelper =
   JSONHelperBuilder::Object<BuildPreset>(
-    cmCMakePresetErrors::INVALID_PRESET_OBJECT, false)
+    cmCMakePresetsErrors::INVALID_PRESET_OBJECT, false)
     .Bind("name"_s, &BuildPreset::Name,
           cmCMakePresetsGraphInternal::PresetNameHelper)
     .Bind("inherits"_s, &BuildPreset::Inherits,
@@ -69,7 +69,7 @@ auto const BuildPresetHelper =
           cmCMakePresetsGraphInternal::PresetBoolHelper, false)
     .Bind<std::nullptr_t>("vendor"_s, nullptr,
                           cmCMakePresetsGraphInternal::VendorHelper(
-                            cmCMakePresetErrors::INVALID_PRESET),
+                            cmCMakePresetsErrors::INVALID_PRESET),
                           false)
     .Bind("displayName"_s, &BuildPreset::DisplayName,
           cmCMakePresetsGraphInternal::PresetStringHelper, false)
@@ -105,7 +105,7 @@ bool BuildPresetsHelper(std::vector<BuildPreset>& out,
                         const Json::Value* value, cmJSONState* state)
 {
   static auto const helper = JSONHelperBuilder::Vector<BuildPreset>(
-    cmCMakePresetErrors::INVALID_PRESETS, BuildPresetHelper);
+    cmCMakePresetsErrors::INVALID_PRESETS, BuildPresetHelper);
 
   return helper(out, value, state);
 }

+ 15 - 15
Source/cmCMakePresetsGraphReadJSONConfigurePresets.cxx

@@ -12,7 +12,7 @@
 
 #include <cm3p/json/value.h>
 
-#include "cmCMakePresetErrors.h"
+#include "cmCMakePresetsErrors.h"
 #include "cmCMakePresetsGraph.h"
 #include "cmCMakePresetsGraphInternal.h"
 #include "cmJSONHelpers.h"
@@ -37,7 +37,7 @@ bool ArchToolsetStrategyHelper(cm::optional<ArchToolsetStrategy>& out,
   }
 
   if (!value->isString()) {
-    cmCMakePresetErrors::INVALID_PRESET(value, state);
+    cmCMakePresetsErrors::INVALID_PRESET(value, state);
     return false;
   }
 
@@ -51,7 +51,7 @@ bool ArchToolsetStrategyHelper(cm::optional<ArchToolsetStrategy>& out,
     return true;
   }
 
-  cmCMakePresetErrors::INVALID_PRESET(value, state);
+  cmCMakePresetsErrors::INVALID_PRESET(value, state);
   return false;
 }
 
@@ -85,7 +85,7 @@ ArchToolsetHelper(
       return objectHelper(out, value, state);
     }
 
-    cmCMakePresetErrors::INVALID_PRESET(value, state);
+    cmCMakePresetsErrors::INVALID_PRESET(value, state);
     return false;
   };
 }
@@ -104,7 +104,7 @@ bool TraceEnableModeHelper(cm::optional<TraceEnableMode>& out,
   }
 
   if (!value->isString()) {
-    cmCMakePresetErrors::INVALID_PRESET(value, state);
+    cmCMakePresetsErrors::INVALID_PRESET(value, state);
     return false;
   }
 
@@ -115,7 +115,7 @@ bool TraceEnableModeHelper(cm::optional<TraceEnableMode>& out,
   } else if (value->asString() == "expand") {
     out = TraceEnableMode::Expand;
   } else {
-    cmCMakePresetErrors::INVALID_PRESET(value, state);
+    cmCMakePresetsErrors::INVALID_PRESET(value, state);
     return false;
   }
 
@@ -131,7 +131,7 @@ bool TraceOutputFormatHelper(cm::optional<TraceOutputFormat>& out,
   }
 
   if (!value->isString()) {
-    cmCMakePresetErrors::INVALID_PRESET(value, state);
+    cmCMakePresetsErrors::INVALID_PRESET(value, state);
     return false;
   }
 
@@ -140,7 +140,7 @@ bool TraceOutputFormatHelper(cm::optional<TraceOutputFormat>& out,
   } else if (value->asString() == "json-v1") {
     out = TraceOutputFormat::JSONv1;
   } else {
-    cmCMakePresetErrors::INVALID_PRESET(value, state);
+    cmCMakePresetsErrors::INVALID_PRESET(value, state);
     return false;
   }
 
@@ -167,7 +167,7 @@ bool VariableValueHelper(std::string& out, const Json::Value* value,
 
 auto const VariableObjectHelper =
   JSONHelperBuilder::Object<CacheVariable>(
-    cmCMakePresetErrors::INVALID_VARIABLE_OBJECT, false)
+    cmCMakePresetsErrors::INVALID_VARIABLE_OBJECT, false)
     .Bind("type"_s, &CacheVariable::Type, VariableStringHelper, false)
     .Bind("value"_s, &CacheVariable::Value, VariableValueHelper);
 
@@ -196,13 +196,13 @@ bool VariableHelper(cm::optional<CacheVariable>& out, const Json::Value* value,
     out = cm::nullopt;
     return true;
   }
-  cmCMakePresetErrors::INVALID_VARIABLE(value, state);
+  cmCMakePresetsErrors::INVALID_VARIABLE(value, state);
   return false;
 }
 
 auto const VariablesHelper =
   JSONHelperBuilder::Map<cm::optional<CacheVariable>>(
-    cmCMakePresetErrors::INVALID_PRESET, VariableHelper);
+    cmCMakePresetsErrors::INVALID_PRESET, VariableHelper);
 
 auto const PresetWarningsHelper =
   JSONHelperBuilder::Object<ConfigurePreset>(
@@ -238,7 +238,7 @@ auto const PresetDebugHelper =
 
 auto const PresetTraceHelper =
   JSONHelperBuilder::Object<ConfigurePreset>(
-    cmCMakePresetErrors::INVALID_PRESET_OBJECT, false)
+    cmCMakePresetsErrors::INVALID_PRESET_OBJECT, false)
     .Bind("mode"_s, &ConfigurePreset::TraceMode, TraceEnableModeHelper, false)
     .Bind("format"_s, &ConfigurePreset::TraceFormat, TraceOutputFormatHelper,
           false)
@@ -250,7 +250,7 @@ auto const PresetTraceHelper =
 
 auto const ConfigurePresetHelper =
   JSONHelperBuilder::Object<ConfigurePreset>(
-    cmCMakePresetErrors::INVALID_PRESET_OBJECT, false)
+    cmCMakePresetsErrors::INVALID_PRESET_OBJECT, false)
     .Bind("name"_s, &ConfigurePreset::Name,
           cmCMakePresetsGraphInternal::PresetNameHelper)
     .Bind("inherits"_s, &ConfigurePreset::Inherits,
@@ -260,7 +260,7 @@ auto const ConfigurePresetHelper =
           cmCMakePresetsGraphInternal::PresetBoolHelper, false)
     .Bind<std::nullptr_t>("vendor"_s, nullptr,
                           cmCMakePresetsGraphInternal::VendorHelper(
-                            cmCMakePresetErrors::INVALID_PRESET),
+                            cmCMakePresetsErrors::INVALID_PRESET),
                           false)
     .Bind("displayName"_s, &ConfigurePreset::DisplayName,
           cmCMakePresetsGraphInternal::PresetStringHelper, false)
@@ -295,7 +295,7 @@ bool ConfigurePresetsHelper(std::vector<ConfigurePreset>& out,
                             const Json::Value* value, cmJSONState* state)
 {
   static auto const helper = JSONHelperBuilder::Vector<ConfigurePreset>(
-    cmCMakePresetErrors::INVALID_PRESETS, ConfigurePresetHelper);
+    cmCMakePresetsErrors::INVALID_PRESETS, ConfigurePresetHelper);
 
   return helper(out, value, state);
 }

+ 6 - 6
Source/cmCMakePresetsGraphReadJSONPackagePresets.cxx

@@ -11,7 +11,7 @@
 
 #include <cm3p/json/value.h>
 
-#include "cmCMakePresetErrors.h"
+#include "cmCMakePresetsErrors.h"
 #include "cmCMakePresetsGraph.h"
 #include "cmCMakePresetsGraphInternal.h"
 #include "cmJSONHelpers.h"
@@ -29,14 +29,14 @@ auto const OutputHelper =
           cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false);
 
 auto const VariableHelper =
-  cmJSONHelperBuilder::String(cmCMakePresetErrors::INVALID_VARIABLE);
+  cmJSONHelperBuilder::String(cmCMakePresetsErrors::INVALID_VARIABLE);
 
 auto const VariablesHelper = cmJSONHelperBuilder::Map<std::string>(
-  cmCMakePresetErrors::INVALID_VARIABLE, VariableHelper);
+  cmCMakePresetsErrors::INVALID_VARIABLE, VariableHelper);
 
 auto const PackagePresetHelper =
   cmJSONHelperBuilder::Object<PackagePreset>(
-    cmCMakePresetErrors::INVALID_PRESET_OBJECT, false)
+    cmCMakePresetsErrors::INVALID_PRESET_OBJECT, false)
     .Bind("name"_s, &PackagePreset::Name,
           cmCMakePresetsGraphInternal::PresetNameHelper)
     .Bind("inherits"_s, &PackagePreset::Inherits,
@@ -46,7 +46,7 @@ auto const PackagePresetHelper =
           cmCMakePresetsGraphInternal::PresetBoolHelper, false)
     .Bind<std::nullptr_t>("vendor"_s, nullptr,
                           cmCMakePresetsGraphInternal::VendorHelper(
-                            cmCMakePresetErrors::INVALID_PRESET),
+                            cmCMakePresetsErrors::INVALID_PRESET),
                           false)
     .Bind("displayName"_s, &PackagePreset::DisplayName,
           cmCMakePresetsGraphInternal::PresetStringHelper, false)
@@ -84,7 +84,7 @@ bool PackagePresetsHelper(std::vector<cmCMakePresetsGraph::PackagePreset>& out,
                           const Json::Value* value, cmJSONState* state)
 {
   static auto const helper = cmJSONHelperBuilder::Vector<PackagePreset>(
-    cmCMakePresetErrors::INVALID_PRESETS, PackagePresetHelper);
+    cmCMakePresetsErrors::INVALID_PRESETS, PackagePresetHelper);
 
   return helper(out, value, state);
 }

+ 14 - 14
Source/cmCMakePresetsGraphReadJSONTestPresets.cxx

@@ -11,7 +11,7 @@
 
 #include <cm3p/json/value.h>
 
-#include "cmCMakePresetErrors.h"
+#include "cmCMakePresetsErrors.h"
 #include "cmCMakePresetsGraph.h"
 #include "cmCMakePresetsGraphInternal.h"
 #include "cmJSONHelpers.h"
@@ -34,7 +34,7 @@ bool TestPresetOutputVerbosityHelper(
   }
 
   if (!value->isString()) {
-    cmCMakePresetErrors::INVALID_PRESET(value, state);
+    cmCMakePresetsErrors::INVALID_PRESET(value, state);
     return false;
   }
 
@@ -53,7 +53,7 @@ bool TestPresetOutputVerbosityHelper(
     return true;
   }
 
-  cmCMakePresetErrors::INVALID_PRESET(value, state);
+  cmCMakePresetsErrors::INVALID_PRESET(value, state);
   return false;
 }
 
@@ -71,7 +71,7 @@ bool TestPresetOutputTruncationHelper(
   }
 
   if (!value->isString()) {
-    cmCMakePresetErrors::INVALID_PRESET(value, state);
+    cmCMakePresetsErrors::INVALID_PRESET(value, state);
     return false;
   }
 
@@ -90,7 +90,7 @@ bool TestPresetOutputTruncationHelper(
     return true;
   }
 
-  cmCMakePresetErrors::INVALID_PRESET(value, state);
+  cmCMakePresetsErrors::INVALID_PRESET(value, state);
   return false;
 }
 
@@ -201,7 +201,7 @@ bool TestPresetExecutionShowOnlyHelper(
   cmJSONState* state)
 {
   if (!value || !value->isString()) {
-    cmCMakePresetErrors::INVALID_PRESET(value, state);
+    cmCMakePresetsErrors::INVALID_PRESET(value, state);
     return false;
   }
 
@@ -215,7 +215,7 @@ bool TestPresetExecutionShowOnlyHelper(
     return true;
   }
 
-  cmCMakePresetErrors::INVALID_PRESET(value, state);
+  cmCMakePresetsErrors::INVALID_PRESET(value, state);
   return false;
 }
 
@@ -232,7 +232,7 @@ bool TestPresetExecutionModeHelper(
   }
 
   if (!value->isString()) {
-    cmCMakePresetErrors::INVALID_PRESET(value, state);
+    cmCMakePresetsErrors::INVALID_PRESET(value, state);
     return false;
   }
 
@@ -251,7 +251,7 @@ bool TestPresetExecutionModeHelper(
     return true;
   }
 
-  cmCMakePresetErrors::INVALID_PRESET(value, state);
+  cmCMakePresetsErrors::INVALID_PRESET(value, state);
   return false;
 }
 
@@ -273,7 +273,7 @@ bool TestPresetExecutionNoTestsActionHelper(
   }
 
   if (!value->isString()) {
-    cmCMakePresetErrors::INVALID_PRESET(value, state);
+    cmCMakePresetsErrors::INVALID_PRESET(value, state);
     return false;
   }
 
@@ -292,7 +292,7 @@ bool TestPresetExecutionNoTestsActionHelper(
     return true;
   }
 
-  cmCMakePresetErrors::INVALID_PRESET(value, state);
+  cmCMakePresetsErrors::INVALID_PRESET(value, state);
   return false;
 }
 
@@ -338,7 +338,7 @@ auto const TestPresetFilterHelper =
 
 auto const TestPresetHelper =
   JSONHelperBuilder::Object<TestPreset>(
-    cmCMakePresetErrors::INVALID_PRESET_OBJECT, false)
+    cmCMakePresetsErrors::INVALID_PRESET_OBJECT, false)
     .Bind("name"_s, &TestPreset::Name,
           cmCMakePresetsGraphInternal::PresetNameHelper)
     .Bind("inherits"_s, &TestPreset::Inherits,
@@ -348,7 +348,7 @@ auto const TestPresetHelper =
           cmCMakePresetsGraphInternal::PresetBoolHelper, false)
     .Bind<std::nullptr_t>("vendor"_s, nullptr,
                           cmCMakePresetsGraphInternal::VendorHelper(
-                            cmCMakePresetErrors::INVALID_PRESET),
+                            cmCMakePresetsErrors::INVALID_PRESET),
                           false)
     .Bind("displayName"_s, &TestPreset::DisplayName,
           cmCMakePresetsGraphInternal::PresetStringHelper, false)
@@ -380,7 +380,7 @@ bool TestPresetsHelper(std::vector<cmCMakePresetsGraph::TestPreset>& out,
                        const Json::Value* value, cmJSONState* state)
 {
   static auto const helper = JSONHelperBuilder::Vector<TestPreset>(
-    cmCMakePresetErrors::INVALID_PRESETS, TestPresetHelper);
+    cmCMakePresetsErrors::INVALID_PRESETS, TestPresetHelper);
 
   return helper(out, value, state);
 }

+ 7 - 7
Source/cmCMakePresetsGraphReadJSONWorkflowPresets.cxx

@@ -8,7 +8,7 @@
 
 #include <cm3p/json/value.h>
 
-#include "cmCMakePresetErrors.h"
+#include "cmCMakePresetsErrors.h"
 #include "cmCMakePresetsGraph.h"
 #include "cmCMakePresetsGraphInternal.h"
 #include "cmJSONHelpers.h"
@@ -22,7 +22,7 @@ bool WorkflowStepTypeHelper(WorkflowPreset::WorkflowStep::Type& out,
                             const Json::Value* value, cmJSONState* state)
 {
   if (!value) {
-    cmCMakePresetErrors::INVALID_PRESET(value, state);
+    cmCMakePresetsErrors::INVALID_PRESET(value, state);
     return false;
   }
 
@@ -50,7 +50,7 @@ bool WorkflowStepTypeHelper(WorkflowPreset::WorkflowStep::Type& out,
     return true;
   }
 
-  cmCMakePresetErrors::INVALID_PRESET(value, state);
+  cmCMakePresetsErrors::INVALID_PRESET(value, state);
   return false;
 }
 
@@ -64,16 +64,16 @@ auto const WorkflowStepHelper =
 
 auto const WorkflowStepsHelper =
   cmJSONHelperBuilder::Vector<WorkflowPreset::WorkflowStep>(
-    cmCMakePresetErrors::INVALID_PRESET, WorkflowStepHelper);
+    cmCMakePresetsErrors::INVALID_PRESET, WorkflowStepHelper);
 
 auto const WorkflowPresetHelper =
   cmJSONHelperBuilder::Object<WorkflowPreset>(
-    cmCMakePresetErrors::INVALID_PRESET_OBJECT, false)
+    cmCMakePresetsErrors::INVALID_PRESET_OBJECT, false)
     .Bind("name"_s, &WorkflowPreset::Name,
           cmCMakePresetsGraphInternal::PresetNameHelper)
     .Bind<std::nullptr_t>("vendor"_s, nullptr,
                           cmCMakePresetsGraphInternal::VendorHelper(
-                            cmCMakePresetErrors::INVALID_PRESET),
+                            cmCMakePresetsErrors::INVALID_PRESET),
                           false)
     .Bind("displayName"_s, &WorkflowPreset::DisplayName,
           cmCMakePresetsGraphInternal::PresetStringHelper, false)
@@ -88,7 +88,7 @@ bool WorkflowPresetsHelper(
   const Json::Value* value, cmJSONState* state)
 {
   static auto const helper = cmJSONHelperBuilder::Vector<WorkflowPreset>(
-    cmCMakePresetErrors::INVALID_PRESETS, WorkflowPresetHelper);
+    cmCMakePresetsErrors::INVALID_PRESETS, WorkflowPresetHelper);
 
   return helper(out, value, state);
 }

+ 113 - 0
Source/cmJSONHelpers.cxx

@@ -0,0 +1,113 @@
+/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+   file Copyright.txt or https://cmake.org/licensing for details.  */
+#include "cmConfigure.h" // IWYU pragma: keep
+
+#include "cmJSONHelpers.h"
+
+#include <functional>
+#include <string>
+#include <vector>
+
+#include <cm3p/json/value.h>
+
+#include "cmJSONState.h"
+
+namespace JsonErrors {
+ErrorGenerator EXPECTED_TYPE(const std::string& type)
+{
+  return [type](const Json::Value* value, cmJSONState* state) -> void {
+    if (state->key().empty()) {
+      state->AddErrorAtValue(cmStrCat("Expected ", type), value);
+      return;
+    }
+    std::string errMsg = cmStrCat("\"", state->key(), "\" expected ", type);
+    if (value && value->isConvertibleTo(Json::ValueType::stringValue)) {
+      errMsg = cmStrCat(errMsg, ", got: ", value->asString());
+    }
+    state->AddErrorAtValue(errMsg, value);
+  };
+}
+
+void INVALID_STRING(const Json::Value* value, cmJSONState* state)
+{
+  JsonErrors::EXPECTED_TYPE("a string")(value, state);
+}
+
+void INVALID_BOOL(const Json::Value* value, cmJSONState* state)
+{
+  JsonErrors::EXPECTED_TYPE("a bool")(value, state);
+}
+
+void INVALID_INT(const Json::Value* value, cmJSONState* state)
+{
+  JsonErrors::EXPECTED_TYPE("an integer")(value, state);
+}
+
+void INVALID_UINT(const Json::Value* value, cmJSONState* state)
+{
+  JsonErrors::EXPECTED_TYPE("an unsigned integer")(value, state);
+}
+
+ObjectErrorGenerator INVALID_NAMED_OBJECT(
+  const std::function<std::string(const Json::Value*, cmJSONState*)>&
+    nameGenerator)
+{
+  return [nameGenerator](
+           ObjectError errorType,
+           const Json::Value::Members& extraFields) -> ErrorGenerator {
+    return [nameGenerator, errorType, extraFields](
+             const Json::Value* value, cmJSONState* state) -> void {
+      std::string name = nameGenerator(value, state);
+      switch (errorType) {
+        case ObjectError::RequiredMissing:
+          state->AddErrorAtValue(cmStrCat("Invalid Required ", name), value);
+          break;
+        case ObjectError::InvalidObject:
+          state->AddErrorAtValue(cmStrCat("Invalid ", name), value);
+          break;
+        case ObjectError::ExtraField: {
+          for (auto const& member : extraFields) {
+            if (value) {
+              state->AddErrorAtValue(
+                cmStrCat("Invalid extra field \"", member, "\" in ", name),
+                &(*value)[member]);
+            } else {
+              state->AddError(
+                cmStrCat("Invalid extra field \"", member, "\" in ", name));
+            }
+          }
+        } break;
+        case ObjectError::MissingRequired:
+          state->AddErrorAtValue(cmStrCat("Missing required field \"",
+                                          state->key(), "\" in ", name),
+                                 value);
+          break;
+      }
+    };
+  };
+}
+
+ErrorGenerator INVALID_OBJECT(ObjectError errorType,
+                              const Json::Value::Members& extraFields)
+{
+  return INVALID_NAMED_OBJECT(
+    [](const Json::Value*, cmJSONState*) -> std::string { return "Object"; })(
+    errorType, extraFields);
+}
+
+ErrorGenerator INVALID_NAMED_OBJECT_KEY(
+  ObjectError errorType, const Json::Value::Members& extraFields)
+{
+  return INVALID_NAMED_OBJECT(
+    [](const Json::Value*, cmJSONState* state) -> std::string {
+      for (auto it = state->parseStack.rbegin();
+           it != state->parseStack.rend(); ++it) {
+        if (it->first.rfind("$vector_item_", 0) == 0) {
+          continue;
+        }
+        return cmStrCat("\"", it->first, "\"");
+      }
+      return "root";
+    })(errorType, extraFields);
+}
+}

+ 21 - 89
Source/cmJSONHelpers.h

@@ -5,11 +5,11 @@
 #include "cmConfigure.h" // IWYU pragma: keep
 
 #include <algorithm>
-#include <cstddef>
 #include <functional>
 #include <iostream>
 #include <map>
 #include <string>
+#include <utility>
 #include <vector>
 
 #include <cm/optional>
@@ -18,6 +18,7 @@
 #include <cm3p/json/value.h>
 
 #include "cmJSONState.h"
+#include "cmStringAlgorithms.h"
 
 template <typename T>
 using cmJSONHelper =
@@ -36,94 +37,25 @@ enum ObjectError
 using ErrorGenerator = std::function<void(const Json::Value*, cmJSONState*)>;
 using ObjectErrorGenerator =
   std::function<ErrorGenerator(ObjectError, const Json::Value::Members&)>;
-const auto EXPECTED_TYPE = [](const std::string& type) {
-  return [type](const Json::Value* value, cmJSONState* state) -> void {
-    if (state->key().empty()) {
-      state->AddErrorAtValue(cmStrCat("Expected ", type), value);
-      return;
-    }
-    std::string errMsg = cmStrCat("\"", state->key(), "\" expected ", type);
-    if (value && value->isConvertibleTo(Json::ValueType::stringValue)) {
-      errMsg = cmStrCat(errMsg, ", got: ", value->asString());
-    }
-    state->AddErrorAtValue(errMsg, value);
-  };
-};
-const auto INVALID_STRING = [](const Json::Value* value,
-                               cmJSONState* state) -> void {
-  JsonErrors::EXPECTED_TYPE("a string")(value, state);
-};
-const auto INVALID_BOOL = [](const Json::Value* value,
-                             cmJSONState* state) -> void {
-  JsonErrors::EXPECTED_TYPE("a bool")(value, state);
-};
-const auto INVALID_INT = [](const Json::Value* value,
-                            cmJSONState* state) -> void {
-  JsonErrors::EXPECTED_TYPE("an integer")(value, state);
-};
-const auto INVALID_UINT = [](const Json::Value* value,
-                             cmJSONState* state) -> void {
-  JsonErrors::EXPECTED_TYPE("an unsigned integer")(value, state);
-};
-const auto INVALID_NAMED_OBJECT =
-  [](const std::function<std::string(const Json::Value*, cmJSONState*)>&
-       nameGenerator) -> ObjectErrorGenerator {
-  return [nameGenerator](
-           ObjectError errorType,
-           const Json::Value::Members& extraFields) -> ErrorGenerator {
-    return [nameGenerator, errorType, extraFields](
-             const Json::Value* value, cmJSONState* state) -> void {
-      std::string name = nameGenerator(value, state);
-      switch (errorType) {
-        case ObjectError::RequiredMissing:
-          state->AddErrorAtValue(cmStrCat("Invalid Required ", name), value);
-          break;
-        case ObjectError::InvalidObject:
-          state->AddErrorAtValue(cmStrCat("Invalid ", name), value);
-          break;
-        case ObjectError::ExtraField: {
-          for (auto const& member : extraFields) {
-            if (value) {
-              state->AddErrorAtValue(
-                cmStrCat("Invalid extra field \"", member, "\" in ", name),
-                &(*value)[member]);
-            } else {
-              state->AddError(
-                cmStrCat("Invalid extra field \"", member, "\" in ", name));
-            }
-          }
-        } break;
-        case ObjectError::MissingRequired:
-          state->AddErrorAtValue(cmStrCat("Missing required field \"",
-                                          state->key(), "\" in ", name),
-                                 value);
-          break;
-      }
-    };
-  };
-};
-const auto INVALID_OBJECT =
-  [](ObjectError errorType,
-     const Json::Value::Members& extraFields) -> ErrorGenerator {
-  return INVALID_NAMED_OBJECT(
-    [](const Json::Value*, cmJSONState*) -> std::string { return "Object"; })(
-    errorType, extraFields);
-};
-const auto INVALID_NAMED_OBJECT_KEY =
-  [](ObjectError errorType,
-     const Json::Value::Members& extraFields) -> ErrorGenerator {
-  return INVALID_NAMED_OBJECT(
-    [](const Json::Value*, cmJSONState* state) -> std::string {
-      for (auto it = state->parseStack.rbegin();
-           it != state->parseStack.rend(); ++it) {
-        if (it->first.rfind("$vector_item_", 0) == 0) {
-          continue;
-        }
-        return cmStrCat("\"", it->first, "\"");
-      }
-      return "root";
-    })(errorType, extraFields);
-};
+ErrorGenerator EXPECTED_TYPE(const std::string& type);
+
+void INVALID_STRING(const Json::Value* value, cmJSONState* state);
+
+void INVALID_BOOL(const Json::Value* value, cmJSONState* state);
+
+void INVALID_INT(const Json::Value* value, cmJSONState* state);
+
+void INVALID_UINT(const Json::Value* value, cmJSONState* state);
+
+ObjectErrorGenerator INVALID_NAMED_OBJECT(
+  const std::function<std::string(const Json::Value*, cmJSONState*)>&
+    nameGenerator);
+
+ErrorGenerator INVALID_OBJECT(ObjectError errorType,
+                              const Json::Value::Members& extraFields);
+
+ErrorGenerator INVALID_NAMED_OBJECT_KEY(
+  ObjectError errorType, const Json::Value::Members& extraFields);
 }
 
 struct cmJSONHelperBuilder

+ 1 - 0
bootstrap

@@ -414,6 +414,7 @@ CMAKE_CXX_SOURCES="\
   cmInstallTargetGenerator \
   cmInstallTargetsCommand \
   cmInstalledFile \
+  cmJSONHelpers \
   cmJSONState \
   cmLDConfigLDConfigTool \
   cmLDConfigTool \