Skip to content

Commit

Permalink
Define $generator_id and $pack_id variables in generator arguments
Browse files Browse the repository at this point in the history
$generator_id resolves to the current generator id
$pack_id resolves to the current pack id in YAML format

Also, add from-pack property on the generator nodes in the cbuild.yml
to identify what pack the generator is defined in.
This resolves potential conflicts when using generators from multiple
packs that has the same name.

Contributed by STMicroelectronics

Signed-off-by: Torbjörn SVENSSON <[email protected]>
  • Loading branch information
Torbjorn-Svensson committed Jun 22, 2023
1 parent 22d2212 commit a46782d
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 5 deletions.
6 changes: 6 additions & 0 deletions libs/rtemodel/include/RtePackage.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,12 @@ class RtePackage : public RteRootItem
*/
void SetPackageState(PackageState packState) { m_packState = packState; }

/**
* @brief get full pack ID in YAML format
* @return full pack ID in YAML format
*/
std::string GetPackYamlID() const;

/**
* @brief get full or common pack ID
* @param withVersion flag to return full (true) or common (false) ID
Expand Down
8 changes: 7 additions & 1 deletion libs/rtemodel/src/RteGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,18 @@ string RteGenerator::GetExecutable(RteTarget* target, const std::string& hostTyp
vector<pair<string, string> > RteGenerator::GetExpandedArguments(RteTarget* target, const string& hostType) const
{
vector<pair<string, string> > args;
string packId = GetPackage()->GetPackYamlID();
string generatorId = GetGeneratorName();

RteItem* argsItem = GetArgumentsItem("exe");
if (argsItem) {
for (auto arg : argsItem->GetChildren()) {
if (arg->GetTag() != "argument" || !arg->MatchesHost(hostType))
continue;
args.push_back({arg->GetAttribute("switch"), ExpandString(arg->GetText())});
string res = arg->GetText();
RteUtils::ReplaceAll(res, "$pack_id", packId);
RteUtils::ReplaceAll(res, "$generator_id", generatorId);
args.push_back({arg->GetAttribute("switch"), ExpandString(res)});
}
}
return args;
Expand Down
20 changes: 20 additions & 0 deletions libs/rtemodel/src/RtePackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,26 @@ string RtePackage::ConstructID()
}


string RtePackage::GetPackYamlID() const
{
string res;

const auto& vendor = GetVendorString().empty() ? "" : GetVendorString() + "::";
const vector<pair<const char*, const string&>> elements = {
{"", vendor},
{"", GetName()},
{"@", GetVersionString()},
};

for (const auto& element : elements) {
if (!element.second.empty()) {
res += element.first + element.second;
}
}
return res;
}


string RtePackage::GetPackageID(bool withVersion) const
{
if (withVersion)
Expand Down
6 changes: 4 additions & 2 deletions tools/projmgr/schemas/common.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,13 @@
"description": "General generator info",
"type": "object",
"properties": {
"from-pack": { "$ref": "#/definitions/PackID"},
"generator": { "type": "string", "description": "Section for a specific generator" },
"path": { "type": "string", "description": "Path name for storing the files generated" },
"gpdsc": { "type": "string", "description": "File name of the *.GDPSC file that stores the information in path" },
"command": { "$ref": "#/definitions/CommandType" }
},
"required": [ "generator", "path", "gpdsc", "command" ]
"required": [ "generator", "from-pack", "path", "gpdsc", "command" ]
},
"CommandType": {
"type": "object",
Expand Down Expand Up @@ -515,9 +516,10 @@
"type": "object",
"properties": {
"id": { "type": "string" },
"from-pack": { "$ref": "#/definitions/PackID"},
"files": { "$ref": "#/definitions/FilesType" }
},
"required": [ "id" ]
"required": [ "id", "from-pack" ]
},
"ComponentID": {
"type": "string",
Expand Down
13 changes: 11 additions & 2 deletions tools/projmgr/src/ProjMgrYamlEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,16 @@ void ProjMgrYamlCbuild::SetComponentsNode(YAML::Node node, const ContextItem* co
}
SetControlsNode(componentNode, componentItem->build);
SetComponentFilesNode(componentNode[YAML_FILES], context, componentId);
SetNodeValue(componentNode[YAML_GENERATOR][YAML_ID], component.generator);
SetGeneratorFiles(componentNode[YAML_GENERATOR], context, componentId);
if (!component.generator.empty()) {
if (context->generators.find(component.generator) != context->generators.end()) {
const RteGenerator* rteGenerator = context->generators.at(component.generator);
SetNodeValue(componentNode[YAML_GENERATOR][YAML_ID], component.generator);
SetNodeValue(componentNode[YAML_GENERATOR][YAML_FROM_PACK], rteGenerator->GetPackage()->GetPackYamlID());
SetGeneratorFiles(componentNode[YAML_GENERATOR], context, componentId);
} else {
ProjMgrLogger::Warn(string("Component ") + componentId + " uses unknown generator " + component.generator);
}
}
node.push_back(componentNode);
}
}
Expand Down Expand Up @@ -204,6 +212,7 @@ void ProjMgrYamlCbuild::SetGeneratorsNode(YAML::Node node, const ContextItem* co
break;
}
}
SetNodeValue(genNode[YAML_FROM_PACK], generator->GetPackage()->GetPackYamlID());
SetNodeValue(genNode[YAML_PATH], FormatPath(workingDir, context->directories.cprj));
SetNodeValue(genNode[YAML_GPDSC], FormatPath(gpdscFile, context->directories.cprj));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ build:
category: sourceC
generator:
id: RteTestGeneratorIdentifier
from-pack: ARM::[email protected]
files:
- file: ${CMSIS_PACK_ROOT}/ARM/RteTestGenerator/0.1.0/Templates/RteTestGen.c.template
category: genSource
Expand All @@ -46,6 +47,7 @@ build:
selected-by: RteTest:CORE
generators:
- generator: RteTestGeneratorIdentifier
from-pack: ARM::[email protected]
path: ../data/TestGenerator/MultipleComponents/RteTestGeneratorIdentifier
gpdsc: ../data/TestGenerator/MultipleComponents/RteTestGeneratorIdentifier/RteTestGen_ARMCM0/RteTest.gpdsc
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ build:
category: sourceC
generator:
id: RteTestGeneratorIdentifier
from-pack: ARM::[email protected]
- component: ARM::RteTest:[email protected]
condition: Cortex-M Device
from-pack: ARM::[email protected]
selected-by: RteTest:CORE
generators:
- generator: RteTestGeneratorIdentifier
from-pack: ARM::[email protected]
path: ../data/TestGenerator/layer/RTE/Device
gpdsc: ../data/TestGenerator/layer/RTE/Device/RteTestGen_ARMCM0/RteTest.gpdsc
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ build:
category: sourceC
generator:
id: RteTestGeneratorIdentifier
from-pack: ARM::[email protected]
- component: ARM::Device:RteTest Generated Component:[email protected]
condition: RteDevice
from-pack: ARM::[email protected]
selected-by: Device:RteTest Generated Component:RteTestWithKey
generator:
id: RteTestGeneratorWithKey
from-pack: ARM::[email protected]
- component: ARM::RteTest:[email protected]
condition: Cortex-M Device
from-pack: ARM::[email protected]
selected-by: RteTest:CORE
generators:
- generator: RteTestGeneratorIdentifier
from-pack: ARM::[email protected]
path: ../data/TestGenerator/GeneratedFiles/RteTestGeneratorIdentifier
gpdsc: ../data/TestGenerator/GeneratedFiles/RteTestGeneratorIdentifier/RteTestGen_ARMCM0/RteTest.gpdsc
command:
Expand Down Expand Up @@ -71,6 +74,7 @@ build:
- ../../../../output/test-gpdsc-multiple-generators.Debug+CM0.cbuild.yml
- --foo=bar
- generator: RteTestGeneratorWithKey
from-pack: ARM::[email protected]
path: ../data/TestGenerator/GeneratedFiles/RteTestGeneratorWithKey
gpdsc: ../data/TestGenerator/GeneratedFiles/RteTestGeneratorWithKey/RteTestGen_ARMCM0/RteTest.gpdsc
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ build:
category: sourceC
generator:
id: RteTestGeneratorIdentifier
from-pack: ARM::[email protected]
- component: ARM::RteTest:[email protected]
condition: Cortex-M Device
from-pack: ARM::[email protected]
selected-by: RteTest:CORE
generators:
- generator: RteTestGeneratorIdentifier
from-pack: ARM::[email protected]
path: ../data/TestGenerator/RTE/Device
gpdsc: ../data/TestGenerator/RTE/Device/RteTestGen_ARMCM0/RteTest.gpdsc
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ build:
selected-by: Device:RteTest Generated Component:RteTestGenFiles
generator:
id: RteTestGeneratorIdentifier
from-pack: ARM::[email protected]
files:
- file: ${CMSIS_PACK_ROOT}/ARM/RteTestGenerator/0.1.0/Templates/RteTest.gpdsc.template
category: genAsset
Expand Down Expand Up @@ -66,6 +67,7 @@ build:
selected-by: CORE
generators:
- generator: RteTestGeneratorIdentifier
from-pack: ARM::[email protected]
path: gendir
gpdsc: gendir/RteTestGen_ARMCM0/RteTest.gpdsc
command:
Expand Down

0 comments on commit a46782d

Please sign in to comment.