Skip to content

Commit bdb300a

Browse files
authored
[projmgr] Add load node handling
1 parent ebed5cc commit bdb300a

15 files changed

+220
-17
lines changed

tools/projmgr/include/ProjMgrParser.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,24 @@ struct DebuggerItem {
438438
TypeFilter type;
439439
};
440440

441+
/**
442+
* @brief load item containing
443+
* file specifies the file name
444+
* info brief description of the file
445+
* type specifies an explicit file type
446+
* run additional command string for download or programming
447+
* debug additional command string for debug
448+
* type filter
449+
*/
450+
struct LoadItem {
451+
std::string file;
452+
std::string info;
453+
std::string type;
454+
std::string run;
455+
std::string debug;
456+
TypeFilter typeFilter;
457+
};
458+
441459
typedef std::vector<std::pair<std::string, BuildType>> BuildTypes;
442460
typedef std::vector<std::pair<std::string, TargetType>> TargetTypes;
443461
/**
@@ -458,7 +476,8 @@ typedef std::vector<std::pair<std::string, TargetType>> TargetTypes;
458476
* cdefault enable switch,
459477
* generator options,
460478
* list of executes,
461-
* list of debuggers
479+
* list of debuggers,
480+
* list of loads
462481
*/
463482
struct CsolutionItem {
464483
std::string name;
@@ -479,6 +498,7 @@ struct CsolutionItem {
479498
CbuildPackItem cbuildPack;
480499
std::vector<ExecutesItem> executes;
481500
std::vector<DebuggerItem> debuggers;
501+
std::vector<LoadItem> loads;
482502
std::vector<std::string> ymlOrderedBuildTypes;
483503
std::vector<std::string> ymlOrderedTargetTypes;
484504
};

tools/projmgr/include/ProjMgrRunDebug.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ struct SystemResourcesType {
5050
*/
5151
struct FilesType {
5252
std::string file;
53+
std::string info;
5354
std::string type;
55+
std::string run;
56+
std::string debug;
5457
std::string pname;
5558
};
5659

@@ -149,6 +152,7 @@ class ProjMgrRunDebug {
149152
void GetDebugSequenceBlock(const RteItem* item, DebugSequencesBlockType& block);
150153
void PushBackUniquely(std::vector<std::pair<const RteItem*, std::vector<std::string>>>& vec,
151154
const RteItem* item, const std::string pname);
155+
FilesType SetLoadFromOutput(const ContextItem* context, OutputType output, const std::string type);
152156
};
153157

154158
#endif // PROJMGRRUNDEBUG_H

tools/projmgr/include/ProjMgrUtils.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2024 Arm Limited. All rights reserved.
2+
* Copyright (c) 2020-2025 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -287,6 +287,13 @@ class ProjMgrUtils {
287287
*/
288288
static const std::string GetVariableName(const std::string item);
289289

290+
/**
291+
* @brief get file type from file extension
292+
* @param input file
293+
* @return file type or empty string
294+
*/
295+
static const std::string FileTypeFromExtension(const std::string& file);
296+
290297
protected:
291298
/**
292299
* @brief get filtered list of contexts

tools/projmgr/include/ProjMgrWorker.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ struct ContextTypesItem {
299299
* additional memory
300300
* debuggers
301301
* default dbgconf
302+
* loads
302303
*/
303304
struct ContextItem {
304305
CdefaultItem* cdefault = nullptr;
@@ -363,6 +364,7 @@ struct ContextItem {
363364
std::vector<MemoryItem> memory;
364365
std::vector<DebuggerItem> debuggers;
365366
std::pair<std::string, RteFileInstance*> dbgconf;
367+
std::vector<LoadItem> loads;
366368
};
367369

368370
/**
@@ -856,7 +858,8 @@ class ProjMgrWorker {
856858
bool ProcessGpdsc(ContextItem& context);
857859
bool ProcessConfigFiles(ContextItem& context);
858860
bool ProcessComponentFiles(ContextItem& context);
859-
void ProcessDebuggers(ContextItem& context);
861+
bool ProcessDebuggers(ContextItem& context);
862+
bool ProcessLoads(ContextItem& context);
860863
bool ProcessExecutes(ContextItem& context, bool solutionLevel = false);
861864
bool ProcessGroups(ContextItem& context);
862865
bool ProcessSequencesRelatives(ContextItem& context, bool rerun);

tools/projmgr/include/ProjMgrYamlParser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static constexpr const char* YAML_LANGUAGE_C = "language-C";
122122
static constexpr const char* YAML_LANGUAGE_CPP = "language-CPP";
123123
static constexpr const char* YAML_LAYER = "layer";
124124
static constexpr const char* YAML_LAYERS = "layers";
125+
static constexpr const char* YAML_LOAD = "load";
125126
static constexpr const char* YAML_LICENSE = "license";
126127
static constexpr const char* YAML_LICENSES = "licenses";
127128
static constexpr const char* YAML_LICENSE_AGREEMENT = "license-agreement";
@@ -291,6 +292,7 @@ class ProjMgrYamlParser {
291292
void ParseGenerators(const YAML::Node& parent, const std::string& file, GeneratorsItem& generators);
292293
void ParseExecutes(const YAML::Node& parent, const std::string& file, std::vector<ExecutesItem>& executes);
293294
bool ParseDebugger(const YAML::Node& parent, const std::string& file, std::vector<DebuggerItem>& debbugers);
295+
bool ParseLoad(const YAML::Node& parent, const std::string& file, std::vector<LoadItem>& loads);
294296
void ParseConnections(const YAML::Node& parent, std::vector<ConnectItem>& connects);
295297
bool ParseTargetType(const YAML::Node& parent, const std::string& file, TargetType& targetType);
296298
bool ParseBuildTypes(const YAML::Node& parent, const std::string& file, BuildTypes& buildTypes);

tools/projmgr/schemas/common.schema.json

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@
11051105
"generators": { "$ref": "#/definitions/GeneratorsOutputType" },
11061106
"language-C": { "$ref": "#/definitions/LanguageCType" },
11071107
"language-CPP": { "$ref": "#/definitions/LanguageCppType" },
1108+
"load": { "$ref": "#/definitions/LoadsType" },
11081109
"misc": { "$ref": "#/definitions/MiscTypes" },
11091110
"optimize": { "$ref": "#/definitions/OptimizeType" },
11101111
"output-dirs": { "$ref": "#/definitions/OutputDirectoriesType" },
@@ -2018,8 +2019,11 @@
20182019
"RunFileType": {
20192020
"type": "object",
20202021
"properties": {
2021-
"file": { "type": "string", "description": "File path." },
2022-
"type": { "type": "string", "description": "File type." },
2022+
"file": { "type": "string", "description": "Specifies the file name." },
2023+
"info": { "type": "string", "description": "Brief description of the file." },
2024+
"type": { "type": "string", "description": "Specifies the file type." },
2025+
"run": { "type": "string", "description": "Additional command string for download or programming." },
2026+
"debug": { "type": "string", "description": "Additional command string for debug." },
20232027
"pname": { "type": "string", "description": "Processor name." }
20242028
},
20252029
"additionalProperties": false
@@ -2044,7 +2048,7 @@
20442048
},
20452049
"DebugBlocksType": {
20462050
"type": "array",
2047-
"uniqueItems": true,
2051+
"uniqueItems": false,
20482052
"items": { "$ref": "#/definitions/DebugBlockType" }
20492053
},
20502054
"DebugBlockType": {
@@ -2111,6 +2115,26 @@
21112115
"additionalProperties": false,
21122116
"required": ["name"]
21132117
},
2118+
"LoadsType": {
2119+
"description": "Specifies additional files to add to the output node.",
2120+
"type": "array",
2121+
"uniqueItems": true,
2122+
"items": { "$ref": "#/definitions/LoadType" }
2123+
},
2124+
"LoadType": {
2125+
"type": "object",
2126+
"properties": {
2127+
"file": { "type": "string", "description": "Specifies the file name." },
2128+
"info": { "type": "string", "description": "Brief description of the file." },
2129+
"type": { "enum": [ "elf", "hex", "bin", "lib" ], "description": "Specifies an explicit file type." },
2130+
"run": { "type": "string", "description": "Additional command string for download or programming." },
2131+
"debug": { "type": "string", "description": "Additional command string for debug." },
2132+
"for-context": { "$ref": "#/definitions/ForContext" },
2133+
"not-for-context": { "$ref": "#/definitions/NotForContext" }
2134+
},
2135+
"additionalProperties": false,
2136+
"required": ["file"]
2137+
},
21142138
"DebugVarsType": {
21152139
"description": "Debug variables for debug sequences.",
21162140
"type": "object",

tools/projmgr/src/ProjMgrCbuildRun.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ void ProjMgrCbuildRun::SetFilesNode(YAML::Node node, const std::vector<FilesType
7171
for (const auto& item : files) {
7272
YAML::Node fileNode;
7373
SetNodeValue(fileNode[YAML_FILE], FormatPath(item.file, m_directory));
74+
SetNodeValue(fileNode[YAML_INFO], item.info);
7475
SetNodeValue(fileNode[YAML_TYPE], item.type);
76+
SetNodeValue(fileNode[YAML_RUN], item.run);
77+
SetNodeValue(fileNode[YAML_DEBUG], item.debug);
7578
SetNodeValue(fileNode[YAML_PNAME], item.pname);
7679
node.push_back(fileNode);
7780
}

tools/projmgr/src/ProjMgrRunDebug.cpp

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,36 @@ bool ProjMgrRunDebug::CollectSettings(const vector<ContextItem*>& contexts) {
170170

171171
// outputs
172172
for (const auto& context : contexts) {
173-
auto output = context->outputTypes;
174-
if (output.elf.on) {
175-
RteFsUtils::NormalizePath(output.elf.filename, context->directories.cprj + '/' + context->directories.outdir);
176-
m_runDebug.outputs.push_back({ output.elf.filename, RteConstants::OUTPUT_TYPE_ELF });
173+
// populate load entries from context outputs
174+
const map<const string, const OutputType> types = {
175+
{ RteConstants::OUTPUT_TYPE_ELF, context->outputTypes.elf },
176+
{ RteConstants::OUTPUT_TYPE_HEX, context->outputTypes.hex },
177+
{ RteConstants::OUTPUT_TYPE_BIN, context->outputTypes.bin },
178+
};
179+
for (const auto& [type, output] : types) {
180+
const auto& load = SetLoadFromOutput(context, output, type);
181+
if (!load.file.empty()) {
182+
m_runDebug.outputs.push_back(load);
183+
}
177184
}
178-
if (output.hex.on) {
179-
RteFsUtils::NormalizePath(output.hex.filename, context->directories.cprj + '/' + context->directories.outdir);
180-
m_runDebug.outputs.push_back({ output.hex.filename, RteConstants::OUTPUT_TYPE_HEX });
185+
}
186+
for (const auto& context : contexts) {
187+
// merge/insert user defined load nodes
188+
for (const auto& item : context->loads) {
189+
bool merged = false;
190+
for (auto& output : m_runDebug.outputs) {
191+
if (output.file == item.file) {
192+
output.info = output.info.empty() ? item.info : output.info;
193+
output.type = output.type.empty() ? item.type : output.type;
194+
output.run = output.run.empty() ? item.run : output.run;
195+
output.debug = output.debug.empty() ? item.debug : output.debug;
196+
merged = true;
197+
break;
198+
}
199+
}
200+
if (!merged) {
201+
m_runDebug.outputs.push_back({ item.file, item.info, item.type, item.run, item.debug });
202+
}
181203
}
182204
}
183205

@@ -239,6 +261,17 @@ bool ProjMgrRunDebug::CollectSettings(const vector<ContextItem*>& contexts) {
239261
return true;
240262
}
241263

264+
FilesType ProjMgrRunDebug::SetLoadFromOutput(const ContextItem* context, OutputType output, const string type) {
265+
FilesType load;
266+
if (output.on) {
267+
RteFsUtils::NormalizePath(output.filename, context->directories.cprj + '/' + context->directories.outdir);
268+
load.file = output.filename;
269+
load.info = "generate by " + context->name;
270+
load.type = type;
271+
}
272+
return load;
273+
}
274+
242275
void ProjMgrRunDebug::GetDebugSequenceBlock(const RteItem* item, DebugSequencesBlockType& block) {
243276
// get 'block' attributes
244277
if (item->GetTag() == "block") {

tools/projmgr/src/ProjMgrUtils.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,19 @@ const string ProjMgrUtils::GetVariableName(const string item) {
448448
}
449449
return RteUtils::EMPTY_STRING;
450450
}
451+
452+
const string ProjMgrUtils::FileTypeFromExtension(const string& file) {
453+
static const map<string, vector<string>> FILE_TYPE = {
454+
{ RteConstants::OUTPUT_TYPE_LIB, {".lib", ".a"} },
455+
{ RteConstants::OUTPUT_TYPE_ELF, {".elf", ".axf"} },
456+
{ RteConstants::OUTPUT_TYPE_HEX, {".hex", ".h386"} },
457+
{ RteConstants::OUTPUT_TYPE_BIN, {".bin" } },
458+
};
459+
fs::path ext((fs::path(file)).extension());
460+
for (const auto& category : FILE_TYPE) {
461+
if (find(category.second.begin(), category.second.end(), ext) != category.second.end()) {
462+
return category.first;
463+
}
464+
}
465+
return RteUtils::EMPTY_STRING;
466+
}

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,13 +2474,18 @@ bool ProjMgrWorker::ProcessExecutes(ContextItem& context, bool solutionLevel) {
24742474
return true;
24752475
}
24762476

2477-
void ProjMgrWorker::ProcessDebuggers(ContextItem& context) {
2477+
bool ProjMgrWorker::ProcessDebuggers(ContextItem& context) {
24782478
const vector<DebuggerItem>& debuggers = m_parser->GetCsolution().debuggers;
24792479
for (const auto& item : debuggers) {
24802480
if (CheckContextFilters(item.type, context)) {
24812481
auto filtered = item;
2482-
if (!filtered.dbgconf.empty() && RteFsUtils::IsRelative(filtered.dbgconf)) {
2483-
RteFsUtils::NormalizePath(filtered.dbgconf, context.csolution->directory);
2482+
if (!filtered.dbgconf.empty()) {
2483+
if (!ProcessSequenceRelative(context, filtered.dbgconf, context.csolution->directory)) {
2484+
return false;
2485+
}
2486+
if (RteFsUtils::IsRelative(filtered.dbgconf)) {
2487+
RteFsUtils::NormalizePath(filtered.dbgconf, context.directories.cprj);
2488+
}
24842489
}
24852490
context.debuggers.push_back(filtered);
24862491
}
@@ -2493,6 +2498,26 @@ void ProjMgrWorker::ProcessDebuggers(ContextItem& context) {
24932498
break;
24942499
}
24952500
}
2501+
return true;
2502+
}
2503+
2504+
bool ProjMgrWorker::ProcessLoads(ContextItem& context) {
2505+
const vector<LoadItem>& loads = m_parser->GetCsolution().loads;
2506+
for (auto item : loads) {
2507+
if (CheckContextFilters(item.typeFilter, context)) {
2508+
if (item.type.empty()) {
2509+
item.type = ProjMgrUtils::FileTypeFromExtension(item.file);
2510+
}
2511+
if (!ProcessSequenceRelative(context, item.file, context.csolution->directory)) {
2512+
return false;
2513+
}
2514+
if (RteFsUtils::IsRelative(item.file)) {
2515+
RteFsUtils::NormalizePath(item.file, context.directories.cprj);
2516+
}
2517+
context.loads.push_back(item);
2518+
}
2519+
}
2520+
return true;
24962521
}
24972522

24982523
bool ProjMgrWorker::ProcessSolutionExecutes() {
@@ -3737,7 +3762,8 @@ bool ProjMgrWorker::ProcessContext(ContextItem& context, bool loadGenFiles, bool
37373762
}
37383763
}
37393764
}
3740-
ProcessDebuggers(context);
3765+
ret &= ProcessDebuggers(context);
3766+
ret &= ProcessLoads(context);
37413767
CheckMissingPackRequirements(context.name);
37423768
return ret;
37433769
}

0 commit comments

Comments
 (0)