Skip to content
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
2 changes: 1 addition & 1 deletion test/packs/ARM/RteTest_DFP/0.2.0/ARM.RteTest_DFP.pdsc
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@
<template name="Board2" type="Board" file="Templates/board2.csolution.yml" condition="BoardTest2">
<description>"Test board Template two"</description>
</template>
<template name="Board3" type="Board" file="Templates/board3.csolution.yml" condition="BoardTest3">
<template name="Board3" type="Board" path="Templates" file="board3.csolution.yml" copy-to="Template3" condition="BoardTest3">
<description>"Test board Template three"</description>
</template>
<clayer name="TestVariant" type="TestVariant" file="Layers/testvariant.clayer.yml">
Expand Down
1 change: 1 addition & 0 deletions tools/projmgr/include/ProjMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class ProjMgr {
bool RunListConfigs();
bool RunListDependencies();
bool RunListExamples();
bool RunListTemplates();
bool RunListContexts();
bool RunListTargetSets();
bool RunListGenerators();
Expand Down
27 changes: 27 additions & 0 deletions tools/projmgr/include/ProjMgrWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,24 @@ struct ExampleItem {
std::vector<std::string> keywords;
};

/**
* @brief template item containing
* name of example
* description
* path to the directory that contains the template
* path to the *.csolution.yml file
* path to copy the template into
* pack identifier
*/
struct TemplateItem {
std::string name;
std::string description;
std::string path;
std::string file;
std::string copyTo;
std::string pack;
};

/**
* @brief debugger type
* name of debug configuration
Expand Down Expand Up @@ -589,6 +607,14 @@ class ProjMgrWorker {
*/
bool ListExamples(std::vector<std::string>& examples, const std::string& filter = RteUtils::EMPTY_STRING);

/**
* @brief list available csolution templates
* @param reference to list of csolution templates
* @param filter words to filter results
* @return true if executed successfully
*/
bool ListTemplates(std::vector<std::string>& templates, const std::string& filter = RteUtils::EMPTY_STRING);

/**
* @brief list contexts
* @param reference to list of contexts
Expand Down Expand Up @@ -1146,6 +1172,7 @@ class ProjMgrWorker {
std::vector<ExampleItem> CollectExamples(ContextItem& context);
std::vector<RteBoard*> GetCompatibleBoards(ContextItem& context);
bool IsBoardListCompatible(const std::vector<RteBoard*> compatibleBoards, const Collection<RteItem*>& boards);
std::vector<TemplateItem> CollectTemplates(ContextItem& context);
};

#endif // PROJMGRWORKER_H
31 changes: 31 additions & 0 deletions tools/projmgr/src/ProjMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Commands:\n\
list devices Print list of available device names\n\
list environment Print list of environment configurations\n\
list examples Print list of examples\n\
list templates Print list of templates\n\
list generators Print list of code generators of a given context\n\
list layers Print list of available, referenced and compatible layers\n\
list packs Print list of used packs from the pack repository\n\
Expand Down Expand Up @@ -183,6 +184,7 @@ int ProjMgr::ParseCommandLine(int argc, char** argv) {
{"list components", { true, {context, contextSet, activeTargetSet, debug, filter, load, quiet, schemaCheck, toolchain, verbose}}},
{"list dependencies", { false, {context, contextSet, activeTargetSet, debug, filter, load, quiet, schemaCheck, toolchain, verbose}}},
{"list examples", { false, {context, contextSet, activeTargetSet, debug, filter, load, quiet, schemaCheck, toolchain, verbose}}},
{"list templates", { false, {context, contextSet, activeTargetSet, debug, filter, load, quiet, schemaCheck, toolchain, verbose}}},
{"list contexts", { false, {debug, filter, quiet, schemaCheck, verbose, ymlOrder}}},
{"list target-sets", { false, {debug, filter, quiet, schemaCheck, verbose}}},
{"list generators", { false, {context, contextSet, activeTargetSet, debug, load, quiet, schemaCheck, toolchain, verbose}}},
Expand Down Expand Up @@ -376,6 +378,10 @@ int ProjMgr::ProcessCommands() {
if (!RunListExamples()) {
return ErrorCode::ERROR;
}
} else if (m_args == "templates") {
if (!RunListTemplates()) {
return ErrorCode::ERROR;
}
} else if (m_args == "contexts") {
if (!RunListContexts()) {
return ErrorCode::ERROR;
Expand Down Expand Up @@ -938,6 +944,31 @@ bool ProjMgr::RunListExamples(void) {
return true;
}

bool ProjMgr::RunListTemplates(void) {
if (!m_csolutionFile.empty()) {
// Parse all input files and create contexts
if (!PopulateContexts()) {
return false;
}
}

// Parse context selection
if (!ParseAndValidateContexts()) {
return false;
}

vector<string> csolutionTemplates;
if (!m_worker.ListTemplates(csolutionTemplates, m_filter)) {
ProjMgrLogger::Get().Error("processing templates list failed");
return false;
}

for (const auto& csolutionTemplate : csolutionTemplates) {
ProjMgrLogger::out() << csolutionTemplate << endl;
}
return true;
}

bool ProjMgr::RunListContexts(void) {
// Parse all input files and create contexts
if (!PopulateContexts()) {
Expand Down
51 changes: 51 additions & 0 deletions tools/projmgr/src/ProjMgrWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4348,6 +4348,57 @@ bool ProjMgrWorker::ListExamples(vector<string>& examples, const string& filter)
return true;
}

std::vector<TemplateItem> ProjMgrWorker::CollectTemplates(ContextItem& context) {
std::vector<TemplateItem> templates;
const auto& rteTemplates = context.rteFilteredModel->GetProjectDescriptors();
for (const auto& rteTemplate : rteTemplates) {
TemplateItem csolutionTemplate;
csolutionTemplate.name = rteTemplate->GetName();
csolutionTemplate.description = rteTemplate->GetDescription();
csolutionTemplate.pack = rteTemplate->GetPackageID(true);
csolutionTemplate.path = rteTemplate->GetPathString();
RteFsUtils::NormalizePath(csolutionTemplate.path, rteTemplate->GetAbsolutePackagePath());
csolutionTemplate.file = rteTemplate->GetFileString();
RteFsUtils::NormalizePath(csolutionTemplate.file, csolutionTemplate.path);
csolutionTemplate.copyTo = rteTemplate->GetCopyToString();
templates.push_back(csolutionTemplate);
}
return templates;
}

bool ProjMgrWorker::ListTemplates(vector<string>& templates, const string& filter) {
const auto& selectedContext = m_selectedContexts.front();
ContextItem& context = m_contexts[selectedContext];
if (!LoadPacks(context)) {
return false;
}
if (!selectedContext.empty()) {
if (!ProcessPrecedences(context, BoardOrDevice::Both)) {
return false;
}
}
if (!SetTargetAttributes(context, context.targetAttributes)) {
return false;
}
const auto& collectedTemplates = CollectTemplates(context);
for (const auto& templateItem : collectedTemplates) {
if (!filter.empty() && templateItem.name.find(filter) == string::npos) {
continue;
}
string templateStr = templateItem.name + " (" + templateItem.pack + ")";
if (m_verbose) {
templateStr += "\n description: " + templateItem.description;
templateStr += "\n path: " + templateItem.path;
templateStr += "\n file: " + templateItem.file;
if (!templateItem.copyTo.empty()) {
templateStr += "\n copy-to: " + templateItem.copyTo;
}
}
templates.push_back(templateStr);
}
return true;
}

bool ProjMgrWorker::FormatValidationResults(set<string>& results, const ContextItem& context) {
for (const auto& validation : context.validationResults) {
string resultStr = RteItem::ConditionResultToString(validation.result) + " " + validation.id;
Expand Down
45 changes: 45 additions & 0 deletions tools/projmgr/test/src/ProjMgrUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6964,6 +6964,51 @@ PreIncludeEnvFolder@1.0.0\n\
EXPECT_TRUE(outStr.empty());
}


TEST_F(ProjMgrUnitTests, ListTemplates) {
char* argv[7];
StdStreamRedirect streamRedirect;

// list all templates
argv[1] = (char*)"list";
argv[2] = (char*)"templates";
EXPECT_EQ(0, RunProjMgr(3, argv, 0));
auto outStr = streamRedirect.GetOutString();
EXPECT_STREQ(outStr.c_str(), "\
Board1Template (ARM::RteTest_DFP@0.2.0)\n\
Board2 (ARM::RteTest_DFP@0.2.0)\n\
Board3 (ARM::RteTest_DFP@0.2.0)\n\
");

// test filter
argv[3] = (char*)"--filter";
argv[4] = (char*)"Board1";
streamRedirect.ClearStringStreams();
EXPECT_EQ(0, RunProjMgr(5, argv, 0));
outStr = streamRedirect.GetOutString();
EXPECT_STREQ(outStr.c_str(), "\
Board1Template (ARM::RteTest_DFP@0.2.0)\n\
");

// list board's compatible template
const string& csolution = testinput_folder + "/Examples/solution.csolution.yml";
const string expected =
argv[3] = (char*)csolution.c_str();
argv[4] = (char*)"--active";
argv[5] = (char*)"TestBoard";
argv[6] = (char*)"--verbose";
streamRedirect.ClearStringStreams();
EXPECT_EQ(0, RunProjMgr(7, argv, 0));
outStr = streamRedirect.GetOutString();
EXPECT_TRUE(regex_search(outStr, regex("\
Board3 \\(ARM::RteTest_DFP@0.2.0\\)\n\
description: \"Test board Template three\"\n\
path: .*/ARM/RteTest_DFP/0.2.0/Templates\n\
file: .*/ARM/RteTest_DFP/0.2.0/Templates/board3.csolution.yml\n\
copy-to: Template3\n\
")));
}

TEST_F(ProjMgrUnitTests, ConvertActiveTargetSet) {
char* argv[6];
StdStreamRedirect streamRedirect;
Expand Down
Loading