Skip to content

Commit a17de20

Browse files
authored
[projmgr] Update list examples command
1 parent bdd4786 commit a17de20

File tree

3 files changed

+76
-69
lines changed

3 files changed

+76
-69
lines changed

tools/projmgr/include/ProjMgrWorker.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ struct EnvironmentItem {
301301
* list of components
302302
* list of categories
303303
* list of keywords
304+
* pack identifier
304305
*/
305306
struct ExampleItem {
306307
std::string name;
@@ -313,6 +314,7 @@ struct ExampleItem {
313314
std::vector<std::string> components;
314315
std::vector<std::string> categories;
315316
std::vector<std::string> keywords;
317+
std::string pack;
316318
};
317319

318320
/**
@@ -1171,7 +1173,7 @@ class ProjMgrWorker {
11711173
bool ParseTargetSetContextSelection();
11721174
std::vector<ExampleItem> CollectExamples(ContextItem& context);
11731175
std::vector<RteBoard*> GetCompatibleBoards(ContextItem& context);
1174-
bool IsBoardListCompatible(const std::vector<RteBoard*> compatibleBoards, const Collection<RteItem*>& boards);
1176+
bool IsBoardListCompatible(const ContextItem& context, const std::vector<RteBoard*> compatibleBoards, const Collection<RteItem*>& boards);
11751177
std::vector<TemplateItem> CollectTemplates(ContextItem& context);
11761178
};
11771179

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4197,10 +4197,22 @@ vector<RteBoard*> ProjMgrWorker::GetCompatibleBoards(ContextItem& context) {
41974197
return compatibleBoards;
41984198
}
41994199

4200-
bool ProjMgrWorker::IsBoardListCompatible(const vector<RteBoard*> compatibleBoards, const Collection<RteItem*>& boards) {
4201-
if (boards.empty() || compatibleBoards.empty()) {
4200+
bool ProjMgrWorker::IsBoardListCompatible(const ContextItem& context, const vector<RteBoard*> compatibleBoards, const Collection<RteItem*>& boards) {
4201+
if (compatibleBoards.empty()) {
4202+
// no board/device is selected
42024203
return true;
42034204
}
4205+
if (boards.empty() && !context.board.empty()) {
4206+
// example without boards = reference application (hardware agnostic example)
4207+
// ref app requires at least a clayer type "board" for the selected board
4208+
const auto& clayers = context.rteFilteredModel->GetLayerDescriptors();
4209+
for (const auto& clayer : clayers) {
4210+
if (RteUtils::EqualNoCase(clayer->GetTypeString(), "board")) {
4211+
return true;
4212+
}
4213+
}
4214+
return false;
4215+
}
42044216
for (const auto& board : boards) {
42054217
for (const auto& compatibleBoard : compatibleBoards) {
42064218
if ((compatibleBoard->GetVendorString() == board->GetVendorString()) &&
@@ -4231,12 +4243,13 @@ std::vector<ExampleItem> ProjMgrWorker::CollectExamples(ContextItem& context) {
42314243
for (const auto& rteExample : rteExamples) {
42324244
Collection<RteItem*> boards;
42334245
boards = rteExample->GetChildrenByTag("board", boards);
4234-
if (!IsBoardListCompatible(compatibleBoards, boards)) {
4246+
if (!IsBoardListCompatible(context, compatibleBoards, boards)) {
42354247
continue;
42364248
}
42374249
ExampleItem example;
42384250
example.name = rteExample->GetName();
4239-
example.description = rteExample->GetChildText("description");
4251+
example.description = rteExample->GetDescription();
4252+
example.pack = rteExample->GetPackageID(true);
42404253
string folder = rteExample->GetFolderString();
42414254
RteFsUtils::NormalizePath(folder, rteExample->GetAbsolutePackagePath());
42424255
example.doc = rteExample->GetDocValue();
@@ -4306,44 +4319,31 @@ bool ProjMgrWorker::ListExamples(vector<string>& examples, const string& filter)
43064319
const auto& collectedExamples = CollectExamples(context);
43074320

43084321
for (const auto& exampleItem : collectedExamples) {
4309-
string example = exampleItem.name;
4310-
example += exampleItem.version.empty() ? "" : "@" + exampleItem.version;
4311-
example += "\n description: " + exampleItem.description;
4312-
example += "\n doc: " + exampleItem.doc;
4313-
if (!exampleItem.archive.empty()) {
4314-
example += "\n archive: " + exampleItem.archive;
4315-
}
4316-
for (const auto& [name, environment] : exampleItem.environments) {
4317-
example += "\n environment: " + name + "\n load: " + environment.load;
4318-
example += "\n folder: " + environment.folder;
4319-
}
4320-
if (!exampleItem.boards.empty()) {
4321-
example += "\n boards:";
4322-
for (const auto& board : exampleItem.boards) {
4323-
example += "\n " + board.vendor + "::" + board.name;
4324-
}
4325-
}
4326-
if (!exampleItem.components.empty()) {
4327-
example += "\n components:";
4328-
for (const auto& component : exampleItem.components) {
4329-
example += "\n " + component;
4330-
}
4331-
}
4332-
if (!exampleItem.categories.empty()) {
4333-
example += "\n categories:";
4334-
for (const auto& category : exampleItem.categories) {
4335-
example += "\n " + category;
4336-
}
4322+
if (!filter.empty() && exampleItem.name.find(filter) == string::npos) {
4323+
continue;
43374324
}
4338-
if (!exampleItem.keywords.empty()) {
4339-
example += "\n keywords:";
4340-
for (const auto& keyword : exampleItem.keywords) {
4341-
example += "\n " + keyword;
4325+
string example = exampleItem.boards.empty() ? "Reference Application: " : "";
4326+
example += exampleItem.name;
4327+
example += exampleItem.version.empty() ? "" : "@" + exampleItem.version;
4328+
example += " (" + exampleItem.pack + ")";
4329+
if (m_verbose) {
4330+
example += "\n description: " + exampleItem.description;
4331+
example += "\n doc: " + exampleItem.doc;
4332+
if (!exampleItem.archive.empty()) {
4333+
example += "\n archive: " + exampleItem.archive;
4334+
}
4335+
for (const auto& [name, environment] : exampleItem.environments) {
4336+
example += "\n environment: " + name + "\n load: " + environment.load;
4337+
example += "\n folder: " + environment.folder;
4338+
}
4339+
if (!exampleItem.boards.empty()) {
4340+
example += "\n boards:";
4341+
for (const auto& board : exampleItem.boards) {
4342+
example += "\n " + board.vendor + "::" + board.name;
4343+
}
43424344
}
43434345
}
4344-
if (filter.empty() || example.find(filter) != string::npos) {
4345-
examples.push_back(example);
4346-
}
4346+
examples.push_back(example);
43474347
}
43484348
return true;
43494349
}

tools/projmgr/test/src/ProjMgrUnitTests.cpp

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6900,61 +6900,66 @@ TEST_F(ProjMgrUnitTests, ListTargetSetsImageOnly) {
69006900
}
69016901

69026902
TEST_F(ProjMgrUnitTests, ListExamples) {
6903-
const string expected = "\
6904-
6903+
char* argv[8];
6904+
StdStreamRedirect streamRedirect;
6905+
const string& csolution = testinput_folder + "/Examples/solution.csolution.yml";
6906+
6907+
// test with board
6908+
argv[1] = (char*)"list";
6909+
argv[2] = (char*)"examples";
6910+
argv[3] = (char*)csolution.c_str();
6911+
argv[4] = (char*)"--active";
6912+
argv[5] = (char*)"TestBoard";
6913+
EXPECT_EQ(0, RunProjMgr(6, argv, 0));
6914+
auto outStr = streamRedirect.GetOutString();
6915+
EXPECT_STREQ(outStr.c_str(), "\
6916+
6917+
6918+
");
6919+
6920+
// test with verbose flag
6921+
streamRedirect.ClearStringStreams();
6922+
argv[6] = (char*)"--verbose";
6923+
EXPECT_EQ(0, RunProjMgr(7, argv, 0));
6924+
outStr = streamRedirect.GetOutString();
6925+
EXPECT_TRUE(regex_search(outStr, regex("\
6926+
69056927
description: PreInclude Test Application\n\
69066928
doc: .*/ARM/RteTest/0.1.0/Examples/PreInclude/Abstract.txt\n\
69076929
environment: uv\n\
69086930
load: .*/ARM/RteTest/0.1.0/Examples/PreInclude/PreInclude.uvprojx\n\
69096931
folder: .*/ARM/RteTest/0.1.0/Examples/PreInclude\n\
69106932
boards:\n\
69116933
Keil::RteTest Dummy board\n\
6912-
components:\n\
6913-
RteTest:GlobalLevel\n\
6914-
6934+
69156935
description: PreInclude Test Application with different folder description\n\
69166936
doc: .*/ARM/RteTest/0.1.0/Examples/PreInclude/Abstract.txt\n\
69176937
environment: uv\n\
69186938
load: .*/ARM/RteTest/0.1.0/Examples/PreInclude.uvprojx\n\
69196939
folder: .*/ARM/RteTest/0.1.0/Examples/PreInclude\n\
69206940
boards:\n\
69216941
Keil::RteTest Dummy board\n\
6922-
components:\n\
6923-
RteTest:GlobalLevel\n\
6924-
categories:\n\
6925-
Example Project\n\
6926-
keywords:\n\
6927-
Getting Started\n\
6928-
";
6929-
char* argv[8];
6930-
StdStreamRedirect streamRedirect;
6931-
const string& csolution = testinput_folder + "/Examples/solution.csolution.yml";
6932-
6933-
// test with board
6934-
argv[1] = (char*)"list";
6935-
argv[2] = (char*)"examples";
6936-
argv[3] = (char*)csolution.c_str();
6937-
argv[4] = (char*)"--active";
6938-
argv[5] = (char*)"TestBoard";
6939-
EXPECT_EQ(0, RunProjMgr(6, argv, 0));
6940-
auto outStr = streamRedirect.GetOutString();
6941-
EXPECT_TRUE(regex_search(outStr, regex(expected)));
6942+
")));
69426943

69436944
// test with compatible device
69446945
streamRedirect.ClearStringStreams();
69456946
argv[5] = (char*)"CM0_Dual";
69466947
EXPECT_EQ(0, RunProjMgr(6, argv, 0));
69476948
outStr = streamRedirect.GetOutString();
6948-
EXPECT_TRUE(regex_search(outStr, regex(expected)));
6949+
EXPECT_STREQ(outStr.c_str(), "\
6950+
6951+
6952+
");
69496953

69506954
// test with filter option
69516955
streamRedirect.ClearStringStreams();
69526956
argv[6] = (char*)"--filter";
6953-
argv[7] = (char*)"Getting Started";
6957+
argv[7] = (char*)"EnvFolder";
69546958
EXPECT_EQ(0, RunProjMgr(8, argv, 0));
69556959
outStr = streamRedirect.GetOutString();
6956-
EXPECT_TRUE(outStr.find("[email protected]") != string::npos);
6957-
EXPECT_TRUE(outStr.find("[email protected]") == string::npos);
6960+
EXPECT_STREQ(outStr.c_str(), "\
6961+
6962+
");
69586963

69596964
// test with non-compatible device
69606965
streamRedirect.ClearStringStreams();

0 commit comments

Comments
 (0)