From 0264b5bf9bb03511652fee3c8852902541855831 Mon Sep 17 00:00:00 2001 From: Daniel Brondani Date: Thu, 21 Aug 2025 16:24:45 +0200 Subject: [PATCH] [projmgr] Extend filtering when listing templates and examples --- tools/projmgr/include/ProjMgrWorker.h | 5 ++++- tools/projmgr/src/ProjMgrWorker.cpp | 22 +++++++++++++++++-- tools/projmgr/test/src/ProjMgrUnitTests.cpp | 24 ++++++++++++++++++++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/tools/projmgr/include/ProjMgrWorker.h b/tools/projmgr/include/ProjMgrWorker.h index 28ad6ce8b..97792de9d 100644 --- a/tools/projmgr/include/ProjMgrWorker.h +++ b/tools/projmgr/include/ProjMgrWorker.h @@ -327,12 +327,13 @@ struct ExampleItem { /** * @brief template item containing - * name of example + * name of template * description * path to the directory that contains the template * path to the *.csolution.yml file * path to copy the template into * pack identifier + * placeholder symmetric to ExampleItem for reusable template */ struct TemplateItem { std::string name; @@ -341,6 +342,7 @@ struct TemplateItem { std::string file; std::string copyTo; std::string pack; + std::vector boards; }; /** @@ -1212,6 +1214,7 @@ class ProjMgrWorker { bool IsBoardListCompatible(const ContextItem& context, const std::vector compatibleBoards, const Collection& boards); bool IsEnvironmentCompatible(const std::string& environment, const StrVec& filter); bool HasCompatibleEnvironment(const Collection& environments, const StrVec& filter); + template bool CheckFilter(const std::string& filter, const T& item); }; #endif // PROJMGRWORKER_H diff --git a/tools/projmgr/src/ProjMgrWorker.cpp b/tools/projmgr/src/ProjMgrWorker.cpp index 0389caf17..7035bfdf7 100644 --- a/tools/projmgr/src/ProjMgrWorker.cpp +++ b/tools/projmgr/src/ProjMgrWorker.cpp @@ -4313,6 +4313,24 @@ std::vector ProjMgrWorker::CollectExamples(const ContextItem& conte return examples; } +template bool ProjMgrWorker::CheckFilter(const std::string& filter, const T& item) { + const bool nameFound = item.name.find(filter) != string::npos; + const bool packFound = item.pack.find(filter) != string::npos; + const bool descriptionFound = m_verbose ? item.description.find(filter) != string::npos : false; + bool boardFound = false; + if (m_verbose) { + for (const auto& board : item.boards) { + if (board.vendor.find(filter) != std::string::npos || + board.name.find(filter) != std::string::npos || + board.revision.find(filter) != std::string::npos) { + boardFound = true; + break; + } + } + } + return nameFound || packFound || descriptionFound || boardFound; +} + bool ProjMgrWorker::ListExamples(vector& examples, const string& filter) { const auto& selectedContext = m_selectedContexts.front(); ContextItem& context = m_contexts[selectedContext]; @@ -4331,7 +4349,7 @@ bool ProjMgrWorker::ListExamples(vector& examples, const string& filter) const auto& collectedExamples = CollectExamples(context, StrVec()); for (const auto& exampleItem : collectedExamples) { - if (!filter.empty() && exampleItem.name.find(filter) == string::npos) { + if (!filter.empty() && !CheckFilter(filter, exampleItem)) { continue; } string example = exampleItem.boards.empty() ? "Reference Application: " : ""; @@ -4394,7 +4412,7 @@ bool ProjMgrWorker::ListTemplates(vector& templates, const string& filte } const auto& collectedTemplates = CollectTemplates(context); for (const auto& templateItem : collectedTemplates) { - if (!filter.empty() && templateItem.name.find(filter) == string::npos) { + if (!filter.empty() && !CheckFilter(filter, templateItem)) { continue; } string templateStr = templateItem.name + " (" + templateItem.pack + ")"; diff --git a/tools/projmgr/test/src/ProjMgrUnitTests.cpp b/tools/projmgr/test/src/ProjMgrUnitTests.cpp index 69faa6988..4cd5db0ab 100644 --- a/tools/projmgr/test/src/ProjMgrUnitTests.cpp +++ b/tools/projmgr/test/src/ProjMgrUnitTests.cpp @@ -6879,7 +6879,7 @@ TEST_F(ProjMgrUnitTests, ListTargetSetsImageOnly) { } TEST_F(ProjMgrUnitTests, ListExamples) { - char* argv[8]; + char* argv[9]; StdStreamRedirect streamRedirect; const string& csolution = testinput_folder + "/Examples/solution.csolution.yml"; @@ -6940,6 +6940,17 @@ PreIncludeEnvFolder@1.0.0 (ARM::RteTest@0.1.0)\n\ PreIncludeEnvFolder@1.0.0 (ARM::RteTest@0.1.0)\n\ "); + // test with filter option (description) + streamRedirect.ClearStringStreams(); + argv[7] = (char*)"different folder description"; + argv[8] = (char*)"--verbose"; + EXPECT_EQ(0, RunProjMgr(9, argv, 0)); + outStr = streamRedirect.GetOutString(); + EXPECT_TRUE(regex_search(outStr, regex("\ +PreIncludeEnvFolder@1.0.0 \\(ARM::RteTest@0.1.0\\)\n\ + description: PreInclude Test Application with different folder description\n\ +"))); + // test with non-compatible device streamRedirect.ClearStringStreams(); argv[5] = (char*)"CM0"; @@ -6974,6 +6985,17 @@ Board3 (ARM::RteTest_DFP@0.2.0)\n\ Board1Template (ARM::RteTest_DFP@0.2.0)\n\ "); + // test filter (description) + argv[4] = (char*)"Template one"; + argv[5] = (char*)"--verbose"; + streamRedirect.ClearStringStreams(); + EXPECT_EQ(0, RunProjMgr(6, argv, 0)); + outStr = streamRedirect.GetOutString(); + EXPECT_TRUE(regex_search(outStr, regex("\ +Board1Template \\(ARM::RteTest_DFP@0.2.0\\)\n\ + description: \"Test board Template one\"\n\ +"))); + // list board's compatible template const string& csolution = testinput_folder + "/Examples/solution.csolution.yml"; const string expected =