From 8dd00674bd5b0eb3fa0d3261bf2d0273e7d41744 Mon Sep 17 00:00:00 2001 From: Tyler Yankee Date: Fri, 6 Feb 2026 13:31:05 -0500 Subject: [PATCH] cmInstrumentationCommand: Use cmJSONState to read content args This approach will be more portable. --- Source/cmInstrumentationCommand.cxx | 10 +++++----- ...ke-command-custom-content-bad-content-stderr.txt | 13 +++++++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Source/cmInstrumentationCommand.cxx b/Source/cmInstrumentationCommand.cxx index 819c80fff1..48715cec9f 100644 --- a/Source/cmInstrumentationCommand.cxx +++ b/Source/cmInstrumentationCommand.cxx @@ -10,7 +10,6 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include -#include #include #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 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 { diff --git a/Tests/RunCMake/Instrumentation/cmake-command-custom-content-bad-content-stderr.txt b/Tests/RunCMake/Instrumentation/cmake-command-custom-content-bad-content-stderr.txt index f9c7205be8..3f56d7beae 100644 --- a/Tests/RunCMake/Instrumentation/cmake-command-custom-content-bad-content-stderr.txt +++ b/Tests/RunCMake/Instrumentation/cmake-command-custom-content-bad-content-stderr.txt @@ -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\)