Skip to content

Commit

Permalink
Merge branch 'main' into pr/implement-cbuild-pack
Browse files Browse the repository at this point in the history
  • Loading branch information
soumeh01 authored Nov 14, 2023
2 parents 37cd7b6 + ab7ac46 commit 4013331
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 296 deletions.
1 change: 0 additions & 1 deletion tools/projmgr/include/ProjMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class ProjMgr {
std::string m_csolutionFile;
std::string m_cdefaultFile;
std::vector<std::string> m_context;
std::string m_contextReplacement;
std::string m_filter;
std::string m_codeGenerator;
std::string m_command;
Expand Down
7 changes: 7 additions & 0 deletions tools/projmgr/include/ProjMgrExtGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ class ProjMgrExtGenerator {
*/
const std::string& GetGlobalGenRunCmd(const std::string& generatorId);

/**
* @brief get generator description
* @param generatorId generator identifier
* @return string with generator description
*/
const std::string& GetGlobalDescription(const std::string& generatorId);

/**
* @brief add generator to the list of used generators of a given context
* @param generatorId generator identifier
Expand Down
2 changes: 2 additions & 0 deletions tools/projmgr/include/ProjMgrParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,14 @@ struct CbuildSetItem {
/**
* @brief global generator item containing
* generator id,
* generator description,
* download url,
* bridge program,
* path for generated files
*/
struct GlobalGeneratorItem {
std::string id;
std::string description;
std::string downloadUrl;
std::string run;
std::string path;
Expand Down
12 changes: 0 additions & 12 deletions tools/projmgr/include/ProjMgrUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,18 +361,6 @@ class ProjMgrUtils {
const std::vector<std::string>& allAvailableContexts,
const std::vector<std::string>& contextFilters);

/**
* @brief replace list of contexts
* @param selectedContexts list of matched contexts
* @param allContexts list of all available contexts
* @param contextReplace filter criteria
* @return Error object with error message (if any)
*/
static Error ReplaceContexts(
std::vector<std::string>& selectedContexts,
const std::vector<std::string>& allContexts,
const std::string& contextReplace);

/**
* @brief get equivalent device attribute
* @param key device attribute rte key
Expand Down
1 change: 0 additions & 1 deletion tools/projmgr/include/ProjMgrWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,6 @@ class ProjMgrWorker {
*/
bool ParseContextSelection(
const std::vector<std::string>& contextSelection,
const std::string& contextReplace = RteUtils::EMPTY_STRING,
const bool checkCbuildSet = false);

/**
Expand Down
File renamed without changes.
9 changes: 8 additions & 1 deletion tools/projmgr/schemas/common.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"minItems": 1,
"items": { "$ref": "#/definitions/BuildContext" }
},
"ArrayOfBuildContextWithProjectName": {
"type": "array",
"uniqueItems": true,
"minItems": 1,
"items": { "$ref": "#/definitions/BuildContextWithProjectName" }
},
"ConditionIDType": {
"type": "string"
},
Expand Down Expand Up @@ -1146,7 +1152,7 @@
"type": "object",
"properties": {
"generated-by": { "type": "string", "description": "Tool name along with version information used to generate this application" },
"contexts": { "$ref": "#/definitions/ArrayOfStrings", "description": "List of fully specified contexts" },
"contexts": { "$ref": "#/definitions/ArrayOfBuildContextWithProjectName", "description": "List of fully specified contexts" },
"compiler": { "type": "string", "description": "Selection of compiler used" }
},
"additionalProperties": false,
Expand All @@ -1162,6 +1168,7 @@
"type": "object",
"properties": {
"id": { "type": "string", "description": "Generator identifier" },
"description": { "type": "string", "description": "Generator description" },
"download-url": { "type": "string", "description": "URL for downloading generator tool" },
"run": { "type": "string", "description": "Related bridge program" },
"path": { "type": "string", "description": "Specifies the directory for generated files" }
Expand Down
35 changes: 15 additions & 20 deletions tools/projmgr/src/ProjMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Commands:\n\
update-rte Create/update configuration files and validate solution\n\n\
Options:\n\
-c, --context arg [...] Input context names [<project-name>][.<build-type>][+<target-type>]\n\
--context-replacement arg Input context replacement name [<project-name>][.<build-type>][+<target-type>]\n\
-d, --debug Enable debug messages\n\
-D, --dry-run Enable dry-run\n\
-e, --export arg Set suffix for exporting <context><suffix>.cprj retaining only specified versions\n\
Expand Down Expand Up @@ -127,7 +126,6 @@ int ProjMgr::RunProjMgr(int argc, char **argv, char** envp) {

cxxopts::Option solution("s,solution", "Input csolution.yml file", cxxopts::value<string>());
cxxopts::Option context("c,context", "Input context names [<project-name>][.<build-type>][+<target-type>]", cxxopts::value<std::vector<std::string>>());
cxxopts::Option contextReplacement("context-replacement", "Input context replacement name [<cproject>][.<build-type>][+<target-type>]", cxxopts::value<std::string>());
cxxopts::Option filter("f,filter", "Filter words", cxxopts::value<string>());
cxxopts::Option help("h,help", "Print usage");
cxxopts::Option generator("g,generator", "Code generator identifier", cxxopts::value<string>());
Expand Down Expand Up @@ -159,16 +157,16 @@ int ProjMgr::RunProjMgr(int argc, char **argv, char** envp) {
{"list components", { true, {context, debug, filter, load, schemaCheck, toolchain, verbose}}},
{"list dependencies", { false, {context, debug, filter, load, schemaCheck, toolchain, verbose}}},
{"list contexts", { false, {debug, filter, schemaCheck, verbose, ymlOrder}}},
{"list generators", { false, {context, contextReplacement, debug, load, schemaCheck, toolchain, verbose}}},
{"list layers", { false, {context, contextReplacement, debug, load, clayerSearchPath, schemaCheck, toolchain, verbose}}},
{"list toolchains", { false, {context, contextReplacement, debug, toolchain, verbose}}},
{"list generators", { false, {context, debug, load, schemaCheck, toolchain, verbose}}},
{"list layers", { false, {context, debug, load, clayerSearchPath, schemaCheck, toolchain, verbose}}},
{"list toolchains", { false, {context, debug, toolchain, verbose}}},
{"list environment", { true, {}}},
};

try {
options.add_options("", {
{"positional", "", cxxopts::value<vector<string>>()},
solution, context, contextReplacement, contextSet, filter, generator,
solution, context, contextSet, filter, generator,
load, clayerSearchPath, missing, schemaCheck, noUpdateRte, output,
help, version, verbose, debug, dryRun, exportSuffix, toolchain, ymlOrder
});
Expand Down Expand Up @@ -226,9 +224,6 @@ int ProjMgr::RunProjMgr(int argc, char **argv, char** envp) {
if (parseResult.count("context")) {
manager.m_context = parseResult["context"].as<vector<string>>();
}
if (parseResult.count("context-replacement")) {
manager.m_contextReplacement = parseResult["context-replacement"].as<string>();
}
if (parseResult.count("filter")) {
manager.m_filter = parseResult["filter"].as<string>();
}
Expand Down Expand Up @@ -455,7 +450,7 @@ bool ProjMgr::RunConfigure(bool printConfig) {

bool checkCbuildSet = (m_context.size() == 0) && m_contextSet;
// Parse context selection
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement, checkCbuildSet)) {
if (!m_worker.ParseContextSelection(m_context, checkCbuildSet)) {
return false;
}
// Get context pointers
Expand Down Expand Up @@ -566,7 +561,7 @@ bool ProjMgr::RunListPacks(void) {
}
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
if (!m_worker.ParseContextSelection(m_context)) {
return false;
}
vector<string> packs;
Expand All @@ -585,7 +580,7 @@ bool ProjMgr::RunListBoards(void) {
}
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
if (!m_worker.ParseContextSelection(m_context)) {
return false;
}
vector<string> boards;
Expand All @@ -607,7 +602,7 @@ bool ProjMgr::RunListDevices(void) {
}
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
if (!m_worker.ParseContextSelection(m_context)) {
return false;
}
vector<string> devices;
Expand All @@ -629,7 +624,7 @@ bool ProjMgr::RunListComponents(void) {
}
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
if (!m_worker.ParseContextSelection(m_context)) {
return false;
}
vector<string> components;
Expand All @@ -651,7 +646,7 @@ bool ProjMgr::RunListConfigs() {
}
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
if (!m_worker.ParseContextSelection(m_context)) {
return false;
}
vector<string> configFiles;
Expand All @@ -671,7 +666,7 @@ bool ProjMgr::RunListDependencies(void) {
return false;
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
if (!m_worker.ParseContextSelection(m_context)) {
return false;
}
vector<string> dependencies;
Expand Down Expand Up @@ -707,7 +702,7 @@ bool ProjMgr::RunListGenerators(void) {
return false;
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
if (!m_worker.ParseContextSelection(m_context)) {
return false;
}
// Get generators
Expand All @@ -729,7 +724,7 @@ bool ProjMgr::RunListLayers(void) {
}
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
if (!m_worker.ParseContextSelection(m_context)) {
return false;
}
// Get layers
Expand All @@ -754,7 +749,7 @@ bool ProjMgr::RunCodeGenerator(void) {
return false;
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
if (!m_worker.ParseContextSelection(m_context)) {
return false;
}
if (m_extGenerator.IsGlobalGenerator(m_codeGenerator)) {
Expand All @@ -779,7 +774,7 @@ bool ProjMgr::RunListToolchains(void) {
}
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
if (!m_worker.ParseContextSelection(m_context)) {
return false;
}
vector<ToolchainItem> toolchains;
Expand Down
3 changes: 3 additions & 0 deletions tools/projmgr/src/ProjMgrExtGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const string& ProjMgrExtGenerator::GetGlobalGenRunCmd(const string& generatorId)
return(m_globalGenerators[generatorId].run);
}

const string& ProjMgrExtGenerator::GetGlobalDescription(const string& generatorId) {
return(m_globalGenerators[generatorId].description);
}

void ProjMgrExtGenerator::AddUsedGenerator(const string& generatorId, const string& genDir, const string& contextId) {
m_usedGenerators[generatorId][genDir].push_back(contextId);
Expand Down
104 changes: 0 additions & 104 deletions tools/projmgr/src/ProjMgrUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,110 +326,6 @@ ProjMgrUtils::Error ProjMgrUtils::GetSelectedContexts(vector<string>& selectedCo
return error;
}

ProjMgrUtils::Error ProjMgrUtils::ReplaceContexts(vector<string>& selectedContexts,
const vector<string>& allContexts, const string& contextReplace)
{
Error error;
if (contextReplace == RteUtils::EMPTY_STRING) {
return error;
}

// validate if the replace filter is valid
auto replaceContexts = GetFilteredContexts(allContexts, contextReplace);
if (replaceContexts.size() == 0) {
error.m_errMsg = "invalid context replacement name. \"" + contextReplace + "\" was not found.\n";
selectedContexts.clear();
return error;
}

// no replacement needed when replacement contexts list
// is exactly same as selected contexts list
if (selectedContexts.size() == replaceContexts.size()) {
set<string> sortedSelectedContexts(selectedContexts.begin(), selectedContexts.end());
set<string> sortedReplaceContexts(replaceContexts.begin(), replaceContexts.end());
if (sortedSelectedContexts == sortedReplaceContexts) {
// no replacement needed
return error;
}
}

// validate if replace filter requests more contexts than selected contexts
if (selectedContexts.size() < replaceContexts.size()) {
error.m_errMsg = "invalid replacement request. Replacement contexts are more than the selected contexts";
selectedContexts.clear();
return error;
}

ContextName replaceFilter;
ProjMgrUtils::ParseContextEntry(contextReplace, replaceFilter);

// validate if the replace filter has contexts which are not matching with selected context list
bool found = false;
for (auto& selectedContext : selectedContexts) {
ContextName context;
ProjMgrUtils::ParseContextEntry(selectedContext, context);
if (replaceFilter.project.empty() ||
WildCards::Match(replaceFilter.project, context.project)) {
found = true;
break;
}
}
if (!found) {
error.m_errMsg = "no suitable replacement found for context replacement \"" + contextReplace + "\"";
selectedContexts.clear();
return error;
}

if (replaceFilter.project.empty()) {
replaceFilter.project = "*";
}

// get a list of contexts needs to be replaced
vector<string> filteredContexts;
ContextName repContextItem, selContextItem;
for (string& selectedContext : selectedContexts) {
ProjMgrUtils::ParseContextEntry(selectedContext, selContextItem);
for (const string& contextItr : replaceContexts) {
if ((!replaceFilter.project.empty()) && (!WildCards::Match(replaceFilter.project, selContextItem.project))) {
// if 'project name' does not match the replace filter push it into the results and iterate further
ProjMgrUtils::PushBackUniquely(filteredContexts, selectedContext);
continue;
}

ProjMgrUtils::ParseContextEntry(contextItr, repContextItem);
// construct context name for replacement
string replaceContext = selContextItem.project;
if (!repContextItem.build.empty()) {
replaceContext += "." + repContextItem.build;
}
replaceContext += "+" + repContextItem.target;

if (find(allContexts.begin(), allContexts.end(), replaceContext) != allContexts.end()) {
// if 'replaceContext' is valid push it into the results
ProjMgrUtils::PushBackUniquely(filteredContexts, replaceContext);
}
}
}

if (filteredContexts.size() == 0) {
// no match found
error.m_errMsg = "no suitable replacements found for context replacement \"" + contextReplace + "\"";
selectedContexts.clear();
return error;
}

if (selectedContexts.size() != filteredContexts.size()) {
// incompatible change
error.m_errMsg = "incompatible replacements found for \"" + contextReplace + "\"";
selectedContexts.clear();
return error;
}

// update selected contexts with the filtered ones
selectedContexts = filteredContexts;
return error;
}

vector<string> ProjMgrUtils::GetFilteredContexts(
const vector<string>& allContexts, const string& contextFilter)
{
Expand Down
Loading

0 comments on commit 4013331

Please sign in to comment.