2021-12-31 17:05:31 +00:00
|
|
|
#include "ProjectConfig.hpp"
|
2021-10-02 17:39:27 +01:00
|
|
|
|
2022-12-26 21:57:28 +00:00
|
|
|
#include "src/Services/StringService.hpp"
|
2023-09-23 12:39:39 +01:00
|
|
|
#include "src/Services/PathService.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
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
using Services::StringService;
|
|
|
|
|
|
|
|
|
|
ProjectConfig::ProjectConfig(const YAML::Node& configNode) {
|
|
|
|
|
if (!configNode["environments"]) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exceptions::InvalidConfig{
|
2023-08-13 15:47:51 +01:00
|
|
|
"No environments found - please review the bloom.yaml configuration file and ensure that "
|
2024-07-23 21:14:22 +01:00
|
|
|
"no syntax errors are present."
|
|
|
|
|
};
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2022-07-23 15:37:22 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
if (!configNode["environments"].IsMap()) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exceptions::InvalidConfig{
|
2023-08-13 15:47:51 +01:00
|
|
|
"Invalid environments configuration provided - 'environments' must be of mapping type."
|
2024-07-23 21:14:22 +01:00
|
|
|
};
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2022-07-23 15:37:22 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
const auto& environments = configNode["environments"];
|
2022-02-05 15:32:08 +00:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
for (auto environmentIt = environments.begin(); environmentIt != environments.end(); environmentIt++) {
|
2024-07-23 21:14:22 +01:00
|
|
|
auto environmentName = std::optional<std::string>{};
|
2022-07-23 15:37:22 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
try {
|
|
|
|
|
environmentName = environmentIt->first.as<std::string>();
|
2022-07-23 15:37:22 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
if (!StringService::isAscii(environmentName.value())) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exceptions::InvalidConfig{
|
2023-08-13 15:47:51 +01:00
|
|
|
"Environment name ('" + environmentName.value() + "') is not in ASCII form."
|
2024-07-23 21:14:22 +01:00
|
|
|
};
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2022-02-05 15:32:08 +00:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
this->environments.emplace(
|
|
|
|
|
environmentName.value(),
|
|
|
|
|
EnvironmentConfig{environmentName.value(), environmentIt->second}
|
2023-08-13 15:47:51 +01:00
|
|
|
);
|
2022-07-23 15:37:22 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
} catch (Exceptions::InvalidConfig& exception) {
|
|
|
|
|
Logger::error(
|
|
|
|
|
"Invalid environment config for environment '" + environmentName.value() + "': "
|
|
|
|
|
+ exception.getMessage() + " Environment will be ignored."
|
|
|
|
|
);
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
} catch (YAML::BadConversion& exception) {
|
|
|
|
|
Logger::error(
|
|
|
|
|
"Invalid environment name provided. Environment names must be ASCII strings. Environment will be "
|
2024-07-23 21:14:22 +01:00
|
|
|
"ignored"
|
2023-08-13 15:47:51 +01:00
|
|
|
);
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-09-23 12:39:39 +01:00
|
|
|
if (configNode["debugServer"]) {
|
|
|
|
|
Logger::warning(
|
|
|
|
|
"The 'debugServer' key was renamed to 'server' in v1.0.0. Please update your bloom.yaml configuration. "
|
2024-07-23 21:14:22 +01:00
|
|
|
"See " + Services::PathService::homeDomainName() + "/docs/v1-0-0-migration for more."
|
2023-09-23 12:39:39 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
if (configNode["server"]) {
|
|
|
|
|
this->debugServerConfig = DebugServerConfig(configNode["server"]);
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
if (configNode["insight"]) {
|
|
|
|
|
this->insightConfig = InsightConfig(configNode["insight"]);
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-23 21:48:55 +01:00
|
|
|
// Old param name, will remove later
|
2023-08-13 15:47:51 +01:00
|
|
|
if (configNode["debugLoggingEnabled"]) {
|
2023-09-23 21:48:55 +01:00
|
|
|
this->debugLogging = configNode["debugLoggingEnabled"].as<bool>(this->debugLogging);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (configNode["debugLogging"]) {
|
|
|
|
|
this->debugLogging = configNode["debugLogging"].as<bool>(this->debugLogging);
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
|
|
|
|
}
|
2023-07-13 01:57:13 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
InsightConfig::InsightConfig(const YAML::Node& insightNode) {
|
|
|
|
|
if (!insightNode.IsMap()) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exceptions::InvalidConfig{
|
2023-08-13 15:47:51 +01:00
|
|
|
"Invalid insight configuration provided - node must take the form of a YAML mapping."
|
2024-07-23 21:14:22 +01:00
|
|
|
};
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2023-07-14 18:39:27 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
if (insightNode["activateOnStartup"]) {
|
|
|
|
|
this->activateOnStartup = insightNode["activateOnStartup"].as<bool>(this->activateOnStartup);
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
if (insightNode["shutdownOnClose"]) {
|
|
|
|
|
this->shutdownOnClose = insightNode["shutdownOnClose"].as<bool>(this->shutdownOnClose);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-13 02:05:33 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
EnvironmentConfig::EnvironmentConfig(std::string name, const YAML::Node& environmentNode)
|
|
|
|
|
: name(std::move(name))
|
|
|
|
|
{
|
|
|
|
|
if (!environmentNode.IsMap()) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exceptions::InvalidConfig{"Environment node must take the form of a YAML mapping."};
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2022-07-23 15:37:22 +01:00
|
|
|
|
2023-09-23 12:39:39 +01:00
|
|
|
static auto warn = true;
|
|
|
|
|
|
|
|
|
|
if (warn) {
|
|
|
|
|
if (environmentNode["debugTool"] && !environmentNode["tool"]) {
|
|
|
|
|
Logger::warning(
|
|
|
|
|
"The 'debugTool' key was renamed to 'tool' in v1.0.0. Please update your bloom.yaml configuration. "
|
2024-07-23 21:14:22 +01:00
|
|
|
"Bloom will fail to start up until this is resolved. See "
|
2023-09-23 12:39:39 +01:00
|
|
|
+ Services::PathService::homeDomainName() + "/docs/v1-0-0-migration for more."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (environmentNode["debugServer"] && !environmentNode["server"]) {
|
|
|
|
|
Logger::warning(
|
2023-10-10 21:49:29 +01:00
|
|
|
"The 'debugServer' key was renamed to 'server' in v1.0.0. Please update your bloom.yaml configuration. "
|
2024-07-23 21:14:22 +01:00
|
|
|
"Bloom will fail to start up until this is resolved. See "
|
2023-09-23 12:39:39 +01:00
|
|
|
+ Services::PathService::homeDomainName() + "/docs/v1-0-0-migration for more."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
warn = false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
if (!environmentNode["tool"]) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exceptions::InvalidConfig{"Missing debug tool configuration."};
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
if (!environmentNode["target"]) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exceptions::InvalidConfig{"Missing target configuration."};
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2022-07-23 15:37:22 +01:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
this->debugToolConfig = DebugToolConfig{environmentNode["tool"]};
|
|
|
|
|
this->targetConfig = TargetConfig{environmentNode["target"]};
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
if (environmentNode["server"]) {
|
2024-07-23 21:14:22 +01:00
|
|
|
this->debugServerConfig = DebugServerConfig{environmentNode["server"]};
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2022-07-23 15:37:22 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
if (environmentNode["insight"]) {
|
|
|
|
|
this->insightConfig = InsightConfig(environmentNode["insight"]);
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
if (environmentNode["shutdownPostDebugSession"]) {
|
|
|
|
|
this->shutdownPostDebugSession = environmentNode["shutdownPostDebugSession"].as<bool>(
|
|
|
|
|
this->shutdownPostDebugSession
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-13 01:57:13 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
TargetConfig::TargetConfig(const YAML::Node& targetNode) {
|
2024-02-15 21:24:41 +00:00
|
|
|
using Targets::TargetPhysicalInterface;
|
|
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
if (!targetNode.IsMap()) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exceptions::InvalidConfig{
|
2023-08-13 15:47:51 +01:00
|
|
|
"Invalid target configuration provided - node must take the form of a YAML mapping."
|
2024-07-23 21:14:22 +01:00
|
|
|
};
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
if (!targetNode["name"]) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exceptions::InvalidConfig{"No target name found."};
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2022-02-05 15:32:08 +00:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
this->name = StringService::asciiToLower(targetNode["name"].as<std::string>());
|
2021-04-08 20:42:23 +01:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
static auto physicalInterfacesByConfigName = std::map<std::string, TargetPhysicalInterface>{
|
2024-02-15 21:24:41 +00:00
|
|
|
{"debugwire", TargetPhysicalInterface::DEBUG_WIRE}, // Deprecated - left here for backwards compatibility
|
|
|
|
|
{"debug-wire", TargetPhysicalInterface::DEBUG_WIRE},
|
|
|
|
|
{"pdi", TargetPhysicalInterface::PDI},
|
|
|
|
|
{"jtag", TargetPhysicalInterface::JTAG},
|
|
|
|
|
{"updi", TargetPhysicalInterface::UPDI},
|
2024-10-03 22:55:40 +01:00
|
|
|
{"sdi", TargetPhysicalInterface::SDI},
|
2024-07-23 21:14:22 +01:00
|
|
|
};
|
2024-02-15 21:24:41 +00:00
|
|
|
|
|
|
|
|
if (!targetNode["physicalInterface"]) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exceptions::InvalidConfig{"No physical interface specified."};
|
2024-02-15 21:24:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto physicalInterfaceName = StringService::asciiToLower(targetNode["physicalInterface"].as<std::string>());
|
|
|
|
|
const auto physicalInterfaceIt = physicalInterfacesByConfigName.find(physicalInterfaceName);
|
|
|
|
|
|
|
|
|
|
if (physicalInterfaceIt == physicalInterfacesByConfigName.end()) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exceptions::InvalidConfig{
|
2024-02-15 21:24:41 +00:00
|
|
|
"Invalid physical interface provided (\"" + physicalInterfaceName + "\") for target. "
|
|
|
|
|
"See " + Services::PathService::homeDomainName() + "/docs/configuration/target-physical-interfaces "
|
|
|
|
|
"for valid physical interface configuration values."
|
2024-07-23 21:14:22 +01:00
|
|
|
};
|
2024-02-15 21:24:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->physicalInterface = physicalInterfaceIt->second;
|
|
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
if (targetNode["variantName"]) {
|
|
|
|
|
this->variantName = StringService::asciiToLower(targetNode["variantName"].as<std::string>());
|
2021-04-08 20:42:23 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-20 23:37:54 +01:00
|
|
|
if (targetNode["hardwareBreakpoints"]) {
|
|
|
|
|
this->hardwareBreakpoints = targetNode["hardwareBreakpoints"].as<bool>(this->hardwareBreakpoints);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 17:52:28 +01:00
|
|
|
if (targetNode["programMemoryCache"]) {
|
|
|
|
|
this->programMemoryCache = targetNode["programMemoryCache"].as<bool>(this->programMemoryCache);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
this->targetNode = targetNode;
|
|
|
|
|
}
|
2023-07-13 01:57:13 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
DebugToolConfig::DebugToolConfig(const YAML::Node& debugToolNode) {
|
|
|
|
|
if (!debugToolNode.IsMap()) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exceptions::InvalidConfig{
|
2023-08-13 15:47:51 +01:00
|
|
|
"Invalid debug tool configuration provided - node must take the form of a YAML mapping."
|
2024-07-23 21:14:22 +01:00
|
|
|
};
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
if (!debugToolNode["name"]) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exceptions::InvalidConfig{"No debug tool name found."};
|
2021-05-30 16:48:34 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
this->name = StringService::asciiToLower(debugToolNode["name"].as<std::string>());
|
|
|
|
|
this->debugToolNode = debugToolNode;
|
|
|
|
|
}
|
2023-07-13 01:57:13 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
DebugServerConfig::DebugServerConfig(const YAML::Node& debugServerNode) {
|
|
|
|
|
if (!debugServerNode.IsMap()) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exceptions::InvalidConfig{
|
2023-08-13 15:47:51 +01:00
|
|
|
"Invalid debug server configuration provided - node must take the form of a YAML mapping."
|
2024-07-23 21:14:22 +01:00
|
|
|
};
|
2023-08-13 15:47:51 +01:00
|
|
|
}
|
2022-07-23 15:37:22 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
if (!debugServerNode["name"]) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exceptions::InvalidConfig{"No debug server name found."};
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2023-08-13 15:47:51 +01:00
|
|
|
|
|
|
|
|
this->name = StringService::asciiToLower(debugServerNode["name"].as<std::string>());
|
|
|
|
|
this->debugServerNode = debugServerNode;
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|