Skip to content

Commit b0e2f96

Browse files
authored
[projmgr] Add support for custom configurations for debuggers
1 parent 9a231c7 commit b0e2f96

File tree

13 files changed

+332
-1
lines changed

13 files changed

+332
-1
lines changed

tools/projmgr/include/ProjMgrParser.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,34 @@ struct MemoryItem {
128128
std::string algorithm;
129129
};
130130

131+
/**
132+
* @brief custom item containing
133+
* scalar
134+
* array
135+
* map
136+
*/
137+
struct CustomItem {
138+
std::string scalar;
139+
std::vector<CustomItem> vec;
140+
std::vector<std::pair<std::string, CustomItem>> map;
141+
};
142+
131143
/**
132144
* @brief debugger item containing
133145
* name of debug configuration
134146
* debug protocol (jtag or swd)
135147
* debug clock speed
136148
* debug configuration file
137149
* start pname
150+
* custom properties
138151
*/
139152
struct DebuggerItem {
140153
std::string name;
141154
std::string protocol;
142155
std::string clock;
143156
std::string dbgconf;
144157
std::string startPname;
158+
CustomItem custom;
145159
};
146160

147161
/**
@@ -609,6 +623,7 @@ struct DebugAdapterDefaultsItem {
609623
std::string port;
610624
std::string protocol;
611625
std::string clock;
626+
CustomItem custom;
612627
};
613628

614629
/**

tools/projmgr/include/ProjMgrRunDebug.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ class ProjMgrRunDebug {
225225
const std::map<std::string, RteDeviceProperty*>& pnames);
226226
void CollectDebugTopology(const ContextItem& context, std::vector<std::pair<const RteItem*, std::vector<std::string>>> debugs,
227227
const std::map<std::string, RteDeviceProperty*>& pnames);
228+
void CustomVecPushBack(std::vector<CustomItem>& vec, const CustomItem& value);
229+
CustomItem& CustomMapFind(std::vector<std::pair<std::string, CustomItem>>& customMap, const std::string& key);
230+
void MergeCustomItems(const CustomItem& src, CustomItem& dst);
228231
};
229232

230233
#endif // PROJMGRRUNDEBUG_H

tools/projmgr/include/ProjMgrWorker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ struct GdbServerItem {
288288
* debug configuration file
289289
* start pname
290290
* list of gdbserver items
291+
* custom options
291292
*/
292293
struct DebuggerType {
293294
std::string name;
@@ -297,6 +298,7 @@ struct DebuggerType {
297298
std::string dbgconf;
298299
std::string startPname;
299300
std::vector<GdbServerItem> gdbserver;
301+
CustomItem custom;
300302
};
301303

302304
/**

tools/projmgr/include/ProjMgrYamlParser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ class ProjMgrYamlParser {
352352
bool ParseLinker(const YAML::Node& parent, const std::string& file, std::vector<LinkerItem>& linker);
353353
void ParseRte(const YAML::Node& parent, std::string& rteBaseDir);
354354
void ParseDebugDefaults(const YAML::Node& parent, const std::string& file, DebugAdapterDefaultsItem& defaults);
355+
void ParseCustom(const YAML::Node& parent, const std::vector<std::string>& skip, CustomItem& custom);
355356
bool GetTypes(const std::string& type, std::string& buildType, std::string& targetType, std::string& pattern);
356357
bool ValidateCdefault(const std::string& input, const YAML::Node& root);
357358
bool ValidateCsolution(const std::string& input, const YAML::Node& root);
@@ -365,6 +366,7 @@ class ProjMgrYamlParser {
365366
void ParsePortablePath(const YAML::Node& parent, const std::string& file, const std::string& key, std::string& value);
366367
void ParsePortablePaths(const YAML::Node& parent, const std::string& file, const std::string& key, std::vector<std::string>& value);
367368
void EnsurePortability(const std::string& file, const YAML::Mark& mark, const std::string& key, std::string& value);
369+
CustomItem GetCustomValue(const YAML::Node& node);
368370

369371
};
370372

tools/projmgr/schemas/common.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2413,7 +2413,7 @@
24132413
"protocol": { "enum": [ "jtag", "swd" ], "description": "Selected debug protocol (jtag or swd)." },
24142414
"clock": { "type": "number", "description": "Selected debug clock speed (in Hz)." }
24152415
},
2416-
"additionalProperties": false
2416+
"additionalProperties": true
24172417
}
24182418
}
24192419
}

tools/projmgr/src/ProjMgrCbuildRun.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class ProjMgrCbuildRun : public ProjMgrCbuildBase {
3232
void SetAccessPortsNode(YAML::Node node, const std::vector<AccessPortType>& accessPorts);
3333
void SetDatapatchNode(YAML::Node node, const std::vector<DatapatchType>& datapatch);
3434
void SetGdbServerNode(YAML::Node node, const std::vector<GdbServerItem>& gdbserver);
35+
void SetCustomNodes(YAML::Node node, const CustomItem& debugger);
36+
YAML::Node GetCustomNode(const CustomItem& value);
3537
};
3638

3739
ProjMgrCbuildRun::ProjMgrCbuildRun(YAML::Node node,
@@ -110,6 +112,31 @@ void ProjMgrCbuildRun::SetDebuggerNode(YAML::Node node, const DebuggerType& debu
110112
}
111113
SetNodeValue(node[YAML_START_PNAME], debugger.startPname);
112114
SetGdbServerNode(node[YAML_GDBSERVER], debugger.gdbserver);
115+
SetCustomNodes(node, debugger.custom);
116+
}
117+
}
118+
119+
YAML::Node ProjMgrCbuildRun::GetCustomNode(const CustomItem& value) {
120+
YAML::Node node;
121+
if (!value.scalar.empty()) {
122+
node = value.scalar;
123+
}
124+
else if (!value.vec.empty()) {
125+
for (const auto& item : value.vec) {
126+
node.push_back(GetCustomNode(item));
127+
}
128+
}
129+
else if (!value.map.empty()) {
130+
for (const auto& [k, v] : value.map) {
131+
node[k] = GetCustomNode(v);
132+
}
133+
}
134+
return node;
135+
}
136+
137+
void ProjMgrCbuildRun::SetCustomNodes(YAML::Node node, const CustomItem& custom) {
138+
for (const auto& [key, value] : custom.map) {
139+
node[key] = GetCustomNode(value);
113140
}
114141
}
115142

tools/projmgr/src/ProjMgrRunDebug.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,13 @@ void ProjMgrRunDebug::CollectDebuggerSettings(const ContextItem& context, const
340340
if (!m_runDebug.debugger.clock.has_value() && !adapter.defaults.clock.empty()) {
341341
m_runDebug.debugger.clock = RteUtils::StringToULL(adapter.defaults.clock);
342342
}
343+
// default custom options
344+
m_runDebug.debugger.custom = adapter.defaults.custom;
343345
}
344346
}
347+
348+
// merge custom options
349+
MergeCustomItems(context.debugger.custom, m_runDebug.debugger.custom);
345350
}
346351

347352
void ProjMgrRunDebug::CollectDebugTopology(const ContextItem& context, const vector<pair<const RteItem*, vector<string>>> debugs,
@@ -632,3 +637,38 @@ bool ProjMgrRunDebug::GetDebugAdapter(const string& name, const DebugAdaptersIte
632637
}
633638
return false;
634639
}
640+
641+
void ProjMgrRunDebug::CustomVecPushBack(vector<CustomItem>& vec, const CustomItem& value) {
642+
for (const auto& item : vec) {
643+
if (item.scalar == value.scalar) {
644+
return;
645+
}
646+
}
647+
vec.push_back(value);
648+
}
649+
650+
CustomItem& ProjMgrRunDebug::CustomMapFind(vector<pair<string, CustomItem>>& customMap, const string& key) {
651+
for (auto& [k, v] : customMap) {
652+
if (key == k) {
653+
return v;
654+
}
655+
}
656+
customMap.push_back({ key, CustomItem() });
657+
return customMap.back().second;
658+
}
659+
660+
void ProjMgrRunDebug::MergeCustomItems(const CustomItem& src, CustomItem& dst) {
661+
if (!src.scalar.empty()) {
662+
dst.scalar = src.scalar;
663+
}
664+
else if (!src.vec.empty()) {
665+
for (const auto& item : src.vec) {
666+
CustomVecPushBack(dst.vec, item);
667+
}
668+
}
669+
else if (!src.map.empty()) {
670+
for (const auto& [k, v] : src.map) {
671+
MergeCustomItems(v, CustomMapFind(dst.map, k));
672+
}
673+
}
674+
}

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,7 @@ bool ProjMgrWorker::ProcessDebuggers(ContextItem& context) {
25232523
}
25242524
}
25252525
context.debugger.startPname = m_activeTargetSet.debugger.startPname;
2526+
context.debugger.custom = m_activeTargetSet.debugger.custom;
25262527
}
25272528
for (const auto& [filename, fi] : context.rteActiveProject->GetFileInstances()) {
25282529
if (fi->HasAttribute("configfile")) {

tools/projmgr/src/ProjMgrYamlParser.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ void ProjMgrYamlParser::ParseDebugger(const YAML::Node& parent, const string& fi
615615
ParseNumber(debuggerNode, file, YAML_CLOCK, debugger.clock);
616616
ParsePortablePath(debuggerNode, file, YAML_DBGCONF, debugger.dbgconf);
617617
ParseString(debuggerNode, YAML_START_PNAME, debugger.startPname);
618+
ParseCustom(debuggerNode, { YAML_NAME, YAML_PROTOCOL, YAML_CLOCK, YAML_DBGCONF, YAML_START_PNAME }, debugger.custom);
618619
}
619620
}
620621

@@ -631,6 +632,7 @@ void ProjMgrYamlParser::ParseDebugDefaults(const YAML::Node& parent, const strin
631632
ParseNumber(defaultsNode, file, YAML_PORT, defaults.port);
632633
ParseString(defaultsNode, YAML_PROTOCOL, defaults.protocol);
633634
ParseNumber(defaultsNode, file, YAML_CLOCK, defaults.clock);
635+
ParseCustom(defaultsNode, { YAML_PORT, YAML_PROTOCOL, YAML_CLOCK }, defaults.custom);
634636
}
635637
}
636638

@@ -1074,6 +1076,34 @@ void ProjMgrYamlParser::ParseImages(const YAML::Node& parent, const string& file
10741076
}
10751077
}
10761078

1079+
CustomItem ProjMgrYamlParser::GetCustomValue(const YAML::Node& node) {
1080+
CustomItem value;
1081+
if (node.IsScalar()) {
1082+
value.scalar = node.as<string>();
1083+
}
1084+
else if (node.IsSequence()) {
1085+
for (const auto& item : node) {
1086+
value.vec.push_back(GetCustomValue(item));
1087+
}
1088+
}
1089+
else if (node.IsMap()) {
1090+
for (const auto& item : node) {
1091+
value.map.push_back({ item.first.as<string>(), GetCustomValue(item.second) });
1092+
}
1093+
}
1094+
return value;
1095+
}
1096+
1097+
void ProjMgrYamlParser::ParseCustom(const YAML::Node& parent, const vector<string>& skip, CustomItem& custom) {
1098+
for (const auto& node : parent) {
1099+
const auto& key = node.first.as<string>();
1100+
if (find(skip.begin(), skip.end(), key) != skip.end()) {
1101+
continue;
1102+
}
1103+
custom.map.push_back({ key, GetCustomValue(node.second) });
1104+
}
1105+
}
1106+
10771107
// Validation Maps
10781108
const set<string> defaultKeys = {
10791109
YAML_COMPILER,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/cproject.schema.json
2+
3+
project:
4+
5+
components:
6+
- component: Startup
7+
- component: CORE

0 commit comments

Comments
 (0)