Skip to content

Commit ea1d742

Browse files
authored
[projmgr] Update cbuild-idx also in case of early convert errors
1 parent 59118ee commit ea1d742

5 files changed

Lines changed: 68 additions & 43 deletions

File tree

tools/projmgr/src/ProjMgr.cpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ bool ProjMgr::SetLoadPacksPolicy(void) {
474474
}
475475

476476
bool ProjMgr::PopulateContexts(void) {
477+
bool result = true;
478+
477479
if (!m_csolutionFile.empty()) {
478480
// Parse csolution
479481
if (!m_parser.ParseCsolution(m_csolutionFile, m_checkSchema, m_frozenPacks)) {
@@ -517,10 +519,10 @@ bool ProjMgr::PopulateContexts(void) {
517519
string const& cprojectFile = fs::canonical(m_rootDir + "/" + cproject, ec).generic_string();
518520
if (cprojectFile.empty()) {
519521
ProjMgrLogger::Get().Error("cproject file was not found", "", cproject);
520-
return false;
522+
result = false;
521523
}
522-
if (!m_parser.ParseCproject(cprojectFile, m_checkSchema)) {
523-
return false;
524+
else if (!m_parser.ParseCproject(cprojectFile, m_checkSchema)) {
525+
result = false;
524526
}
525527
}
526528
} else {
@@ -547,13 +549,13 @@ bool ProjMgr::PopulateContexts(void) {
547549
const string& cprojectFile = fs::path(descriptor.cproject).is_absolute() ?
548550
descriptor.cproject : fs::canonical(m_rootDir + "/" + descriptor.cproject, ec).generic_string();
549551
if (!m_worker.AddContexts(m_parser, descriptor, cprojectFile)) {
550-
return false;
552+
result = false;
551553
}
552554
}
553555

554556
// Populate active target-set
555557
if (m_activeTargetSet.has_value() && !m_worker.PopulateActiveTargetSet(m_activeTargetSet.value())) {
556-
return false;
558+
result = false;
557559
}
558560

559561
// Add image only context
@@ -562,7 +564,7 @@ bool ProjMgr::PopulateContexts(void) {
562564
// Retrieve all context types
563565
m_worker.RetrieveAllContextTypes();
564566

565-
return true;
567+
return result;
566568
}
567569

568570
bool ProjMgr::GenerateYMLConfigurationFiles(bool previousResult) {
@@ -599,13 +601,13 @@ bool ProjMgr::GenerateYMLConfigurationFiles(bool previousResult) {
599601
}
600602
}
601603

604+
// Get executes
605+
map<string, ExecutesItem> executes;
606+
m_worker.GetExecutes(executes);
607+
602608
// Generate cbuild index file
603-
if (!m_allContexts.empty()) {
604-
map<string, ExecutesItem> executes;
605-
m_worker.GetExecutes(executes);
606-
if (!m_emitter.GenerateCbuildIndex(m_processedContexts, m_failedContext, executes)) {
607-
return false;
608-
}
609+
if (!m_emitter.GenerateCbuildIndex(m_processedContexts, m_failedContext, executes)) {
610+
return false;
609611
}
610612

611613
return result;
@@ -635,13 +637,15 @@ bool ProjMgr::ParseAndValidateContexts() {
635637
}
636638

637639
bool ProjMgr::Configure() {
640+
bool result = true;
641+
638642
// Parse all input files and populate contexts inputs
639643
if (!PopulateContexts()) {
640-
return false;
644+
result = false;
641645
}
642646

643647
if (!ParseAndValidateContexts()) {
644-
return false;
648+
result = false;
645649
}
646650

647651
if (m_worker.HasVarDefineError()) {
@@ -654,24 +658,26 @@ bool ProjMgr::Configure() {
654658
}
655659

656660
// Process contexts
657-
bool error = !ProcessContexts();
661+
if (!ProcessContexts()) {
662+
result = false;
663+
}
658664

659665
if (m_worker.HasToolchainErrors()) {
660-
error = true;
666+
result = false;
661667
}
662668

663669
m_selectedToolchain = m_worker.GetSelectedToochain();
664670

665671
// Process solution level executes
666672
if (!m_worker.ProcessSolutionExecutes()) {
667-
error = true;
673+
result = false;
668674
}
669675
// Process executes dependencies
670676
m_worker.ProcessExecutesDependencies();
671677

672678
// Check missing files
673679
if (!m_worker.CheckMissingFiles()) {
674-
error = true;
680+
result = false;
675681
}
676682

677683
// Collect unused packs
@@ -692,7 +698,7 @@ bool ProjMgr::Configure() {
692698
}
693699
}
694700

695-
return !error;
701+
return result;
696702
}
697703

698704
bool ProjMgr::ProcessContexts() {

tools/projmgr/src/ProjMgrCbuildIdx.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2025 Arm Limited. All rights reserved.
2+
* Copyright (c) 2020-2026 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -44,15 +44,17 @@ ProjMgrCbuildIdx::ProjMgrCbuildIdx(YAML::Node node,
4444
SetNodeValue(node[YAML_OUTPUT_TMPDIR], FormatPath(parser->GetCsolution().directories.tmpdir, directory));
4545

4646
// Image Only flag
47-
bool imageOnlySolution = true;
48-
for (const auto& processedContext : processedContexts) {
49-
if (!processedContext->imageOnly) {
50-
imageOnlySolution = false;
51-
break;
47+
if (!processedContexts.empty()) {
48+
bool imageOnlySolution = true;
49+
for (const auto& processedContext : processedContexts) {
50+
if (!processedContext->imageOnly) {
51+
imageOnlySolution = false;
52+
break;
53+
}
54+
}
55+
if (imageOnlySolution) {
56+
node[YAML_IMAGE_ONLY] = true;
5257
}
53-
}
54-
if (imageOnlySolution) {
55-
node[YAML_IMAGE_ONLY] = true;
5658
}
5759

5860
// Generate layer info for each target
@@ -95,6 +97,9 @@ ProjMgrCbuildIdx::ProjMgrCbuildIdx(YAML::Node node,
9597
[&](const pair<std::string, CprojectItem>& elem) {
9698
return (fs::path(elem.first).filename().string() == fs::path(cprojectFile).filename().string());
9799
});
100+
if (itr == cprojects.end()) {
101+
continue;
102+
}
98103
auto cproject = itr->second;
99104
YAML::Node cprojectNode;
100105
const string& cprojectFilename = fs::relative(cproject.path, directory, ec).generic_string();

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5006,7 +5006,9 @@ bool ProjMgrWorker::ParseContextSelection(
50065006
else {
50075007
m_selectedContexts.clear();
50085008
//first context in yml ordered context should be processed
5009-
m_selectedContexts.push_back(ymlOrderedContexts.front());
5009+
if (!ymlOrderedContexts.empty()) {
5010+
m_selectedContexts.push_back(ymlOrderedContexts.front());
5011+
}
50105012
}
50115013
}
50125014
else {
@@ -5036,6 +5038,11 @@ bool ProjMgrWorker::ParseContextSelection(
50365038
string errMsg = "unknown selected context(s):";
50375039
for (const auto& context : unknownContexts) {
50385040
errMsg += "\n " + context;
5041+
// 'remove' shifts unwanted element to the end, 'erase' actually shrinks the vector
5042+
m_selectedContexts.erase(
5043+
remove(m_selectedContexts.begin(), m_selectedContexts.end(), context),
5044+
m_selectedContexts.end()
5045+
);
50395046
}
50405047
ProjMgrLogger::Get().Error(errMsg);
50415048
return false;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build-idx:
2+
generated-by: csolution version 0.0.0
3+
csolution: ../data/TestSolution/test_missing_project.csolution.yml
4+
tmpdir: tmp

tools/projmgr/test/src/ProjMgrUnitTests.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,6 +2863,10 @@ TEST_F(ProjMgrUnitTests, RunProjMgrLayers_missing_project_file) {
28632863
for (const auto& expected : expectedVec) {
28642864
EXPECT_TRUE(errStr.find(expected) != string::npos) << "Missing Expected: " + expected;
28652865
}
2866+
2867+
// Check generated cbuild-idx
2868+
ProjMgrTestEnv::CompareFile(testoutput_folder + "/test_missing_project.cbuild-idx.yml",
2869+
testinput_folder + "/TestSolution/ref/test_missing_project.cbuild-idx.yml");
28662870
}
28672871

28682872
TEST_F(ProjMgrUnitTests, RunProjMgrLayers_pname) {
@@ -6202,7 +6206,7 @@ TEST_F(ProjMgrUnitTests, FailCreatedFor) {
62026206
argv[4] = (char*)testoutput_folder.c_str();
62036207
EXPECT_EQ(1, RunProjMgr(5, argv, 0));
62046208
auto errMsg = streamRedirect.GetErrorString();
6205-
EXPECT_TRUE(regex_match(errMsg, regex(expectedErrMsg)));
6209+
EXPECT_TRUE(regex_search(errMsg, regex(expectedErrMsg)));
62066210
}
62076211

62086212
TEST_F(ProjMgrUnitTests, RunProjMgr_FailedConvertShouldCreateRteDirInProjectFolder) {
@@ -6987,20 +6991,19 @@ TEST_F(ProjMgrUnitTests, Test_Check_Define_Value) {
69876991

69886992
//Test2: Check Parsing errors
69896993
streamRedirect.ClearStringStreams();
6990-
expected = "\
6991-
error csolution: invalid define: \\\"No_ending_escape_quotes, improper quotes\n\
6992-
error csolution: invalid define: Escape_quotes_in_\\\"middle\\\", improper quotes\n\
6993-
error csolution: invalid define: \\\"Invalid_ending\"\\, improper quotes\n\
6994-
error csolution: invalid define: \\\"No_ending_escape_quotes, improper quotes\n\
6995-
error csolution: invalid define: \\\"sam.h\\, improper quotes\n\
6996-
error csolution: invalid define: \\\"Invalid_ending\"\\, improper quotes\n\
6997-
error csolution: invalid define: No_Starting_escaped_quotes\\\", improper quotes\n\
6998-
error csolution: invalid define: \\\"Mixed_quotes\", improper quotes\n\
6999-
";
6994+
expected = R"(error csolution: invalid define: \\\"No_ending_escape_quotes, improper quotes
6995+
error csolution: invalid define: Escape_quotes_in_\\\"middle\\\", improper quotes
6996+
error csolution: invalid define: \\\"Invalid_ending\"\\, improper quotes
6997+
error csolution: invalid define: \\\"No_ending_escape_quotes, improper quotes
6998+
error csolution: invalid define: \\\"sam.h\\, improper quotes
6999+
error csolution: invalid define: \\\"Invalid_ending\"\\, improper quotes
7000+
error csolution: invalid define: No_Starting_escaped_quotes\\\", improper quotes
7001+
error csolution: invalid define: \\\"Mixed_quotes\", improper quotes
7002+
)";
70007003
argv[5] = (char*)"-n";
70017004
EXPECT_EQ(1, RunProjMgr(6, argv, m_envp));
70027005
errStr = streamRedirect.GetErrorString();
7003-
EXPECT_EQ(errStr, expected);
7006+
EXPECT_TRUE(regex_search(errStr, regex(expected)));
70047007
}
70057008

70067009
TEST_F(ProjMgrUnitTests, ComponentVersions) {
@@ -7228,13 +7231,13 @@ TEST_F(ProjMgrUnitTests, ConvertActiveTargetSet) {
72287231
argv[4] = (char*)"Type1@Unknown";
72297232
EXPECT_EQ(1, RunProjMgr(5, argv, 0));
72307233
auto errStr = streamRedirect.GetErrorString();
7231-
EXPECT_STREQ(errStr.c_str(), "error csolution: 'Type1@Unknown' is not selectable as active target-set\n");
7234+
EXPECT_TRUE(errStr.find("error csolution: 'Type1@Unknown' is not selectable as active target-set\n") != string::npos);
72327235

72337236
streamRedirect.ClearStringStreams();
72347237
argv[4] = (char*)"TypeUnknown";
72357238
EXPECT_EQ(1, RunProjMgr(5, argv, 0));
72367239
errStr = streamRedirect.GetErrorString();
7237-
EXPECT_STREQ(errStr.c_str(), "error csolution: 'TypeUnknown' is not selectable as active target-set\n");
7240+
EXPECT_TRUE(errStr.find("error csolution: 'TypeUnknown' is not selectable as active target-set\n") != string::npos);
72387241

72397242
streamRedirect.ClearStringStreams();
72407243
argv[4] = (char*)"Type1";

0 commit comments

Comments
 (0)