- Renamed build script for brief target descriptor generation
- Created new TargetService class - Moved brief target descriptor mapping to new TargetService class - Replaced CMake custom commands with custom targets, for TDF validation and brief target descriptor generation build scripts - Moved BriefTargetDescriptor into separate header file
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include <QUrlQuery>
|
||||
|
||||
#include "src/Logger/Logger.hpp"
|
||||
#include "src/Services/TargetService.hpp"
|
||||
#include "src/Services/PathService.hpp"
|
||||
#include "src/Services/ProcessService.hpp"
|
||||
#include "src/Helpers/BiMap.hpp"
|
||||
@@ -399,10 +400,10 @@ int Application::presentCapabilitiesMachine() {
|
||||
|
||||
auto supportedTargets = QJsonArray();
|
||||
|
||||
for (const auto& [configValue, descriptor] : Targets::TargetDescription::TargetDescriptionFile::mapping()) {
|
||||
for (const auto& [configValue, descriptor] : Services::TargetService::briefDescriptorsByConfigValue()) {
|
||||
supportedTargets.push_back(QJsonObject({
|
||||
{"name" , QString::fromStdString(descriptor.targetName)},
|
||||
{"family" , targetFamilyNames.at(descriptor.targetFamily)},
|
||||
{"name" , QString::fromStdString(descriptor.name)},
|
||||
{"family" , targetFamilyNames.at(descriptor.family)},
|
||||
{"configurationValue" , QString::fromStdString(configValue)},
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ target_sources(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Application.cpp
|
||||
|
||||
# Services
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Services/TargetService.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Services/TargetControllerService.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Services/PathService.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Services/ProcessService.cpp
|
||||
|
||||
20
src/Services/TargetService.cpp
Normal file
20
src/Services/TargetService.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "TargetService.hpp"
|
||||
|
||||
namespace Services
|
||||
{
|
||||
using Targets::BriefTargetDescriptor;
|
||||
|
||||
const std::map<std::string, BriefTargetDescriptor>& TargetService::briefDescriptorsByConfigValue() {
|
||||
return TargetService::descriptorsByConfigValue;
|
||||
}
|
||||
|
||||
std::optional<BriefTargetDescriptor> TargetService::briefDescriptor(const std::string& configValue) {
|
||||
const auto descriptorIt = TargetService::descriptorsByConfigValue.find(configValue);
|
||||
|
||||
if (descriptorIt != TargetService::descriptorsByConfigValue.end()) {
|
||||
return descriptorIt->second;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
48
src/Services/TargetService.hpp
Normal file
48
src/Services/TargetService.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <functional>
|
||||
|
||||
#include "src/Targets/BriefTargetDescriptor.hpp"
|
||||
|
||||
namespace Services
|
||||
{
|
||||
class TargetService
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Performs a lookup for the given target configuration value, to retrieve the corresponding brief target
|
||||
* descriptor object.
|
||||
*
|
||||
* @param configValue
|
||||
* The target configuration value to lookup.
|
||||
*
|
||||
* @return
|
||||
* A BriefTargetDescriptor object, if found, otherwise, std::nullopt.
|
||||
*/
|
||||
static std::optional<Targets::BriefTargetDescriptor> briefDescriptor(const std::string& configValue);
|
||||
|
||||
/**
|
||||
* Provides access to the internal mapping of the brief target descriptor objects of all targets supported by
|
||||
* Bloom. See TargetService::descriptorsByConfigValue for more.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
static const std::map<std::string, Targets::BriefTargetDescriptor>& briefDescriptorsByConfigValue();
|
||||
|
||||
private:
|
||||
/**
|
||||
* This mapping contains brief target descriptor objects for every target supported by Bloom, mapped by their
|
||||
* configuration value. The contents is generated by a build script and stored in an ASCII text file, located
|
||||
* at GENERATED_BRIEF_TARGET_DESCRIPTOR_MAPPING_PATH.
|
||||
*
|
||||
* See build/scripts/GenerateBriefTargetDescriptors.php and the root CMakeLists.txt for more.
|
||||
*/
|
||||
static const inline std::map<std::string, Targets::BriefTargetDescriptor> descriptorsByConfigValue = {
|
||||
#include GENERATED_BRIEF_TARGET_DESCRIPTOR_MAPPING_PATH
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -375,25 +375,23 @@ namespace TargetController
|
||||
};
|
||||
}
|
||||
|
||||
std::unique_ptr<Targets::Target> TargetControllerComponent::constructTargetFromBrief(
|
||||
const TargetDescription::GeneratedMapping::BriefTargetDescriptor &targetBrief
|
||||
) {
|
||||
std::unique_ptr<Target> TargetControllerComponent::constructTarget(const BriefTargetDescriptor& briefDescriptor) {
|
||||
using Services::PathService;
|
||||
|
||||
if (targetBrief.targetFamily == TargetFamily::AVR_8) {
|
||||
if (briefDescriptor.family == TargetFamily::AVR_8) {
|
||||
return std::make_unique<Microchip::Avr::Avr8Bit::Avr8>(
|
||||
this->environmentConfig.targetConfig,
|
||||
Microchip::Avr::Avr8Bit::TargetDescription::TargetDescriptionFile(
|
||||
PathService::targetDescriptionDirPath() + "/" + targetBrief.relativeTdfPath
|
||||
PathService::targetDescriptionDirPath() + "/" + briefDescriptor.relativeTdfPath
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (targetBrief.targetFamily == TargetFamily::RISC_V) {
|
||||
if (briefDescriptor.family == TargetFamily::RISC_V) {
|
||||
return std::make_unique<RiscV::RiscV>(
|
||||
this->environmentConfig.targetConfig,
|
||||
RiscV::TargetDescription::TargetDescriptionFile(
|
||||
PathService::targetDescriptionDirPath() + "/" + targetBrief.relativeTdfPath
|
||||
PathService::targetDescriptionDirPath() + "/" + briefDescriptor.relativeTdfPath
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -470,10 +468,9 @@ namespace TargetController
|
||||
const auto& targetName = this->environmentConfig.targetConfig.name;
|
||||
|
||||
static const auto supportedDebugTools = this->getSupportedDebugTools();
|
||||
static const auto targetsByConfigValue = TargetDescription::TargetDescriptionFile::mapping();
|
||||
|
||||
const auto debugToolIt = supportedDebugTools.find(debugToolName);
|
||||
const auto targetBriefIt = targetsByConfigValue.find(targetName);
|
||||
const auto briefTargetDescriptor = Services::TargetService::briefDescriptor(targetName);
|
||||
|
||||
if (debugToolIt == supportedDebugTools.end()) {
|
||||
throw Exceptions::InvalidConfig(
|
||||
@@ -481,7 +478,7 @@ namespace TargetController
|
||||
);
|
||||
}
|
||||
|
||||
if (targetBriefIt == targetsByConfigValue.end()) {
|
||||
if (!briefTargetDescriptor.has_value()) {
|
||||
throw Exceptions::InvalidConfig(
|
||||
"Target name (\"" + targetName + "\") not recognised. Please check your configuration!"
|
||||
);
|
||||
@@ -497,7 +494,7 @@ namespace TargetController
|
||||
Logger::info("Debug tool serial: " + this->debugTool->getSerialNumber());
|
||||
Logger::info("Debug tool firmware version: " + this->debugTool->getFirmwareVersionString());
|
||||
|
||||
this->target = this->constructTargetFromBrief(targetBriefIt->second);
|
||||
this->target = this->constructTarget(*briefTargetDescriptor);
|
||||
const auto& targetDescriptor = this->getTargetDescriptor();
|
||||
|
||||
if (!this->target->supportsDebugTool(this->debugTool.get())) {
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
#include "Responses/Breakpoint.hpp"
|
||||
|
||||
#include "src/DebugToolDrivers/DebugTools.hpp"
|
||||
#include "src/Targets/BriefTargetDescriptor.hpp"
|
||||
#include "src/Targets/Target.hpp"
|
||||
#include "src/Targets/Targets.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
@@ -248,12 +249,10 @@ namespace TargetController
|
||||
/**
|
||||
* Constructs a Target instance from a BriefTargetDescriptor object.
|
||||
*
|
||||
* @param targetBrief
|
||||
* @param briefDescriptor
|
||||
* @return
|
||||
*/
|
||||
std::unique_ptr<Targets::Target> constructTargetFromBrief(
|
||||
const Targets::TargetDescription::GeneratedMapping::BriefTargetDescriptor& targetBrief
|
||||
);
|
||||
std::unique_ptr<Targets::Target> constructTarget(const Targets::BriefTargetDescriptor& briefDescriptor);
|
||||
|
||||
/**
|
||||
* Processes any pending commands in the queue.
|
||||
|
||||
53
src/Targets/BriefTargetDescriptor.hpp
Normal file
53
src/Targets/BriefTargetDescriptor.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
#include "TargetFamily.hpp"
|
||||
|
||||
namespace Targets
|
||||
{
|
||||
/**
|
||||
* The BriefTargetDescriptor struct provides limited information on a particular target.
|
||||
*
|
||||
* This struct serves as a starting point for constructing a Target object - it provides us with all the relevant
|
||||
* information to construct a TargetDescriptionFile object, and subsequently, a Target object.
|
||||
*
|
||||
* At build time, we generate a BriefTargetDescriptor object for every target supported by Bloom. These objects
|
||||
* can be found in the TargetService::descriptorsByConfigValue member. See the TargetService class for more.
|
||||
*/
|
||||
struct BriefTargetDescriptor
|
||||
{
|
||||
/**
|
||||
* Target's market name.
|
||||
*/
|
||||
std::string name;
|
||||
|
||||
/**
|
||||
* Target's configuration value.
|
||||
*/
|
||||
std::string configValue;
|
||||
|
||||
/**
|
||||
* Target's family (AVR8/RISC-V)
|
||||
*/
|
||||
TargetFamily family;
|
||||
|
||||
/**
|
||||
* The file path to to the target's TDF, relative to Bloom's TDF directory.
|
||||
*/
|
||||
std::string relativeTdfPath;
|
||||
|
||||
constexpr BriefTargetDescriptor(
|
||||
const std::string& name,
|
||||
const std::string& configValue,
|
||||
TargetFamily family,
|
||||
const std::string& relativeTdfPath
|
||||
)
|
||||
: name(name)
|
||||
, configValue(configValue)
|
||||
, family(family)
|
||||
, relativeTdfPath(relativeTdfPath)
|
||||
{}
|
||||
};
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "src/Targets/TargetFamily.hpp"
|
||||
|
||||
namespace Targets::TargetDescription
|
||||
{
|
||||
struct GeneratedMapping
|
||||
{
|
||||
struct BriefTargetDescriptor
|
||||
{
|
||||
std::string targetName;
|
||||
std::string configValue;
|
||||
TargetFamily targetFamily;
|
||||
std::string relativeTdfPath;
|
||||
|
||||
constexpr BriefTargetDescriptor(
|
||||
const std::string& targetName,
|
||||
const std::string& configValue,
|
||||
TargetFamily targetFamily,
|
||||
const std::string& relativeTdfPath
|
||||
)
|
||||
: targetName(targetName)
|
||||
, configValue(configValue)
|
||||
, targetFamily(targetFamily)
|
||||
, relativeTdfPath(relativeTdfPath)
|
||||
{}
|
||||
};
|
||||
|
||||
/*
|
||||
* The @MAPPING_PLACEHOLDER@ comment below will be replaced with the TDF mapping
|
||||
*/
|
||||
static const inline std::map<std::string, BriefTargetDescriptor> map = {
|
||||
//@MAPPING_PLACEHOLDER@
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -20,10 +20,6 @@ namespace Targets::TargetDescription
|
||||
|
||||
using Services::StringService;
|
||||
|
||||
const std::map<std::string, GeneratedMapping::BriefTargetDescriptor>& TargetDescriptionFile::mapping() {
|
||||
return GeneratedMapping::map;
|
||||
}
|
||||
|
||||
TargetDescriptionFile::TargetDescriptionFile(const std::string& xmlFilePath) {
|
||||
this->init(xmlFilePath);
|
||||
}
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
#include "src/Targets/TargetFamily.hpp"
|
||||
#include "src/Targets/TargetPhysicalInterface.hpp"
|
||||
|
||||
#include GENERATED_TDF_MAPPING_PATH
|
||||
|
||||
namespace Targets::TargetDescription
|
||||
{
|
||||
/**
|
||||
@@ -53,19 +51,6 @@ namespace Targets::TargetDescription
|
||||
class TargetDescriptionFile
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Returns a mapping of target configuration values to instances of the GeneratedMapping::BriefTargetDescriptor
|
||||
* struct.
|
||||
*
|
||||
* The mapping is generated pre-build.
|
||||
*
|
||||
* The GeneratedMapping::BriefTargetDescriptor struct holds some brief info about a particular target, such as
|
||||
* target name, family and TDF path. See the GeneratedMapping.hpp.in template for more.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
static const std::map<std::string, GeneratedMapping::BriefTargetDescriptor>& mapping();
|
||||
|
||||
/**
|
||||
* Will construct a TargetDescriptionFile instance from the XML of a target description file, the path to which
|
||||
* is given via xmlFilePath.
|
||||
|
||||
Reference in New Issue
Block a user