Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[projmgr] csolution option --context-set inconsistency #1627

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/projmgr/include/ProjMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class ProjMgr {
bool Configure();
bool GenerateYMLConfigurationFiles();
void updateRte();
bool ParseAndValidateContexts();
};

#endif // PROJMGR_H
6 changes: 6 additions & 0 deletions tools/projmgr/include/ProjMgrWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,12 @@ class ProjMgrWorker {
const std::vector<std::string>& contextSelection,
const bool checkCbuildSet = false);

/**
* @brief get the list of selected contexts
* @return list of selected contexts
*/
std::vector<std::string> GetSelectedContexts() const;

/**
* @brief check if context is selected
* @param context name
Expand Down
4 changes: 2 additions & 2 deletions tools/projmgr/include/ProjMgrYamlEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ class ProjMgrYamlEmitter {

/**
* @brief generate cbuild set file
* @param contexts vector with pointers to contexts
* @param contexts list of selected contexts
* @param selectedCompiler name of the selected compiler
* @param cbuildSetFile path to *.cbuild-set file to be generated
* @param boolean check schema of generated file
* @return true if executed successfully
*/
static bool GenerateCbuildSet(const std::vector<ContextItem*> contexts,
static bool GenerateCbuildSet(const std::vector<std::string> selectedContexts,
const std::string& selectedCompiler, const std::string& cbuildSetFile, bool checkSchema);

/**
Expand Down
108 changes: 65 additions & 43 deletions tools/projmgr/src/ProjMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,16 @@ int ProjMgr::ParseCommandLine(int argc, char** argv) {
{"update-rte", { false, {context, contextSet, debug, load, quiet, schemaCheck, toolchain, verbose, frozenPacks}}},
{"convert", { false, {context, contextSet, debug, exportSuffix, load, quiet, schemaCheck, noUpdateRte, output, outputAlt, 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}}},
{"list devices", { true, {context, debug, filter, load, quiet, schemaCheck, toolchain, verbose}}},
{"list configs", { true, {context, debug, filter, load, quiet, schemaCheck, toolchain, verbose}}},
{"list components", { true, {context, debug, filter, load, quiet, schemaCheck, toolchain, verbose}}},
{"list dependencies", { false, {context, debug, filter, load, quiet, schemaCheck, toolchain, verbose}}},
{"list packs", { true, {context, contextSet, debug, filter, load, missing, quiet, schemaCheck, toolchain, verbose, relativePaths}}},
{"list boards", { true, {context, contextSet, debug, filter, load, quiet, schemaCheck, toolchain, verbose}}},
{"list devices", { true, {context, contextSet, debug, filter, load, quiet, schemaCheck, toolchain, verbose}}},
{"list configs", { true, {context, contextSet, debug, filter, load, quiet, schemaCheck, toolchain, verbose}}},
{"list components", { true, {context, contextSet, debug, filter, load, quiet, schemaCheck, toolchain, verbose}}},
{"list dependencies", { false, {context, contextSet, debug, filter, load, quiet, schemaCheck, toolchain, verbose}}},
{"list contexts", { false, {debug, filter, quiet, schemaCheck, verbose, ymlOrder}}},
{"list generators", { false, {context, debug, load, quiet, schemaCheck, toolchain, verbose}}},
{"list layers", { false, {context, debug, load, clayerSearchPath, quiet, schemaCheck, toolchain, verbose, updateIdx}}},
{"list toolchains", { false, {context, debug, quiet, toolchain, verbose}}},
{"list generators", { false, {context, contextSet, debug, load, quiet, schemaCheck, toolchain, verbose}}},
{"list layers", { false, {context, contextSet, debug, load, clayerSearchPath, quiet, schemaCheck, toolchain, verbose, updateIdx}}},
{"list toolchains", { false, {context, contextSet, debug, quiet, toolchain, verbose}}},
{"list environment", { true, {}}},
};

Expand Down Expand Up @@ -509,22 +509,6 @@ bool ProjMgr::GenerateYMLConfigurationFiles() {

bool result = true;

// Generate cbuild set file
if (m_contextSet) {
const string& cbuildSetFile = m_parser.GetCsolution().directory + "/" +
m_parser.GetCsolution().name + ".cbuild-set.yml";

if ((m_context.size() == 0) && (RteFsUtils::Exists(cbuildSetFile) == false)) {
ProjMgrLogger::Warn("unable to locate " + cbuildSetFile + " file.");
}
else if (!m_processedContexts.empty()) {
// Generate cbuild-set file
if (!m_emitter.GenerateCbuildSet(m_processedContexts, m_selectedToolchain, cbuildSetFile, m_checkSchema)) {
result = false;
}
}
}

// Generate cbuild files
for (auto& contextItem : m_processedContexts) {
if (!m_emitter.GenerateCbuild(contextItem, m_checkSchema)) {
Expand All @@ -544,25 +528,47 @@ bool ProjMgr::GenerateYMLConfigurationFiles() {
return result;
}

bool ProjMgr::Configure() {
// Parse all input files and populate contexts inputs
if (!PopulateContexts()) {
return false;
}

bool checkCbuildSet = (m_context.size() == 0) && m_contextSet;
bool ProjMgr::ParseAndValidateContexts() {
const string& cbuildSetFile = m_parser.GetCsolution().directory + "/" +
m_parser.GetCsolution().name + ".cbuild-set.yml";
bool fileExist = RteFsUtils::Exists(cbuildSetFile);
bool writeCbuildSetFile = m_contextSet && (!fileExist || !m_selectedToolchain.empty());

// Parse context selection
if (!m_worker.ParseContextSelection(m_context, checkCbuildSet)) {
if (!m_worker.ParseContextSelection(m_context, m_contextSet)) {
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)){
if (!m_worker.ValidateContexts(m_context, false)) {
return false;
}
}

if (writeCbuildSetFile) {
const auto& selectedContexts = m_worker.GetSelectedContexts();
if (!selectedContexts.empty()) {
// Generate cbuild-set file
if (!m_emitter.GenerateCbuildSet(selectedContexts, m_selectedToolchain, cbuildSetFile, m_checkSchema)) {
return false;
}
}
}

return true;
}

bool ProjMgr::Configure() {
// Parse all input files and populate contexts inputs
if (!PopulateContexts()) {
return false;
}

if (!ParseAndValidateContexts()) {
return false;
}

if (m_worker.HasVarDefineError()) {
auto undefVars = m_worker.GetUndefLayerVars();
string errMsg = "undefined variables in "+ fs::path(m_csolutionFile).filename().generic_string() +":\n";
Expand Down Expand Up @@ -688,10 +694,12 @@ bool ProjMgr::RunListPacks(void) {
return false;
}
}

// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!ParseAndValidateContexts()) {
return false;
}

vector<string> packs;
bool ret = m_worker.ListPacks(packs, m_missingPacks, m_filter);
for (const auto& pack : packs) {
Expand All @@ -707,10 +715,12 @@ bool ProjMgr::RunListBoards(void) {
return false;
}
}

// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!ParseAndValidateContexts()) {
return false;
}

vector<string> boards;
if (!m_worker.ListBoards(boards, m_filter)) {
ProjMgrLogger::Error("processing boards list failed");
Expand All @@ -729,10 +739,12 @@ bool ProjMgr::RunListDevices(void) {
return false;
}
}

// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!ParseAndValidateContexts()) {
return false;
}

vector<string> devices;
if (!m_worker.ListDevices(devices, m_filter)) {
ProjMgrLogger::Error("processing devices list failed");
Expand All @@ -751,10 +763,12 @@ bool ProjMgr::RunListComponents(void) {
return false;
}
}

// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!ParseAndValidateContexts()) {
return false;
}

vector<string> components;
if (!m_worker.ListComponents(components, m_filter)) {
ProjMgrLogger::Error("processing components list failed");
Expand All @@ -780,10 +794,12 @@ bool ProjMgr::RunListConfigs() {
return false;
}
}

// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!ParseAndValidateContexts()) {
return false;
}

vector<string> configFiles;
if (!m_worker.ListConfigs(configFiles, m_filter)) {
ProjMgrLogger::Error("processing config list failed");
Expand All @@ -807,10 +823,12 @@ bool ProjMgr::RunListDependencies(void) {
if (!PopulateContexts()) {
return false;
}

// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!ParseAndValidateContexts()) {
return false;
}

vector<string> dependencies;
if (!m_worker.ListDependencies(dependencies, m_filter)) {
ProjMgrLogger::Error("processing dependencies list failed");
Expand Down Expand Up @@ -848,10 +866,12 @@ bool ProjMgr::RunListGenerators(void) {
if (!PopulateContexts()) {
return false;
}

// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!ParseAndValidateContexts()) {
return false;
}

// Get generators
vector<string> generators;
if (!m_worker.ListGenerators(generators)) {
Expand All @@ -877,7 +897,7 @@ bool ProjMgr::RunListLayers(void) {
}

// Step2 : Parse selected contexts
if (!m_worker.ParseContextSelection(m_context)) {
if (!ParseAndValidateContexts()) {
return false;
}

Expand Down Expand Up @@ -1000,10 +1020,12 @@ bool ProjMgr::RunListToolchains(void) {
return false;
}
}

// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!ParseAndValidateContexts()) {
return false;
}

vector<ToolchainItem> toolchains;
bool success = m_worker.ListToolchains(toolchains);

Expand Down
72 changes: 53 additions & 19 deletions tools/projmgr/src/ProjMgrWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4165,43 +4165,77 @@ bool ProjMgrWorker::ProcessSequencesRelatives(ContextItem& context, BuildType& b
bool ProjMgrWorker::ParseContextSelection(
const vector<string>& contextSelection, const bool checkCbuildSet)
{
vector<string> contexts;
ListContexts(contexts);
vector<string> ymlOrderedContexts;
ListContexts(ymlOrderedContexts, RteUtils::EMPTY_STRING, true);

auto csolutionItem = m_parser->GetCsolution();
string cbuildSetFile = csolutionItem.directory + "/" + csolutionItem.name + ".cbuild-set.yml";
if (checkCbuildSet && RteFsUtils::Exists(cbuildSetFile)) {
if (!m_parser->ParseCbuildSet(cbuildSetFile, m_checkSchema)) {
return false;
}
const auto& cbuildSetItem = m_parser->GetCbuildSetItem();
m_selectedContexts = cbuildSetItem.contexts;
if (m_selectedToolchain.empty()) {
m_selectedToolchain = cbuildSetItem.compiler;
}
if (!ValidateContexts(m_selectedContexts, true)) {
return false;
}
}
else {
if (!checkCbuildSet) {
// selected all contexts to process, when contextSelection is empty
// otherwise process contexts from contextSelection
const auto& filterError = ProjMgrUtils::GetSelectedContexts(
m_selectedContexts, contexts, contextSelection);
m_selectedContexts, ymlOrderedContexts, contextSelection);
if (filterError) {
ProjMgrLogger::Error(filterError.m_errMsg);
return false;
}
}
else
{
auto csolutionItem = m_parser->GetCsolution();
string cbuildSetFile = csolutionItem.directory + "/" + csolutionItem.name + ".cbuild-set.yml";

if (contextSelection.empty()) {
if (RteFsUtils::Exists(cbuildSetFile)) {
// Parse the existing cbuild-set file
if (!m_parser->ParseCbuildSet(cbuildSetFile, m_checkSchema)) {
return false;
}

// Read contexts info from the file
const auto& cbuildSetItem = m_parser->GetCbuildSetItem();
m_selectedContexts = cbuildSetItem.contexts;

// Select toolchain if not already selected
if (m_selectedToolchain.empty()) {
m_selectedToolchain = cbuildSetItem.compiler;
}

if (!ValidateContexts(m_selectedContexts, true)) {
return false;
}
}
else {
m_selectedContexts.clear();
//first context in yml ordered context should be processed
m_selectedContexts.push_back(ymlOrderedContexts.front());
}
}
else {
// Contexts are specified in contextSelection
const auto& filterError = ProjMgrUtils::GetSelectedContexts(
m_selectedContexts, ymlOrderedContexts, contextSelection);
if (filterError) {
ProjMgrLogger::Error(filterError.m_errMsg);
return false;
}
}
}

// Process the selected contexts
if (!((m_selectedContexts.size() == 1) && (m_selectedContexts.front() == RteUtils::EMPTY_STRING))) {
for (const auto& context : m_selectedContexts) {
if (!ParseContextLayers(m_contexts[context])) {
return false;
}
}
}

return true;
}

vector<string> ProjMgrWorker::GetSelectedContexts() const {
return m_selectedContexts;
}

bool ProjMgrWorker::IsContextSelected(const string& context) {
if (find(m_selectedContexts.begin(), m_selectedContexts.end(), context) != m_selectedContexts.end()) {
return true;
Expand Down
Loading
Loading