Skip to content

Commit 587bb48

Browse files
[projmgr] Improve layer variables handling (#1098) (#1901)
Co-authored-by: Daniel Brondani <[email protected]>
1 parent 329e617 commit 587bb48

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

tools/projmgr/include/ProjMgrUtils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,13 @@ class ProjMgrUtils {
280280
*/
281281
static const std::string ULLToHex(unsigned long long number);
282282

283+
/**
284+
* @brief get variable name
285+
* @param input string
286+
* @return variable name or empty string
287+
*/
288+
static const std::string GetVariableName(const std::string item);
289+
283290
protected:
284291
/**
285292
* @brief get filtered list of contexts

tools/projmgr/include/ProjMgrWorker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ struct ContextTypesItem {
281281
* map of absolute file paths,
282282
* map of generators,
283283
* map of compatible layers,
284+
* map of layer variables,
284285
* valid connections,
285286
* linker options,
286287
* map of variables,
@@ -342,6 +343,7 @@ struct ContextItem {
342343
std::map<std::string, RteGenerator*> generators;
343344
std::map<std::string, GpdscItem> gpdscs;
344345
StrVecMap compatibleLayers;
346+
StrMap layerVariables;
345347
std::vector<ConnectionsCollectionVec> validConnections;
346348
LinkerContextItem linker;
347349
std::map<std::string, std::string> variables;

tools/projmgr/src/ProjMgrCbuildIdx.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,10 @@ void ProjMgrCbuildIdx::SetVariablesNode(YAML::Node node, ProjMgrParser* parser,
192192
}
193193
YAML::Node layerNode;
194194
string layerFile;
195+
const string layerId = context->layerVariables.find(type) != context->layerVariables.end() ?
196+
context->layerVariables.at(type) : type + "-Layer";
195197
if (filenames.empty()) {
196-
layerNode[type + "-Layer"] = "";
198+
layerNode[layerId] = "";
197199
}
198200
for (const auto& [filename, options] : filenames) {
199201
string packRoot = ProjMgrKernel::Get()->GetCmsisPackRoot();
@@ -211,7 +213,7 @@ void ProjMgrCbuildIdx::SetVariablesNode(YAML::Node node, ProjMgrParser* parser,
211213
layerFile = "$" + string(RteConstants::AS_SOLUTION_DIR_BR) + "$/" + RteFsUtils::LexicallyNormal(relPath);
212214
}
213215
}
214-
SetNodeValue(layerNode[type + "-Layer"], layerFile);
216+
SetNodeValue(layerNode[layerId], layerFile);
215217
if (parser->GetGenericClayers().find(filename) != parser->GetGenericClayers().end()) {
216218
const auto& clayer = parser->GetGenericClayers().at(filename);
217219
SetNodeValue(layerNode[YAML_DESCRIPTION], clayer.description);

tools/projmgr/src/ProjMgrUtils.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,3 +439,12 @@ const string ProjMgrUtils::ULLToHex(const unsigned long long number) {
439439
ss << "0x" << hex << setfill('0') << uppercase << setw(8) << number;
440440
return ss.str();
441441
}
442+
443+
const string ProjMgrUtils::GetVariableName(const string item) {
444+
smatch sm;
445+
regex_match(item, sm, regex(".*\\$(.*)\\$.*"));
446+
if (sm.size() >= 2) {
447+
return sm[1];
448+
}
449+
return RteUtils::EMPTY_STRING;
450+
}

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ bool ProjMgrWorker::ParseContextLayers(ContextItem& context) {
199199
continue;
200200
}
201201
if (CheckContextFilters(clayer.typeFilter, context)) {
202-
error_code ec;
202+
const auto variable = ProjMgrUtils::GetVariableName(clayer.layer);
203+
if (!variable.empty()) {
204+
context.layerVariables[clayer.type] = variable;
205+
}
203206
string clayerFile = RteUtils::ExpandAccessSequences(clayer.layer, context.variables);
204207
if (clayerFile.empty()) {
205208
continue;
@@ -208,16 +211,9 @@ bool ProjMgrWorker::ParseContextLayers(ContextItem& context) {
208211
RteFsUtils::NormalizePath(clayerFile, context.cproject->directory);
209212
}
210213
if (!RteFsUtils::Exists(clayerFile)) {
211-
smatch sm;
212-
try {
213-
regex_match(clayer.layer, sm, regex(".*\\$(.*)\\$.*"));
214-
}
215-
catch (exception&) {};
216-
if (sm.size() >= 2) {
217-
if (context.variables.find(sm[1]) == context.variables.end()) {
218-
m_undefLayerVars.insert(string(sm[1]));
219-
continue;
220-
}
214+
if (!variable.empty() && context.variables.find(variable) == context.variables.end()) {
215+
m_undefLayerVars.insert(string(variable));
216+
continue;
221217
}
222218
}
223219
if (m_parser->ParseClayer(clayerFile, m_checkSchema)) {
@@ -860,7 +856,10 @@ bool ProjMgrWorker::ProcessLayerCombinations(ContextItem& context, LayersDiscove
860856

861857
// init list of compatible layers with all required layer types
862858
for (const auto& type : discover.requiredLayerTypes) {
863-
context.compatibleLayers.insert({ type, StrVec() });
859+
context.compatibleLayers.emplace(type, StrVec());
860+
}
861+
for (const auto& [type, _] : context.layerVariables) {
862+
context.compatibleLayers.emplace(type, StrVec());
864863
}
865864
// update list of compatible layers
866865
context.validConnections.push_back(combination);

0 commit comments

Comments
 (0)