diff --git a/test/packs/ARM/RteTest_DFP/0.2.0/ARM.RteTest_DFP.pdsc b/test/packs/ARM/RteTest_DFP/0.2.0/ARM.RteTest_DFP.pdsc
index 3e9fef067..0aff72afe 100644
--- a/test/packs/ARM/RteTest_DFP/0.2.0/ARM.RteTest_DFP.pdsc
+++ b/test/packs/ARM/RteTest_DFP/0.2.0/ARM.RteTest_DFP.pdsc
@@ -567,7 +567,7 @@
"Test board Template two"
-
+
"Test board Template three"
diff --git a/tools/projmgr/include/ProjMgr.h b/tools/projmgr/include/ProjMgr.h
index 55da713ab..bd32f7cda 100644
--- a/tools/projmgr/include/ProjMgr.h
+++ b/tools/projmgr/include/ProjMgr.h
@@ -193,6 +193,7 @@ class ProjMgr {
bool RunListConfigs();
bool RunListDependencies();
bool RunListExamples();
+ bool RunListTemplates();
bool RunListContexts();
bool RunListTargetSets();
bool RunListGenerators();
diff --git a/tools/projmgr/include/ProjMgrWorker.h b/tools/projmgr/include/ProjMgrWorker.h
index cd3da7fcb..d0fab98d7 100644
--- a/tools/projmgr/include/ProjMgrWorker.h
+++ b/tools/projmgr/include/ProjMgrWorker.h
@@ -315,6 +315,24 @@ struct ExampleItem {
std::vector 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
@@ -589,6 +607,14 @@ class ProjMgrWorker {
*/
bool ListExamples(std::vector& 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& templates, const std::string& filter = RteUtils::EMPTY_STRING);
+
/**
* @brief list contexts
* @param reference to list of contexts
@@ -1146,6 +1172,7 @@ class ProjMgrWorker {
std::vector CollectExamples(ContextItem& context);
std::vector GetCompatibleBoards(ContextItem& context);
bool IsBoardListCompatible(const std::vector compatibleBoards, const Collection& boards);
+ std::vector CollectTemplates(ContextItem& context);
};
#endif // PROJMGRWORKER_H
diff --git a/tools/projmgr/src/ProjMgr.cpp b/tools/projmgr/src/ProjMgr.cpp
index 1105fb7ee..04c055016 100644
--- a/tools/projmgr/src/ProjMgr.cpp
+++ b/tools/projmgr/src/ProjMgr.cpp
@@ -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\
@@ -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}}},
@@ -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;
@@ -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 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()) {
diff --git a/tools/projmgr/src/ProjMgrWorker.cpp b/tools/projmgr/src/ProjMgrWorker.cpp
index e760d6532..50ad8f0af 100644
--- a/tools/projmgr/src/ProjMgrWorker.cpp
+++ b/tools/projmgr/src/ProjMgrWorker.cpp
@@ -4348,6 +4348,57 @@ bool ProjMgrWorker::ListExamples(vector& examples, const string& filter)
return true;
}
+std::vector ProjMgrWorker::CollectTemplates(ContextItem& context) {
+ std::vector 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& 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& results, const ContextItem& context) {
for (const auto& validation : context.validationResults) {
string resultStr = RteItem::ConditionResultToString(validation.result) + " " + validation.id;
diff --git a/tools/projmgr/test/src/ProjMgrUnitTests.cpp b/tools/projmgr/test/src/ProjMgrUnitTests.cpp
index 0a1c7dc90..4647567b3 100644
--- a/tools/projmgr/test/src/ProjMgrUnitTests.cpp
+++ b/tools/projmgr/test/src/ProjMgrUnitTests.cpp
@@ -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;