Skip to content

Commit

Permalink
[projmgr] Update load packs policy handling
Browse files Browse the repository at this point in the history
  • Loading branch information
grasci-arm authored Jun 6, 2023
1 parent 0d0c96c commit 29c0da7
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 15 deletions.
1 change: 1 addition & 0 deletions tools/projmgr/include/ProjMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class ProjMgr {
bool RunListToolchains(void);
bool RunListEnvironment(void);
bool PopulateContexts(void);
bool SetLoadPacksPolicy(void);
};

#endif // PROJMGR_H
38 changes: 23 additions & 15 deletions tools/projmgr/src/ProjMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ int ProjMgr::RunProjMgr(int argc, char **argv, char** envp) {
return manager.PrintUsage(optionsDict, manager.m_command, manager.m_args) ? 0 : 1;
}

// Set load packs policy
if (!manager.SetLoadPacksPolicy()) {
return 1;
}

// Environment variables
vector<string> envVars;
if (envp) {
Expand Down Expand Up @@ -319,6 +324,23 @@ int ProjMgr::RunProjMgr(int argc, char **argv, char** envp) {
return 0;
}

// Set load packs policy
bool ProjMgr::SetLoadPacksPolicy(void) {
if (m_loadPacksPolicy.empty()) {
m_worker.SetLoadPacksPolicy(LoadPacksPolicy::DEFAULT);
} else if (m_loadPacksPolicy == "latest") {
m_worker.SetLoadPacksPolicy(LoadPacksPolicy::LATEST);
} else if (m_loadPacksPolicy == "all") {
m_worker.SetLoadPacksPolicy(LoadPacksPolicy::ALL);
} else if (m_loadPacksPolicy == "required") {
m_worker.SetLoadPacksPolicy(LoadPacksPolicy::REQUIRED);
} else {
ProjMgrLogger::Error("unknown load option: '" + m_loadPacksPolicy + "', it must be 'latest', 'all' or 'required'");
return false;
}
return true;
}

bool ProjMgr::PopulateContexts(void) {
if (!m_csolutionFile.empty()) {
// Parse csolution
Expand Down Expand Up @@ -360,26 +382,12 @@ bool ProjMgr::PopulateContexts(void) {
return false;
}

// Set output directory
// Set toolchain
m_worker.SetSelectedToolchain(m_selectedToolchain);

// Set output directory
m_worker.SetOutputDir(m_outputDir);

// Set load packs policy
if (m_loadPacksPolicy.empty()) {
m_worker.SetLoadPacksPolicy(LoadPacksPolicy::DEFAULT);
} else if (m_loadPacksPolicy == "latest") {
m_worker.SetLoadPacksPolicy(LoadPacksPolicy::LATEST);
} else if (m_loadPacksPolicy == "all") {
m_worker.SetLoadPacksPolicy(LoadPacksPolicy::ALL);
} else if (m_loadPacksPolicy == "required") {
m_worker.SetLoadPacksPolicy(LoadPacksPolicy::REQUIRED);
} else {
ProjMgrLogger::Error("unknown load option: '" + m_loadPacksPolicy + "', it must be 'latest', 'all' or 'required'");
return false;
}

// Add contexts
for (auto& descriptor : m_parser.GetCsolution().contexts) {
error_code ec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ solution:

packs:
- pack: ARM
for-context: .Debug
- pack: ARM::*DFP
for-context: .Release

projects:
- project: ./TestProject1/test1.cproject.yml
Expand Down
27 changes: 27 additions & 0 deletions tools/projmgr/test/src/ProjMgrUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,16 @@ TEST_F(ProjMgrUnitTests, RunProjMgr_ListPacks) {
map<std::pair<string, string>, string> testInputs = {
{{"TestSolution/test.csolution.yml", "test1.Debug+CM0"},
"ARM::RteTest_DFP@0.2.0 \\(.*\\)\n" },
// packs are specified only with vendor
{{"TestSolution/test.csolution_filtered_pack_selection.yml", "test1.Debug+CM0"},
"ARM::RteTest@0.1.0 \\(.*\\)\nARM::RteTestBoard@0.1.0 \\(.*\\)\nARM::RteTestGenerator@0.1.0 \\(.*\\)\nARM::RteTest_DFP@0.2.0 \\(.*\\)\n"},
// packs are specified with wildcards
{{"TestSolution/test.csolution_filtered_pack_selection.yml", "test1.Release+CM0"},
"ARM::RteTest_DFP@0.2.0 \\(.*\\)\n"},
// packs are not specified
{{"TestSolution/test.csolution_no_packs.yml", "test1.Debug+CM0"},
"ARM::RteTest@0.1.0 \\(.*\\)\nARM::RteTestBoard@0.1.0 \\(.*\\)\nARM::RteTestGenerator@0.1.0 \\(.*\\)\nARM::RteTest_DFP@0.2.0 \\(.*\\)\n"},
// packs are fully specified
{{"TestSolution/test.csolution_pack_selection.yml", "test2.Debug+CM0"},
"ARM::RteTest_DFP@0.2.0 \\(.*\\)\n"}
};
Expand Down Expand Up @@ -213,6 +219,27 @@ ARM::RteTest_DFP@0.2.0 \\(.*\\)\n\
EXPECT_TRUE(regex_match(outStr, regex(expectedAll)));
}

TEST_F(ProjMgrUnitTests, RunProjMgr_ListPacksAll) {
char* argv[5];
StdStreamRedirect streamRedirect;
argv[1] = (char*)"list";
argv[2] = (char*)"packs";
argv[3] = (char*)"-l";
argv[4] = (char*)"all";
EXPECT_EQ(0, RunProjMgr(5, argv, 0));

const string& expectedAll = "\
ARM::RteTest@0.1.0 \\(.*\\)\n\
ARM::RteTestBoard@0.1.0 \\(.*\\)\n\
ARM::RteTestGenerator@0.1.0 \\(.*\\)\n\
ARM::RteTest_DFP@0.1.1 \\(.*\\)\n\
ARM::RteTest_DFP@0.2.0 \\(.*\\)\n\
";

auto outStr = streamRedirect.GetOutString();
EXPECT_TRUE(regex_match(outStr, regex(expectedAll)));
}

TEST_F(ProjMgrUnitTests, RunProjMgr_ListPacksMissing) {
char* argv[8];
StdStreamRedirect streamRedirect;
Expand Down

0 comments on commit 29c0da7

Please sign in to comment.