Skip to content

Commit

Permalink
[projmgr] Add --cbuild2cmake option
Browse files Browse the repository at this point in the history
  • Loading branch information
grasci-arm authored Jun 24, 2024
1 parent afb8bed commit 2ba9658
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 25 deletions.
1 change: 1 addition & 0 deletions tools/projmgr/include/ProjMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class ProjMgr {
bool m_contextSet;
bool m_relativePaths;
bool m_frozenPacks;
bool m_cbuild2cmake;
bool m_updateIdx;
GroupNode m_files;
std::vector<ContextItem*> m_processedContexts;
Expand Down
9 changes: 8 additions & 1 deletion tools/projmgr/include/ProjMgrWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,12 @@ class ProjMgrWorker {
*/
void SetDryRun(bool dryRun);

/**
* @brief set cbuild2cmake mode
* @param boolean cbuild2cmake
*/
void SetCbuild2Cmake(bool cbuild2cmake);

/**
* @brief set printing paths relative to project or ${CMSSIS_PACK_ROOT}
* @param boolean bRelativePaths
Expand Down Expand Up @@ -692,6 +698,7 @@ class ProjMgrWorker {
bool m_debug;
bool m_dryRun;
bool m_relativePaths;
bool m_cbuild2cmake;
std::set<std::string> m_undefLayerVars;
StrMap m_packMetadata;
std::map<std::string, ExecutesItem> m_executes;
Expand Down Expand Up @@ -799,7 +806,7 @@ class ProjMgrWorker {
void SetFilesDependencies(const GroupNode& group, const std::string& ouput, StrVec& dependsOn, const std::string& dep, const std::string& outDir);
void SetBuildOutputDependencies(const OutputTypes& outputTypes, const std::string& input, StrVec& dependsOn, const std::string& dep, const std::string& outDir);
void SetExecutesDependencies(const std::string& output, const std::string& dep, const std::string& outDir);
void ValidateComponentSources(ContextItem& context);
bool ValidateComponentSources(ContextItem& context);
void ProcessSelectableCompilers();
};

Expand Down
39 changes: 22 additions & 17 deletions tools/projmgr/src/ProjMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,13 @@ int ProjMgr::ParseCommandLine(int argc, char** argv) {
cxxopts::Option frozenPacks("frozen-packs", "The list of packs from cbuild-pack.yml is frozen and raises error if not up-to-date", cxxopts::value<bool>()->default_value("false"));
cxxopts::Option updateIdx("update-idx", "Update cbuild-idx file with layer info", cxxopts::value<bool>()->default_value("false"));
cxxopts::Option quiet("q,quiet", "Run silently, printing only error messages", cxxopts::value<bool>()->default_value("false"));
cxxopts::Option cbuild2cmake("cbuild2cmake", "Generate build information files only for cbuild2cmake backend", cxxopts::value<bool>()->default_value("false"));

// command options dictionary
map<string, std::pair<bool, vector<cxxopts::Option>>> optionsDict = {
// command, optional args, options
{"update-rte", { false, {context, contextSet, debug, load, quiet, schemaCheck, toolchain, verbose, frozenPacks}}},
{"convert", { false, {context, contextSet, debug, exportSuffix, load, quiet, schemaCheck, noUpdateRte, output, toolchain, verbose, frozenPacks}}},
{"convert", { false, {context, contextSet, debug, exportSuffix, load, quiet, schemaCheck, noUpdateRte, output, toolchain, verbose, frozenPacks, cbuild2cmake}}},
{"run", { false, {context, contextSet, debug, generator, load, quiet, schemaCheck, verbose, dryRun}}},
{"list packs", { true, {context, debug, filter, load, missing, quiet, schemaCheck, toolchain, verbose, relativePaths}}},
{"list boards", { true, {context, debug, filter, load, quiet, schemaCheck, toolchain, verbose}}},
Expand All @@ -183,7 +184,7 @@ int ProjMgr::ParseCommandLine(int argc, char** argv) {
solution, context, contextSet, filter, generator,
load, clayerSearchPath, missing, schemaCheck, noUpdateRte, output,
help, version, verbose, debug, dryRun, exportSuffix, toolchain, ymlOrder,
relativePaths, frozenPacks, updateIdx, quiet
relativePaths, frozenPacks, updateIdx, quiet, cbuild2cmake
});
options.parse_positional({ "positional" });

Expand All @@ -205,6 +206,8 @@ int ProjMgr::ParseCommandLine(int argc, char** argv) {
m_relativePaths = parseResult.count("relative-paths");
m_worker.SetPrintRelativePaths(m_relativePaths);
m_frozenPacks = parseResult.count("frozen-packs");
m_cbuild2cmake = parseResult.count("cbuild2cmake");
m_worker.SetCbuild2Cmake(m_cbuild2cmake);
ProjMgrLogger::m_quiet = parseResult.count("quiet");

vector<string> positionalArguments;
Expand Down Expand Up @@ -645,24 +648,26 @@ bool ProjMgr::RunConvert(void) {
Success &= GenerateYMLConfigurationFiles();

// Generate Cprjs
for (auto& contextItem : m_processedContexts) {
const string filename = RteFsUtils::MakePathCanonical(contextItem->directories.cprj + "/" + contextItem->name + ".cprj");
RteFsUtils::CreateDirectories(contextItem->directories.cprj);
if (m_generator.GenerateCprj(*contextItem, filename)) {
ProjMgrLogger::Info(filename, "file generated successfully");
} else {
ProjMgrLogger::Error(filename, "file cannot be written");
return false;
}
if (!m_export.empty()) {
// Generate non-locked Cprj
const string exportfilename = RteFsUtils::MakePathCanonical(contextItem->directories.cprj + "/" + contextItem->name + m_export + ".cprj");
if (m_generator.GenerateCprj(*contextItem, exportfilename, true)) {
ProjMgrLogger::Info(exportfilename, "export file generated successfully");
if (!m_cbuild2cmake) {
for (auto& contextItem : m_processedContexts) {
const string filename = RteFsUtils::MakePathCanonical(contextItem->directories.cprj + "/" + contextItem->name + ".cprj");
RteFsUtils::CreateDirectories(contextItem->directories.cprj);
if (m_generator.GenerateCprj(*contextItem, filename)) {
ProjMgrLogger::Info(filename, "file generated successfully");
} else {
ProjMgrLogger::Error(exportfilename, "export file cannot be written");
ProjMgrLogger::Error(filename, "file cannot be written");
return false;
}
if (!m_export.empty()) {
// Generate non-locked Cprj
const string exportfilename = RteFsUtils::MakePathCanonical(contextItem->directories.cprj + "/" + contextItem->name + m_export + ".cprj");
if (m_generator.GenerateCprj(*contextItem, exportfilename, true)) {
ProjMgrLogger::Info(exportfilename, "export file generated successfully");
} else {
ProjMgrLogger::Error(exportfilename, "export file cannot be written");
return false;
}
}
}
}

Expand Down
19 changes: 16 additions & 3 deletions tools/projmgr/src/ProjMgrWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ void ProjMgrWorker::SetDryRun(bool dryRun) {
m_dryRun = dryRun;
}

void ProjMgrWorker::SetCbuild2Cmake(bool cbuild2cmake) {
m_cbuild2cmake = cbuild2cmake;
}

void ProjMgrWorker::SetPrintRelativePaths(bool bRelativePaths) {
m_relativePaths = bRelativePaths;
}
Expand Down Expand Up @@ -2119,12 +2123,15 @@ bool ProjMgrWorker::ProcessComponentFiles(ContextItem& context) {
}
}
}
ValidateComponentSources(context);
if (!ValidateComponentSources(context)) {
return false;
}
return true;
}

void ProjMgrWorker::ValidateComponentSources(ContextItem& context) {
bool ProjMgrWorker::ValidateComponentSources(ContextItem& context) {
// find multiple defined sources
bool error = false;
StrSet sources, multipleDefinedSources;
for (const auto& [componentID, files] : context.componentFiles) {
for (const auto& file : files) {
Expand All @@ -2148,9 +2155,15 @@ void ProjMgrWorker::ValidateComponentSources(ContextItem& context) {
}
}
}
ProjMgrLogger::Warn(errMsg);
if (m_cbuild2cmake) {
ProjMgrLogger::Error(errMsg);
error = true;
} else {
ProjMgrLogger::Warn(errMsg);
}
}
}
return !error;
}

void ProjMgrWorker::SetFilesDependencies(const GroupNode& group, const string& ouput, StrVec& dependsOn, const string& dep, const string& outDir) {
Expand Down
14 changes: 10 additions & 4 deletions tools/projmgr/test/src/ProjMgrUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5930,23 +5930,29 @@ TEST_F(ProjMgrUnitTests, SelectableToolchains) {

TEST_F(ProjMgrUnitTests, SourcesAddedByMultipleComponents) {
StdStreamRedirect streamRedirect;
char* argv[5];
char* argv[6];
const string& csolution = testinput_folder + "/TestSolution/ComponentSources/components.csolution.yml";
argv[1] = (char*)"convert";
argv[2] = (char*)csolution.c_str();
argv[3] = (char*)"-o";
argv[4] = (char*)testoutput_folder.c_str();;
EXPECT_EQ(0, RunProjMgr(5, argv, m_envp));

const string expected = "\
warning csolution: source modules added by multiple components:\n\
const string& expected = "\
(warning|error) csolution: source modules added by multiple components:\n\
filename: .*/ARM/RteTest/0.1.0/Dummy/dummy.c\n\
- component: ARM::RteTest:[email protected]\n\
from-pack: ARM::[email protected]\n\
- component: ARM::RteTest:[email protected]\n\
from-pack: ARM::[email protected]\n\
";

const string& errStr = streamRedirect.GetErrorString();
string errStr = streamRedirect.GetErrorString();
EXPECT_TRUE(regex_search(errStr, regex(expected)));

argv[5] = (char*)"--cbuild2cmake";
streamRedirect.ClearStringStreams();
EXPECT_EQ(1, RunProjMgr(6, argv, m_envp));
errStr = streamRedirect.GetErrorString();
EXPECT_TRUE(regex_search(errStr, regex(expected)));
}

0 comments on commit 2ba9658

Please sign in to comment.