Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[projmgr] Extend list generators in verbose mode #1194

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tools/projmgr/include/ProjMgrExtGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ class ProjMgrExtGenerator {
*/
const std::string& GetGlobalGenRunCmd(const std::string& generatorId);

/**
* @brief get generator description
* @param generatorId generator identifier
* @return string with generator description
*/
const std::string& GetGlobalDescription(const std::string& generatorId);

/**
* @brief add generator to the list of used generators of a given context
* @param generatorId generator identifier
Expand Down
2 changes: 2 additions & 0 deletions tools/projmgr/include/ProjMgrParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,14 @@ struct CbuildSetItem {
/**
* @brief global generator item containing
* generator id,
* generator description,
* download url,
* bridge program,
* path for generated files
*/
struct GlobalGeneratorItem {
std::string id;
std::string description;
std::string downloadUrl;
std::string run;
std::string path;
Expand Down
1 change: 1 addition & 0 deletions tools/projmgr/schemas/common.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,7 @@
"type": "object",
"properties": {
"id": { "type": "string", "description": "Generator identifier" },
"description": { "type": "string", "description": "Generator description" },
"download-url": { "type": "string", "description": "URL for downloading generator tool" },
"run": { "type": "string", "description": "Related bridge program" },
"path": { "type": "string", "description": "Specifies the directory for generated files" }
Expand Down
3 changes: 3 additions & 0 deletions tools/projmgr/src/ProjMgrExtGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const string& ProjMgrExtGenerator::GetGlobalGenRunCmd(const string& generatorId)
return(m_globalGenerators[generatorId].run);
}

const string& ProjMgrExtGenerator::GetGlobalDescription(const string& generatorId) {
return(m_globalGenerators[generatorId].description);
}

void ProjMgrExtGenerator::AddUsedGenerator(const string& generatorId, const string& genDir, const string& contextId) {
m_usedGenerators[generatorId][genDir].push_back(contextId);
Expand Down
27 changes: 24 additions & 3 deletions tools/projmgr/src/ProjMgrWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3321,17 +3321,38 @@ bool ProjMgrWorker::ListContexts(vector<string>& contexts, const string& filter,

bool ProjMgrWorker::ListGenerators(vector<string>& generators) {
set<string> generatorsSet;
GeneratorContextVecMap generatorsMap;
StrMap generatorsDescription;
for (const auto& selectedContext : m_selectedContexts) {
ContextItem& context = m_contexts[selectedContext];
if (!ProcessContext(context, false, true, false)) {
return false;
}
for (const auto& [id, generator] : context.generators) {
generatorsSet.insert(id + " (" + generator->GetDescription() + ")");
for (const auto& [_, item] : context.gpdscs) {
if (item.generator == id) {
const string workingDir = fs::path(context.cproject->directory).append(item.workingDir).generic_string();
generatorsMap[id][workingDir].push_back(context.name);
generatorsDescription[id] = generator->GetDescription();
break;
}
}
}
}
for (const auto& [id, _] : m_extGenerator->GetUsedGenerators()) {
generatorsSet.insert(id + " (Global Registered Generator)");
GeneratorContextVecMap extGeneratorsMap(m_extGenerator->GetUsedGenerators());
generatorsMap.insert(extGeneratorsMap.begin(), extGeneratorsMap.end());
for (const auto& [id, dirs] : generatorsMap) {
string generatorEntry = id + " (" + (m_extGenerator->IsGlobalGenerator(id) ?
m_extGenerator->GetGlobalDescription(id) : generatorsDescription[id]) + ")";
if (m_verbose) {
for (const auto& [dir, contexts] : dirs) {
generatorEntry += "\n base-dir: " + RteFsUtils::RelativePath(dir, m_parser->GetCsolution().directory);
for (const auto& context : contexts) {
generatorEntry += "\n context: " + context;
}
}
}
generatorsSet.insert(generatorEntry);
}
generators.assign(generatorsSet.begin(), generatorsSet.end());
return true;
Expand Down
1 change: 1 addition & 0 deletions tools/projmgr/src/ProjMgrYamlParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ bool ProjMgrYamlParser::ParseGlobalGenerator(const string& input,
GlobalGeneratorItem generator;
map<const string, string&> generatorChildren = {
{YAML_ID, generator.id},
{YAML_DESCRIPTION, generator.description},
{YAML_DOWNLOAD_URL, generator.downloadUrl},
{YAML_RUN, generator.run},
};
Expand Down
3 changes: 2 additions & 1 deletion tools/projmgr/templates/global.generator.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
generator:
- id: CubeMX
description: Global Registered Generator
download-url: https://www.st.com/en/development-tools/stm32cubemx.html#st-get-software
run: ../bin/cbridge
path: $SolutionDir()$/STM32CubeMX/$Dname$
path: $SolutionDir()$/STM32CubeMX/$TargetType$
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
generator:
- id: RteTestExternalGenerator
description: Global Registered Generator
download-url: https://raw.githubusercontent.com/Open-CMSIS-Pack
run: ./bridge.sh
path: $SolutionDir()$/generated/$TargetType$
59 changes: 59 additions & 0 deletions tools/projmgr/test/src/ProjMgrUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4312,6 +4312,65 @@ TEST_F(ProjMgrUnitTests, ExternalGenerator_NoCgenFile) {
RteFsUtils::RemoveFile(dstGlobalGenerator);
}

TEST_F(ProjMgrUnitTests, ExternalGeneratorListVerbose) {
const string& srcGlobalGenerator = testinput_folder + "/ExternalGenerator/global.generator.yml";
const string& dstGlobalGenerator = testcmsiscompiler_folder + "/global.generator.yml";
RteFsUtils::CopyCheckFile(srcGlobalGenerator, dstGlobalGenerator, false);
StdStreamRedirect streamRedirect;

char* argv[5];
const string& csolution = testinput_folder + "/ExternalGenerator/extgen.csolution.yml";
argv[1] = (char*)csolution.c_str();
argv[2] = (char*)"list";
argv[3] = (char*)"generators";
argv[4] = (char*)"-v";
EXPECT_EQ(0, RunProjMgr(5, argv, 0));

const string expected = "\
RteTestExternalGenerator (Global Registered Generator)\n\
base-dir: generated/CM0\n\
context: ns.Debug+CM0\n\
context: ns.Release+CM0\n\
context: s.Debug+CM0\n\
context: s.Release+CM0\n\
base-dir: generated/MultiCore\n\
context: core0.Debug+MultiCore\n\
context: core0.Release+MultiCore\n\
context: core1.Debug+MultiCore\n\
context: core1.Release+MultiCore\n\
base-dir: single/generated\n\
context: single-core.Debug+CM0\n\
context: single-core.Release+CM0\n\
";
auto outStr = streamRedirect.GetOutString();
EXPECT_TRUE(outStr.find(expected) != string::npos);

RteFsUtils::RemoveFile(dstGlobalGenerator);
}

TEST_F(ProjMgrUnitTests, ClassicGeneratorListVerbose) {
StdStreamRedirect streamRedirect;

char* argv[5];
const string& csolution = testinput_folder + "/TestGenerator/test-gpdsc-multiple-generators.csolution.yml";
argv[1] = (char*)"list";
argv[2] = (char*)"generators";
argv[3] = (char*)csolution.c_str();
argv[4] = (char*)"-v";
EXPECT_EQ(0, RunProjMgr(5, argv, 0));

const string expected = "\
RteTestGeneratorIdentifier (RteTest Generator Description)\n\
base-dir: GeneratedFiles/RteTestGeneratorIdentifier\n\
context: test-gpdsc-multiple-generators.Debug+CM0\n\
RteTestGeneratorWithKey (RteTest Generator with Key Description)\n\
base-dir: GeneratedFiles/RteTestGeneratorWithKey\n\
context: test-gpdsc-multiple-generators.Debug+CM0\n\
";
auto outStr = streamRedirect.GetOutString();
EXPECT_TRUE(outStr.find(expected) != string::npos);
}

TEST_F(ProjMgrUnitTests, DeviceAttributes) {
const map<string, vector<string>> projects = {
{"fpu", {"+fpu-dp","+fpu-sp", "+no-fpu"}},
Expand Down
Loading