From 37534881696f70695c8b41ab1d49dbc203ef3233 Mon Sep 17 00:00:00 2001 From: Daniel Brondani Date: Fri, 19 Jul 2024 11:10:44 +0200 Subject: [PATCH] [projmgr] Fix `context-set` handling --- tools/projmgr/src/ProjMgr.cpp | 50 +++---------------- tools/projmgr/src/ProjMgrWorker.cpp | 8 +-- .../ref/variables-notdefined.cbuild-idx.yml | 5 ++ tools/projmgr/test/src/ProjMgrUnitTests.cpp | 12 ++--- 4 files changed, 21 insertions(+), 54 deletions(-) diff --git a/tools/projmgr/src/ProjMgr.cpp b/tools/projmgr/src/ProjMgr.cpp index 4eb5ac46b..64f3f28e6 100644 --- a/tools/projmgr/src/ProjMgr.cpp +++ b/tools/projmgr/src/ProjMgr.cpp @@ -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(); @@ -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 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(), m_checkSchema)) { return false; } diff --git a/tools/projmgr/src/ProjMgrWorker.cpp b/tools/projmgr/src/ProjMgrWorker.cpp index 412868cbe..ff476c2e3 100644 --- a/tools/projmgr/src/ProjMgrWorker.cpp +++ b/tools/projmgr/src/ProjMgrWorker.cpp @@ -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(); @@ -4238,6 +4234,10 @@ bool ProjMgrWorker::ParseContextSelection( return false; } } + // validate context selection + if (!ValidateContexts(m_selectedContexts, contextSelection.empty())) { + return false; + } } // Process the selected contexts diff --git a/tools/projmgr/test/data/TestLayers/ref/variables-notdefined.cbuild-idx.yml b/tools/projmgr/test/data/TestLayers/ref/variables-notdefined.cbuild-idx.yml index df0eef4d3..dae3d6c13 100644 --- a/tools/projmgr/test/data/TestLayers/ref/variables-notdefined.cbuild-idx.yml +++ b/tools/projmgr/test/data/TestLayers/ref/variables-notdefined.cbuild-idx.yml @@ -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 diff --git a/tools/projmgr/test/src/ProjMgrUnitTests.cpp b/tools/projmgr/test/src/ProjMgrUnitTests.cpp index d5c2ab262..5f059c286 100644 --- a/tools/projmgr/test/src/ProjMgrUnitTests.cpp +++ b/tools/projmgr/test/src/ProjMgrUnitTests.cpp @@ -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 @@ -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); }