MCPcopy Index your code
hub / github.com/Kitware/CMake / HandleJSONCommand

Function HandleJSONCommand

Source/cmStringCommand.cxx:933–1094  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

931#endif
932
933bool HandleJSONCommand(std::vector<std::string> const& arguments,
934 cmExecutionStatus& status)
935{
936#if !defined(CMAKE_BOOTSTRAP)
937
938 auto& makefile = status.GetMakefile();
939 Args args{ arguments.begin() + 1, arguments.end() };
940
941 std::string const* errorVariable = nullptr;
942 std::string const* outputVariable = nullptr;
943 bool success = true;
944
945 try {
946 outputVariable = &args.PopFront("missing out-var argument"_s);
947
948 if (!args.empty() && *args.begin() == "ERROR_VARIABLE"_s) {
949 args.PopFront("");
950 errorVariable = &args.PopFront("missing error-var argument"_s);
951 makefile.AddDefinition(*errorVariable, "NOTFOUND"_s);
952 }
953
954 auto const& mode = args.PopFront("missing mode argument"_s);
955 if (mode != "GET"_s && mode != "GET_RAW"_s && mode != "TYPE"_s &&
956 mode != "MEMBER"_s && mode != "LENGTH"_s && mode != "REMOVE"_s &&
957 mode != "SET"_s && mode != "EQUAL"_s && mode != "STRING_ENCODE"_s) {
958 throw json_error(cmStrCat(
959 "got an invalid mode '"_s, mode,
960 "', expected one of GET, GET_RAW, TYPE, MEMBER, LENGTH, REMOVE, SET, "
961 " EQUAL, STRING_ENCODE"_s));
962 }
963
964 auto const& jsonstr = args.PopFront("missing json string argument"_s);
965
966 if (mode == "STRING_ENCODE"_s) {
967 Json::Value json(jsonstr);
968 makefile.AddDefinition(*outputVariable, WriteJson(json));
969 } else {
970 Json::Value json = ReadJson(jsonstr);
971
972 if (mode == "GET"_s) {
973 auto const& value = ResolvePath(json, args);
974 if (value.isObject() || value.isArray()) {
975 makefile.AddDefinition(*outputVariable, WriteJson(value));
976 } else if (value.isBool()) {
977 makefile.AddDefinitionBool(*outputVariable, value.asBool());
978 } else {
979 makefile.AddDefinition(*outputVariable, value.asString());
980 }
981
982 } else if (mode == "GET_RAW"_s) {
983 auto const& value = ResolvePath(json, args);
984 makefile.AddDefinition(*outputVariable, WriteJson(value));
985
986 } else if (mode == "TYPE"_s) {
987 auto const& value = ResolvePath(json, args);
988 makefile.AddDefinition(*outputVariable,
989 JsonTypeToString(value.type()));
990

Callers

nothing calls this directly

Calls 15

json_errorClass · 0.85
WriteJsonFunction · 0.85
JsonTypeToStringFunction · 0.85
ParseIndexFunction · 0.85
isObjectMethod · 0.80
isArrayMethod · 0.80
isBoolMethod · 0.80
AddDefinitionBoolMethod · 0.80
asBoolMethod · 0.80
asStringMethod · 0.80
ViewMethod · 0.80
removeIndexMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…