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
4 changes: 3 additions & 1 deletion tools/projmgr/include/ProjMgrWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ struct EnvironmentItem {
* list of components
* list of categories
* list of keywords
* pack identifier
*/
struct ExampleItem {
std::string name;
Expand All @@ -313,6 +314,7 @@ struct ExampleItem {
std::vector<std::string> components;
std::vector<std::string> categories;
std::vector<std::string> keywords;
std::string pack;
};

/**
Expand Down Expand Up @@ -1171,7 +1173,7 @@ class ProjMgrWorker {
bool ParseTargetSetContextSelection();
std::vector<ExampleItem> CollectExamples(ContextItem& context);
std::vector<RteBoard*> GetCompatibleBoards(ContextItem& context);
bool IsBoardListCompatible(const std::vector<RteBoard*> compatibleBoards, const Collection<RteItem*>& boards);
bool IsBoardListCompatible(const ContextItem& context, const std::vector<RteBoard*> compatibleBoards, const Collection<RteItem*>& boards);
std::vector<TemplateItem> CollectTemplates(ContextItem& context);
};

Expand Down
78 changes: 39 additions & 39 deletions tools/projmgr/src/ProjMgrWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4197,10 +4197,22 @@ vector<RteBoard*> ProjMgrWorker::GetCompatibleBoards(ContextItem& context) {
return compatibleBoards;
}

bool ProjMgrWorker::IsBoardListCompatible(const vector<RteBoard*> compatibleBoards, const Collection<RteItem*>& boards) {
if (boards.empty() || compatibleBoards.empty()) {
bool ProjMgrWorker::IsBoardListCompatible(const ContextItem& context, const vector<RteBoard*> compatibleBoards, const Collection<RteItem*>& boards) {
if (compatibleBoards.empty()) {
// no board/device is selected
return true;
}
if (boards.empty() && !context.board.empty()) {
// example without boards = reference application (hardware agnostic example)
// ref app requires at least a clayer type "board" for the selected board
const auto& clayers = context.rteFilteredModel->GetLayerDescriptors();
for (const auto& clayer : clayers) {
if (RteUtils::EqualNoCase(clayer->GetTypeString(), "board")) {
return true;
}
}
return false;
}
for (const auto& board : boards) {
for (const auto& compatibleBoard : compatibleBoards) {
if ((compatibleBoard->GetVendorString() == board->GetVendorString()) &&
Expand Down Expand Up @@ -4231,12 +4243,13 @@ std::vector<ExampleItem> ProjMgrWorker::CollectExamples(ContextItem& context) {
for (const auto& rteExample : rteExamples) {
Collection<RteItem*> boards;
boards = rteExample->GetChildrenByTag("board", boards);
if (!IsBoardListCompatible(compatibleBoards, boards)) {
if (!IsBoardListCompatible(context, compatibleBoards, boards)) {
continue;
}
ExampleItem example;
example.name = rteExample->GetName();
example.description = rteExample->GetChildText("description");
example.description = rteExample->GetDescription();
example.pack = rteExample->GetPackageID(true);
string folder = rteExample->GetFolderString();
RteFsUtils::NormalizePath(folder, rteExample->GetAbsolutePackagePath());
example.doc = rteExample->GetDocValue();
Expand Down Expand Up @@ -4306,44 +4319,31 @@ bool ProjMgrWorker::ListExamples(vector<string>& examples, const string& filter)
const auto& collectedExamples = CollectExamples(context);

for (const auto& exampleItem : collectedExamples) {
string example = exampleItem.name;
example += exampleItem.version.empty() ? "" : "@" + exampleItem.version;
example += "\n description: " + exampleItem.description;
example += "\n doc: " + exampleItem.doc;
if (!exampleItem.archive.empty()) {
example += "\n archive: " + exampleItem.archive;
}
for (const auto& [name, environment] : exampleItem.environments) {
example += "\n environment: " + name + "\n load: " + environment.load;
example += "\n folder: " + environment.folder;
}
if (!exampleItem.boards.empty()) {
example += "\n boards:";
for (const auto& board : exampleItem.boards) {
example += "\n " + board.vendor + "::" + board.name;
}
}
if (!exampleItem.components.empty()) {
example += "\n components:";
for (const auto& component : exampleItem.components) {
example += "\n " + component;
}
}
if (!exampleItem.categories.empty()) {
example += "\n categories:";
for (const auto& category : exampleItem.categories) {
example += "\n " + category;
}
if (!filter.empty() && exampleItem.name.find(filter) == string::npos) {
continue;
}
if (!exampleItem.keywords.empty()) {
example += "\n keywords:";
for (const auto& keyword : exampleItem.keywords) {
example += "\n " + keyword;
string example = exampleItem.boards.empty() ? "Reference Application: " : "";
example += exampleItem.name;
example += exampleItem.version.empty() ? "" : "@" + exampleItem.version;
example += " (" + exampleItem.pack + ")";
if (m_verbose) {
example += "\n description: " + exampleItem.description;
example += "\n doc: " + exampleItem.doc;
if (!exampleItem.archive.empty()) {
example += "\n archive: " + exampleItem.archive;
}
for (const auto& [name, environment] : exampleItem.environments) {
example += "\n environment: " + name + "\n load: " + environment.load;
example += "\n folder: " + environment.folder;
}
if (!exampleItem.boards.empty()) {
example += "\n boards:";
for (const auto& board : exampleItem.boards) {
example += "\n " + board.vendor + "::" + board.name;
}
}
}
if (filter.empty() || example.find(filter) != string::npos) {
examples.push_back(example);
}
examples.push_back(example);
}
return true;
}
Expand Down
63 changes: 34 additions & 29 deletions tools/projmgr/test/src/ProjMgrUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6900,61 +6900,66 @@ TEST_F(ProjMgrUnitTests, ListTargetSetsImageOnly) {
}

TEST_F(ProjMgrUnitTests, ListExamples) {
const string expected = "\
PreInclude@1.0.0\n\
char* argv[8];
StdStreamRedirect streamRedirect;
const string& csolution = testinput_folder + "/Examples/solution.csolution.yml";

// test with board
argv[1] = (char*)"list";
argv[2] = (char*)"examples";
argv[3] = (char*)csolution.c_str();
argv[4] = (char*)"--active";
argv[5] = (char*)"TestBoard";
EXPECT_EQ(0, RunProjMgr(6, argv, 0));
auto outStr = streamRedirect.GetOutString();
EXPECT_STREQ(outStr.c_str(), "\
PreInclude@1.0.0 (ARM::RteTest@0.1.0)\n\
PreIncludeEnvFolder@1.0.0 (ARM::RteTest@0.1.0)\n\
");

// test with verbose flag
streamRedirect.ClearStringStreams();
argv[6] = (char*)"--verbose";
EXPECT_EQ(0, RunProjMgr(7, argv, 0));
outStr = streamRedirect.GetOutString();
EXPECT_TRUE(regex_search(outStr, regex("\
PreInclude@1.0.0 \\(ARM::RteTest@0.1.0\\)\n\
description: PreInclude Test Application\n\
doc: .*/ARM/RteTest/0.1.0/Examples/PreInclude/Abstract.txt\n\
environment: uv\n\
load: .*/ARM/RteTest/0.1.0/Examples/PreInclude/PreInclude.uvprojx\n\
folder: .*/ARM/RteTest/0.1.0/Examples/PreInclude\n\
boards:\n\
Keil::RteTest Dummy board\n\
components:\n\
RteTest:GlobalLevel\n\
PreIncludeEnvFolder@1.0.0\n\
PreIncludeEnvFolder@1.0.0 \\(ARM::RteTest@0.1.0\\)\n\
description: PreInclude Test Application with different folder description\n\
doc: .*/ARM/RteTest/0.1.0/Examples/PreInclude/Abstract.txt\n\
environment: uv\n\
load: .*/ARM/RteTest/0.1.0/Examples/PreInclude.uvprojx\n\
folder: .*/ARM/RteTest/0.1.0/Examples/PreInclude\n\
boards:\n\
Keil::RteTest Dummy board\n\
components:\n\
RteTest:GlobalLevel\n\
categories:\n\
Example Project\n\
keywords:\n\
Getting Started\n\
";
char* argv[8];
StdStreamRedirect streamRedirect;
const string& csolution = testinput_folder + "/Examples/solution.csolution.yml";

// test with board
argv[1] = (char*)"list";
argv[2] = (char*)"examples";
argv[3] = (char*)csolution.c_str();
argv[4] = (char*)"--active";
argv[5] = (char*)"TestBoard";
EXPECT_EQ(0, RunProjMgr(6, argv, 0));
auto outStr = streamRedirect.GetOutString();
EXPECT_TRUE(regex_search(outStr, regex(expected)));
")));

// test with compatible device
streamRedirect.ClearStringStreams();
argv[5] = (char*)"CM0_Dual";
EXPECT_EQ(0, RunProjMgr(6, argv, 0));
outStr = streamRedirect.GetOutString();
EXPECT_TRUE(regex_search(outStr, regex(expected)));
EXPECT_STREQ(outStr.c_str(), "\
PreInclude@1.0.0 (ARM::RteTest@0.1.0)\n\
PreIncludeEnvFolder@1.0.0 (ARM::RteTest@0.1.0)\n\
");

// test with filter option
streamRedirect.ClearStringStreams();
argv[6] = (char*)"--filter";
argv[7] = (char*)"Getting Started";
argv[7] = (char*)"EnvFolder";
EXPECT_EQ(0, RunProjMgr(8, argv, 0));
outStr = streamRedirect.GetOutString();
EXPECT_TRUE(outStr.find("PreIncludeEnvFolder@1.0.0") != string::npos);
EXPECT_TRUE(outStr.find("PreInclude@1.0.0") == string::npos);
EXPECT_STREQ(outStr.c_str(), "\
PreIncludeEnvFolder@1.0.0 (ARM::RteTest@0.1.0)\n\
");

// test with non-compatible device
streamRedirect.ClearStringStreams();
Expand Down
Loading