From dee0eb4b8fbfe41f4876f351f306f43b8bdc7731 Mon Sep 17 00:00:00 2001 From: Sourabh Mehta <73165318+soumeh01@users.noreply.github.com> Date: Wed, 27 Sep 2023 14:08:52 +0200 Subject: [PATCH] Generate .Cbuild-idx.yml file with all contexts info --- tools/projmgr/src/ProjMgr.cpp | 17 ++++++++++------- tools/projmgr/src/ProjMgrYamlEmitter.cpp | 3 +++ tools/projmgr/test/src/ProjMgrUnitTests.cpp | 8 ++++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/tools/projmgr/src/ProjMgr.cpp b/tools/projmgr/src/ProjMgr.cpp index a887104b7..935084cf6 100644 --- a/tools/projmgr/src/ProjMgr.cpp +++ b/tools/projmgr/src/ProjMgr.cpp @@ -450,6 +450,7 @@ bool ProjMgr::RunConfigure(bool printConfig) { if (!m_worker.InitializeModel()) { return false; } + vector allContexts; vector orderedContexts; m_worker.GetYmlOrderedContexts(orderedContexts); // Process contexts @@ -457,6 +458,7 @@ bool ProjMgr::RunConfigure(bool printConfig) { m_processedContexts.clear(); for (auto& contextName : orderedContexts) { auto& contextItem = (*contexts)[contextName]; + allContexts.push_back(&contextItem); if (!m_worker.IsContextSelected(contextName)) { continue; } @@ -481,6 +483,14 @@ bool ProjMgr::RunConfigure(bool printConfig) { ProjMgrLogger::Info(infoMsg); } } + + // Generate cbuild index + if (!allContexts.empty()) { + if (!m_emitter.GenerateCbuildIndex(m_parser, allContexts, m_outputDir)) { + return false; + } + } + return !error; } @@ -516,13 +526,6 @@ bool ProjMgr::RunConvert(void) { return false; } } - - // Generate cbuild index - if (!m_processedContexts.empty()) { - if (!m_emitter.GenerateCbuildIndex(m_parser, m_processedContexts, m_outputDir)) { - return false; - } - } return !error; } diff --git a/tools/projmgr/src/ProjMgrYamlEmitter.cpp b/tools/projmgr/src/ProjMgrYamlEmitter.cpp index 0a8470a2c..0f35fa291 100644 --- a/tools/projmgr/src/ProjMgrYamlEmitter.cpp +++ b/tools/projmgr/src/ProjMgrYamlEmitter.cpp @@ -536,6 +536,9 @@ bool ProjMgrYamlEmitter::GenerateCbuildIndex(ProjMgrParser& parser, const vector ProjMgrYamlCbuild cbuild(rootNode[YAML_BUILD_IDX], contexts, parser, directory); if (!cbuild.CompareFile(filename, rootNode)) { + if (!RteFsUtils::Exists(directory)) { + RteFsUtils::CreateDirectories(directory); + } ofstream fileStream(filename); if (!fileStream) { ProjMgrLogger::Error(filename, "file cannot be written"); diff --git a/tools/projmgr/test/src/ProjMgrUnitTests.cpp b/tools/projmgr/test/src/ProjMgrUnitTests.cpp index 0021bb7c0..e50eb21ff 100644 --- a/tools/projmgr/test/src/ProjMgrUnitTests.cpp +++ b/tools/projmgr/test/src/ProjMgrUnitTests.cpp @@ -3420,7 +3420,9 @@ TEST_F(ProjMgrUnitTests, RunProjMgr_UpdateRte) { const string rteDir = testinput_folder + "/TestSolution/TestProject1/RTE/"; const string configFile = rteDir + "Device/RteTest_ARMCM0/startup_ARMCM0.c"; const string baseFile = configFile + ".base@1.1.1"; + const string& testdir = testoutput_folder + "/OutputDir"; RteFsUtils::RemoveDir(rteDir); + RteFsUtils::RemoveDir(testdir); RteFsUtils::CreateFile(configFile, "// config file"); RteFsUtils::CreateFile(baseFile, "// config file@base"); @@ -3433,7 +3435,7 @@ TEST_F(ProjMgrUnitTests, RunProjMgr_UpdateRte) { argv[3] = (char*)"-c"; argv[4] = (char*)"test1.Debug+CM0"; argv[5] = (char*)"-o"; - argv[6] = (char*)testoutput_folder.c_str(); + argv[6] = (char*)testdir.c_str(); argv[7] = (char*)"-v"; EXPECT_EQ(0, RunProjMgr(8, argv, 0)); EXPECT_TRUE(RteFsUtils::Exists(rteDir + "/_Debug_CM0/RTE_Components.h")); @@ -3445,10 +3447,12 @@ info csolution: config files for each component:\n\ - .*/TestSolution/TestProject1/RTE/Device/RteTest_ARMCM0/ARMCM0_ac6.sct \\(base@1.0.0\\)\n\ - .*/TestSolution/TestProject1/RTE/Device/RteTest_ARMCM0/startup_ARMCM0.c \\(base@1.1.1\\) \\(update@2.0.3\\)\n\ - .*/TestSolution/TestProject1/RTE/Device/RteTest_ARMCM0/system_ARMCM0.c \\(base@1.0.0\\)\n\ +.*/test.cbuild-idx.yml - info csolution: file generated successfully\n\ "; auto outStr = streamRedirect.GetOutString(); - EXPECT_TRUE(regex_match(outStr, regex(expected))); + EXPECT_TRUE(regex_match(outStr, regex(expected))) << + "Expected regex: \n" << expected << "\nActual:\n" << outStr; streamRedirect.ClearStringStreams(); argv[1] = (char*)"list";