Skip to content

Commit

Permalink
[projmgr] Check invalid context-set (#1086) (#1881)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Brondani <[email protected]>
  • Loading branch information
spcaipers-arm and brondani authored Dec 2, 2024
1 parent 936cf7d commit 0839678
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tools/projmgr/src/ProjMgrWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4393,8 +4393,24 @@ bool ProjMgrWorker::ParseContextSelection(
}
}

// Process the selected contexts
if (!((m_selectedContexts.size() == 1) && (m_selectedContexts.front() == RteUtils::EMPTY_STRING))) {
// Check selected contexts
StrVec unknownContexts;
for (const auto& context : m_selectedContexts) {
if (m_contexts.find(context) == m_contexts.end()) {
unknownContexts.push_back(context);
}
}
if (!unknownContexts.empty()) {
string errMsg = "unknown selected context(s):";
for (const auto& context : unknownContexts) {
errMsg += "\n " + context;
}
ProjMgrLogger::Get().Error(errMsg);
return false;
}

// Parse context layers
for (const auto& context : m_selectedContexts) {
if (!ParseContextLayers(m_contexts[context])) {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cbuild-set:
generated-by: csolution version 2.6.0
contexts:
- context: unknown1.debug+target
- context: unknown2.release+target
compiler: AC6
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json

solution:
compiler: AC6

target-types:
- type: CM0
device: RteTest_ARMCM0

projects:
- project: TestProject1/test1.cproject.yml
12 changes: 12 additions & 0 deletions tools/projmgr/test/src/ProjMgrUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6560,3 +6560,15 @@ TEST_F(ProjMgrUnitTests, PackCaseSensitive) {
EXPECT_EQ("required pack: Arm::RteTest_DFP not installed",
cbuild["build-idx"]["cbuilds"][0]["messages"]["errors"][0].as<string>());
}

TEST_F(ProjMgrUnitTests, InvalidContextSet) {
StdStreamRedirect streamRedirect;
char* argv[4];
const string& csolution = testinput_folder + "/TestSolution/invalid-context-set.csolution.yml";
argv[1] = (char*)"convert";
argv[2] = (char*)csolution.c_str();
argv[3] = (char*)"--context-set";
EXPECT_EQ(1, RunProjMgr(4, argv, m_envp));
auto errStr = streamRedirect.GetErrorString();
EXPECT_NE(string::npos, errStr.find("unknown selected context(s):\n unknown1.debug+target\n unknown2.release+target"));
}

0 comments on commit 0839678

Please sign in to comment.