From e2da85c6724b6e77972e4b39814ad06fa89a94ca Mon Sep 17 00:00:00 2001 From: Tyler Yankee Date: Wed, 12 Aug 2026 13:45:56 -0400 Subject: [PATCH] VS: Use cmJSONState to read flag table This approach will be more portable. --- Source/cmGlobalVisualStudio10Generator.cxx | 56 ++++++++++------------ 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index 05069a40dc..c2df38bdd7 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -11,7 +11,6 @@ #include #include -#include #include #include "cmsys/FStream.hxx" @@ -24,6 +23,7 @@ #include "cmGlobalVisualStudio7Generator.h" #include "cmGlobalVisualStudioGenerator.h" #include "cmIDEFlagTable.h" +#include "cmJSONState.h" #include "cmLocalGenerator.h" #include "cmLocalVisualStudio10Generator.h" #include "cmMakefile.h" @@ -1379,39 +1379,35 @@ cmIDEFlagTable const* cmLoadFlagTableJson(std::string const& flagJsonPath, if (savedFlagIterator != loadedFlagJsonFiles.end()) { ret = savedFlagIterator->second.data(); } else { - Json::Reader reader; - cmsys::ifstream stream; - - stream.open(flagJsonPath.c_str(), std::ios_base::in); - if (stream) { - Json::Value flags; - if (reader.parse(stream, flags, false) && flags.isArray()) { - std::vector flagTable; - for (auto const& flag : flags) { - Json::Value const& vsminJson = flag["vsmin"]; - if (vsminJson.isString()) { - std::string const& vsmin = vsminJson.asString(); - if (!vsmin.empty()) { - if (!vsVer || - cmSystemTools::VersionCompareGreater(vsmin, *vsVer)) { - continue; - } + Json::Value flags; + cmJSONState parseState(flagJsonPath, &flags, + cmJSONState::StrictMode::Relaxed); + if (parseState.errors.empty() && flags.isArray()) { + std::vector flagTable; + for (auto const& flag : flags) { + Json::Value const& vsminJson = flag["vsmin"]; + if (vsminJson.isString()) { + std::string const& vsmin = vsminJson.asString(); + if (!vsmin.empty()) { + if (!vsVer || + cmSystemTools::VersionCompareGreater(vsmin, *vsVer)) { + continue; } } - cmIDEFlagTable flagEntry; - flagEntry.IDEName = cmLoadFlagTableString(flag, "name"); - flagEntry.commandFlag = cmLoadFlagTableString(flag, "switch"); - flagEntry.comment = cmLoadFlagTableString(flag, "comment"); - flagEntry.value = cmLoadFlagTableString(flag, "value"); - flagEntry.special = cmLoadFlagTableSpecial(flag, "flags"); - flagTable.push_back(flagEntry); } - cmIDEFlagTable endFlag{ "", "", "", "", 0 }; - flagTable.push_back(endFlag); - - loadedFlagJsonFiles[flagJsonPath] = flagTable; - ret = loadedFlagJsonFiles[flagJsonPath].data(); + cmIDEFlagTable flagEntry; + flagEntry.IDEName = cmLoadFlagTableString(flag, "name"); + flagEntry.commandFlag = cmLoadFlagTableString(flag, "switch"); + flagEntry.comment = cmLoadFlagTableString(flag, "comment"); + flagEntry.value = cmLoadFlagTableString(flag, "value"); + flagEntry.special = cmLoadFlagTableSpecial(flag, "flags"); + flagTable.push_back(flagEntry); } + cmIDEFlagTable endFlag{ "", "", "", "", 0 }; + flagTable.push_back(endFlag); + + loadedFlagJsonFiles[flagJsonPath] = flagTable; + ret = loadedFlagJsonFiles[flagJsonPath].data(); } } return ret;