cmInstrumentationCommand: Use cmJSONState to read content args

This approach will be more portable.
This commit is contained in:
Tyler Yankee
2026-07-30 13:52:58 -04:00
parent 76e4137229
commit 8dd00674bd
2 changed files with 16 additions and 7 deletions
+5 -5
View File
@@ -10,7 +10,6 @@ file LICENSE.rst or https://cmake.org/licensing for details. */
#include <cmext/string_view>
#include <cm3p/json/reader.h>
#include <cm3p/json/value.h>
#include "cmsys/String.h"
@@ -20,6 +19,7 @@ file LICENSE.rst or https://cmake.org/licensing for details. */
#include "cmExecutionStatus.h"
#include "cmInstrumentation.h"
#include "cmInstrumentationQuery.h"
#include "cmJSONState.h"
#include "cmList.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
@@ -206,11 +206,11 @@ bool cmInstrumentationCommand(std::vector<std::string> const& args,
value.append(item);
}
} else if (type == "JSON") {
Json::CharReaderBuilder builder;
std::istringstream iss(contentString);
if (!Json::parseFromStream(builder, iss, &value, nullptr)) {
status.SetError(
cmStrCat("failed to parse custom content as JSON: ", contentString));
cmJSONState parseState(iss, &value, cmJSONState::StrictMode::Relaxed);
if (!parseState.errors.empty()) {
status.SetError(cmStrCat("failed to parse custom content as JSON:\n ",
parseState.GetErrorMessage()));
return false;
}
} else {
@@ -1,6 +1,15 @@
CMake Error at [^
]*:1 \(cmake_instrumentation\):
cmake_instrumentation failed to parse custom content as JSON: Not valid
JSON content
cmake_instrumentation failed to parse custom content as JSON:
(
Syntax error: value, object or array expected\.
Not valid JSON content
\^|
JSON Parse Error:
\* Line 1, Column 1
Syntax error: value, object or array expected\.
)
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)