2021-12-31 17:05:31 +00:00
|
|
|
#include "ProjectConfig.hpp"
|
2021-10-02 17:39:27 +01:00
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
#include "src/Helpers/String.hpp"
|
2021-04-06 02:10:14 +01:00
|
|
|
#include "src/Logger/Logger.hpp"
|
|
|
|
|
#include "src/Exceptions/InvalidConfig.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
namespace Bloom
|
|
|
|
|
{
|
2022-07-23 15:37:22 +01:00
|
|
|
ProjectConfig::ProjectConfig(const YAML::Node& configNode) {
|
|
|
|
|
if (!configNode["environments"]) {
|
2022-02-05 15:32:08 +00:00
|
|
|
throw Exceptions::InvalidConfig(
|
2022-07-23 15:37:22 +01:00
|
|
|
"No environments found - please review the bloom.yaml configuration file and ensure that "
|
2022-02-05 15:32:08 +00:00
|
|
|
"no syntax errors are present."
|
2021-04-04 21:04:12 +01:00
|
|
|
);
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-12-31 19:44:20 +00:00
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
if (!configNode["environments"].IsMap()) {
|
|
|
|
|
throw Exceptions::InvalidConfig(
|
|
|
|
|
"Invalid environments configuration provided - 'environments' must be of mapping type."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto& environments = configNode["environments"];
|
|
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
for (auto environmentIt = environments.begin(); environmentIt != environments.end(); environmentIt++) {
|
2022-07-23 15:37:22 +01:00
|
|
|
auto environmentName = std::optional<std::string>(std::nullopt);
|
2022-02-05 15:32:08 +00:00
|
|
|
|
|
|
|
|
try {
|
2022-07-23 15:37:22 +01:00
|
|
|
environmentName = environmentIt->first.as<std::string>();
|
|
|
|
|
|
|
|
|
|
if (!String::isAscii(environmentName.value())) {
|
|
|
|
|
throw Exceptions::InvalidConfig(
|
|
|
|
|
"Environment name ('" + environmentName.value() + "') is not in ASCII form."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
this->environments.insert(
|
|
|
|
|
std::pair(
|
2022-07-23 15:37:22 +01:00
|
|
|
environmentName.value(),
|
|
|
|
|
EnvironmentConfig(environmentName.value(), environmentIt->second)
|
2022-02-05 15:32:08 +00:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
} catch (Exceptions::InvalidConfig& exception) {
|
2022-07-23 15:37:22 +01:00
|
|
|
Logger::error(
|
|
|
|
|
"Invalid environment config for environment '" + environmentName.value() + "': "
|
|
|
|
|
+ exception.getMessage() + " Environment will be ignored."
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
} catch (YAML::BadConversion& exception) {
|
|
|
|
|
Logger::error(
|
|
|
|
|
"Invalid environment name provided. Environment names must be ASCII strings. Environment will be "
|
|
|
|
|
"ignored"
|
|
|
|
|
);
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
if (configNode["debugServer"]) {
|
|
|
|
|
this->debugServerConfig = DebugServerConfig(configNode["debugServer"]);
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
if (configNode["insight"]) {
|
|
|
|
|
this->insightConfig = InsightConfig(configNode["insight"]);
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
if (configNode["debugLoggingEnabled"]) {
|
|
|
|
|
this->debugLoggingEnabled = configNode["debugLoggingEnabled"].as<bool>(this->debugLoggingEnabled);
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
InsightConfig::InsightConfig(const YAML::Node& insightNode) {
|
|
|
|
|
if (insightNode["enabled"]) {
|
|
|
|
|
this->insightEnabled = insightNode["enabled"].as<bool>(this->insightEnabled);
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
EnvironmentConfig::EnvironmentConfig(std::string name, const YAML::Node& environmentNode)
|
|
|
|
|
: name(std::move(name))
|
|
|
|
|
{
|
|
|
|
|
if (!environmentNode["debugTool"]) {
|
|
|
|
|
throw Exceptions::InvalidConfig("Missing debug tool configuration.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!environmentNode["debugTool"].IsMap()) {
|
|
|
|
|
throw Exceptions::InvalidConfig(
|
|
|
|
|
"Invalid debug tool configuration provided - 'debugTool' must be of mapping type."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!environmentNode["target"]) {
|
|
|
|
|
throw Exceptions::InvalidConfig("Missing target configuration.");
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
if (!environmentNode["target"].IsMap()) {
|
|
|
|
|
throw Exceptions::InvalidConfig(
|
|
|
|
|
"Invalid target configuration provided - 'target' must be of mapping type."
|
|
|
|
|
);
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
this->debugToolConfig = DebugToolConfig(environmentNode["debugTool"]);
|
|
|
|
|
this->targetConfig = TargetConfig(environmentNode["target"]);
|
|
|
|
|
|
|
|
|
|
if (environmentNode["debugServer"]) {
|
|
|
|
|
if (!environmentNode["debugServer"].IsMap()) {
|
|
|
|
|
throw Exceptions::InvalidConfig(
|
|
|
|
|
"Invalid debug server configuration provided - 'debugServer' must be of mapping type."
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
this->debugServerConfig = DebugServerConfig(environmentNode["debugServer"]);
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
if (environmentNode["insight"]) {
|
|
|
|
|
if (!environmentNode["insight"].IsMap()) {
|
|
|
|
|
throw Exceptions::InvalidConfig(
|
|
|
|
|
"Invalid insight configuration provided - 'insight' must be of mapping type."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->insightConfig = InsightConfig(environmentNode["insight"]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (environmentNode["shutdownPostDebugSession"]) {
|
|
|
|
|
this->shutdownPostDebugSession = environmentNode["shutdownPostDebugSession"].as<bool>(
|
|
|
|
|
this->shutdownPostDebugSession
|
|
|
|
|
);
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
TargetConfig::TargetConfig(const YAML::Node& targetNode) {
|
|
|
|
|
if (!targetNode["name"]) {
|
2022-02-05 15:32:08 +00:00
|
|
|
throw Exceptions::InvalidConfig("No target name found.");
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
this->name = String::asciiToLower(targetNode["name"].as<std::string>());
|
2022-02-05 15:32:08 +00:00
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
if (targetNode["variantName"]) {
|
|
|
|
|
this->variantName = String::asciiToLower(targetNode["variantName"].as<std::string>());
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-04-08 20:42:23 +01:00
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
this->targetNode = targetNode;
|
2021-04-08 20:42:23 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
DebugToolConfig::DebugToolConfig(const YAML::Node& debugToolNode) {
|
|
|
|
|
if (!debugToolNode["name"]) {
|
2022-02-05 15:32:08 +00:00
|
|
|
throw Exceptions::InvalidConfig("No debug tool name found.");
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
this->name = String::asciiToLower(debugToolNode["name"].as<std::string>());
|
2021-05-30 16:48:34 +01:00
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
if (debugToolNode["releasePostDebugSession"]) {
|
|
|
|
|
this->releasePostDebugSession = debugToolNode["releasePostDebugSession"].as<bool>(
|
|
|
|
|
this->releasePostDebugSession
|
|
|
|
|
);
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-05-30 16:48:34 +01:00
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
this->debugToolNode = debugToolNode;
|
2021-05-30 16:48:34 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-23 15:37:22 +01:00
|
|
|
DebugServerConfig::DebugServerConfig(const YAML::Node& debugServerNode) {
|
|
|
|
|
if (!debugServerNode["name"]) {
|
|
|
|
|
throw Exceptions::InvalidConfig("No debug server name found.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->name = String::asciiToLower(debugServerNode["name"].as<std::string>());
|
|
|
|
|
this->debugServerNode = debugServerNode;
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|