Skip to content

Commit

Permalink
[projmgr] Fix context-set handling
Browse files Browse the repository at this point in the history
  • Loading branch information
brondani authored Jul 19, 2024
1 parent 21980a0 commit 3753488
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 54 deletions.
50 changes: 7 additions & 43 deletions tools/projmgr/src/ProjMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,6 @@ bool ProjMgr::ParseAndValidateContexts() {
return false;
}

// validate and restrict the input contexts when used with -S option
if (!m_context.empty() && m_contextSet) {
if (!m_worker.ValidateContexts(m_context, false)) {
return false;
}
}

if (m_contextSet) {
const auto& selectedContexts = m_worker.GetSelectedContexts();
m_selectedToolchain = m_worker.GetSelectedToochain();
Expand Down Expand Up @@ -937,44 +930,15 @@ bool ProjMgr::RunListLayers(void) {
return false;
}

auto csolution = m_parser.GetCsolution();
string cbuildSetFile = csolution.directory + "/" + csolution.name + ".cbuild-set.yml";

// Check if the cbuildSetFile exists
if (!RteFsUtils::Exists(cbuildSetFile)) {
vector<string> orderedContexts;
m_worker.GetYmlOrderedContexts(orderedContexts);
if (orderedContexts.empty()) {
return false;
}

//first context in yaml ordered context should be processed
string selectedContext = orderedContexts.front();

// process only selectedContext
auto& contextItem = (*contexts)[selectedContext];
m_allContexts.push_back(&contextItem);
}
else {
// If cbuildSetFile exists, parse the file and select contexts from it
if (!m_parser.ParseCbuildSet(cbuildSetFile, true)) {
return false;
}

// Retrieve the parsed contexts
const auto& cbuildSetItem = m_parser.GetCbuildSetItem();
const auto& selectedContexts = cbuildSetItem.contexts;

for (auto& contextName : selectedContexts) {
auto& contextItem = (*contexts)[contextName];
m_allContexts.push_back(&contextItem);
}
}

// Generate Cbuild index
if (!m_allContexts.empty()) {
m_processedContexts.clear();
for (auto& contextName : m_worker.GetSelectedContexts()) {
auto& contextItem = (*contexts)[contextName];
m_processedContexts.push_back(&contextItem);
}
if (!m_processedContexts.empty()) {
if (!m_emitter.GenerateCbuildIndex(
m_parser, m_worker, m_allContexts, m_outputDir,
m_parser, m_worker, m_processedContexts, m_outputDir,
m_failedContext, map<string, ExecutesItem>(), m_checkSchema)) {
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions tools/projmgr/src/ProjMgrWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4218,10 +4218,6 @@ bool ProjMgrWorker::ParseContextSelection(
if (m_selectedToolchain.empty()) {
m_selectedToolchain = cbuildSetItem.compiler;
}

if (!ValidateContexts(m_selectedContexts, true)) {
return false;
}
}
else {
m_selectedContexts.clear();
Expand All @@ -4238,6 +4234,10 @@ bool ProjMgrWorker::ParseContextSelection(
return false;
}
}
// validate context selection
if (!ValidateContexts(m_selectedContexts, contextSelection.empty())) {
return false;
}
}

// Process the selected contexts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ build-idx:
project: variables-notdefined
configuration: .BuildType+TargetType
errors: true
- cbuild: testlayers.BuildType+TargetType.cbuild.yml
project: testlayers
configuration: .BuildType+TargetType
clayers:
- clayer: ../data/TestLayers/Layer1/layer1.clayer.yml
12 changes: 5 additions & 7 deletions tools/projmgr/test/src/ProjMgrUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6160,7 +6160,7 @@ TEST_F(ProjMgrUnitTests, ConvertEmptyLayer) {
}

TEST_F(ProjMgrUnitTests, RunProjMgr_conflict_cbuild_set) {
char* argv[9];
char* argv[7];
StdStreamRedirect streamRedirect;

// convert --solution solution.yml
Expand All @@ -6169,12 +6169,10 @@ TEST_F(ProjMgrUnitTests, RunProjMgr_conflict_cbuild_set) {
argv[2] = (char*)"--solution";
argv[3] = (char*)csolution.c_str();
argv[4] = (char*)"-c";
argv[5] = (char*)".Debug";
argv[6] = (char*)"-c";
argv[7] = (char*)".Release";
argv[8] = (char*)"-S";
EXPECT_EQ(1, RunProjMgr(9, argv, 0));
argv[5] = (char*)"test1+CM0";
argv[6] = (char*)"-S";
EXPECT_EQ(1, RunProjMgr(7, argv, 0));

auto errStr = streamRedirect.GetErrorString();
EXPECT_NE(errStr.find("build-type is not unique in '.Release' and '.Debug'"), string::npos);
EXPECT_NE(errStr.find("build-type is not unique in 'test1.Release+CM0' and 'test1.Debug+CM0'"), string::npos);
}

0 comments on commit 3753488

Please sign in to comment.