Commit c9036ffc authored by Craig Scott's avatar Craig Scott
Browse files

JSON wip

parent 57e4050d
......@@ -855,7 +855,7 @@ void cmake::SetArgs(const std::vector<std::string>& args)
}
for (const auto& path : logSettingDirs) {
if (this->TryLoadLoggerSettings(path + "/.cmake-log-settings")) {
if (this->TryLoadLoggerSettings(path + "/cmake-log-settings.json")) {
break;
}
}
......@@ -924,6 +924,55 @@ cmake::LogLevel cmake::StringToLogLevel(const std::string& levelStr)
return level;
}
bool cmake::ParseLoggerJsonValue(std::vector<std::string>& context,
const Json::Value& jsonValue)
{
if (!jsonValue.isObject()) {
const auto badNode = context.empty()
? "root node"
: cmJoin(cmRange(context.begin(), context.end()), ".");
this->IssueMessage(MessageType::FATAL_ERROR,
"CMake logger settings file: " + badNode +
" is not an object or is an unsupported type");
return false;
}
for (const auto& name : jsonValue.getMemberNames()) {
if (name == "level") {
const auto& level = jsonValue["level"];
if (!level.isString()) {
this->IssueMessage(
MessageType::FATAL_ERROR,
"CMake logger settings file: " +
cmJoin(cmRange(context.begin(), context.end()), ".") +
(context.empty() ? "" : ".") + "level is not a string");
return false;
}
this->IssueMessage(MessageType::MESSAGE, "level = " + level.asString());
const auto logLevel = StringToLogLevel(level.asString());
if (logLevel == LogLevel::UNDEFINED) {
this->IssueMessage(
MessageType::FATAL_ERROR,
"CMake logger settings file: " +
cmJoin(cmRange(context.begin(), context.end()), ".") +
(context.empty() ? "" : ".") +
"level must be one of:\n"
" ERROR, WARNING, NOTICE, STATUS, VERBOSE, DEBUG, TRACE");
return false;
}
this->SetLogLevel(logLevel, context);
} else {
context.push_back(name);
const auto ok = this->ParseLoggerJsonValue(context, jsonValue[name]);
context.pop_back();
if (!ok) {
return false;
}
}
}
return true;
}
// Try to load the logger settings from `.cmake-log-settings` file
bool cmake::TryLoadLoggerSettings(const std::string& settingsFile)
{
......@@ -941,6 +990,24 @@ bool cmake::TryLoadLoggerSettings(const std::string& settingsFile)
return false;
}
#if defined(CMAKE_BUILD_WITH_CMAKE)
Json::Value root;
Json::CharReaderBuilder builder;
std::string errors;
bool parsingOk = Json::parseFromStream(builder, in, &root, &errors);
if (!parsingOk)
{
this->IssueMessage(
MessageType::WARNING,
"Failed to parse the logger settings file: " + errors);
return false;
}
std::vector<std::string> context;
return this->ParseLoggerJsonValue(context, root);
#endif
/*
std::size_t lineNo = 1;
const auto warnIgnoredLine =
......@@ -1004,6 +1071,7 @@ bool cmake::TryLoadLoggerSettings(const std::string& settingsFile)
}
return true;
*/
}
void cmake::SetDirectoriesFromFile(const char* arg)
......
......@@ -551,6 +551,8 @@ private:
};
LogSettingsNode LogSettingsRoot;
bool ParseLoggerJsonValue(std::vector<std::string>& nodes,
const Json::Value& jsonValue);
bool TryLoadLoggerSettings(const std::string& settingsFile);
void UpdateConversionPathTable();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment