Skip to content

Commit

Permalink
[projmgr] Option --context-replacement to replace context(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
grasci-arm authored Jul 24, 2023
1 parent 5d3d826 commit 5e9b9ec
Show file tree
Hide file tree
Showing 9 changed files with 522 additions and 154 deletions.
56 changes: 29 additions & 27 deletions tools/projmgr/docs/Manual/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,35 +143,37 @@ Usage:
csolution <command> [<name>.csolution.yml] [options]
Commands:
convert Convert user input *.yml files to *.cprj files
list boards Print list of available board names
list contexts Print list of contexts in a <name>.csolution.yml
list components Print list of available components
list dependencies Print list of unresolved project dependencies
list devices Print list of available device names
list environment Print list of environment configurations
list generators Print list of code generators of a given context
list layers Print list of available, referenced and compatible layers
list packs Print list of used packs from the pack repository
list toolchains Print list of supported toolchains
run Run code generator
update-rte Create/update configuration files and validate solution
convert Convert user input *.yml files to *.cprj files
list boards Print list of available board names
list contexts Print list of contexts in a <name>.csolution.yml
list components Print list of available components
list dependencies Print list of unresolved project dependencies
list devices Print list of available device names
list environment Print list of environment configurations
list generators Print list of code generators of a given context
list layers Print list of available, referenced and compatible layers
list packs Print list of used packs from the pack repository
list toolchains Print list of supported toolchains
run Run code generator
update-rte Create/update configuration files and validate solution
Options:
-c, --context arg [...] Input context names [<project-name>][.<build-type>][+<target-type>]
-d, --debug Enable debug messages
-e, --export arg Set suffix for exporting <context><suffix>.cprj retaining only specified versions
-f, --filter arg Filter words
-g, --generator arg Code generator identifier
-l, --load arg Set policy for packs loading [latest | all | required]
-L, --clayer-path arg Set search path for external clayers
-m, --missing List only required packs that are missing in the pack repository
-n, --no-check-schema Skip schema check
-N, --no-update-rte Skip creation of RTE directory and files
-o, --output arg Output directory
-t, --toolchain arg Selection of the toolchain used in the project optionally with version
-v, --verbose Enable verbose messages
-V, --version Print version
-c, --context arg [...] Input context names [<project-name>][.<build-type>][+<target-type>]
--context-replacement arg Input context replacement name [<project-name>][.<build-type>][+<target-type>]
-d, --debug Enable debug messages
-D, --dry-run Enable dry-run
-e, --export arg Set suffix for exporting <context><suffix>.cprj retaining only specified versions
-f, --filter arg Filter words
-g, --generator arg Code generator identifier
-l, --load arg Set policy for packs loading [latest | all | required]
-L, --clayer-path arg Set search path for external clayers
-m, --missing List only required packs that are missing in the pack repository
-n, --no-check-schema Skip schema check
-N, --no-update-rte Skip creation of RTE directory and files
-o, --output arg Output directory
-t, --toolchain arg Selection of the toolchain used in the project optionally with version
-v, --verbose Enable verbose messages
-V, --version Print version
Use 'csolution <command> -h' for more information about a command.
```
Expand Down
1 change: 1 addition & 0 deletions tools/projmgr/include/ProjMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ 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
40 changes: 36 additions & 4 deletions tools/projmgr/include/ProjMgrUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,49 @@ class ProjMgrUtils {
*/
static void SetOutputType(const std::string typeString, OutputTypes& type);

struct Error {
Error(std::string errMsg = RteUtils::EMPTY_STRING) {
m_errMsg = errMsg;
}
std::string m_errMsg;
operator bool() const { return (m_errMsg != RteUtils::EMPTY_STRING); }
};

/**
* @brief get filtered list of contexts
* @brief get selected list of contexts
* @param selectedContexts list of matched contexts
* @param allAvailableContexts list of all available contexts
* @param contextFilter filter criteria
* @return list of filters for which match was not found, else empty list
*/
static std::vector<std::string> GetSelectedContexts(
std::list<std::string>& selectedContexts,
static Error GetSelectedContexts(
std::vector<std::string>& selectedContexts,
const std::vector<std::string>& allAvailableContexts,
const std::vector<std::string>& contextFilter);
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);

protected:
static std::string ConstructID(const std::vector<std::pair<const char*, const std::string&>>& elements);
/**
* @brief get filtered list of contexts
* @param allContexts list of all available contexts
* @param contextFilter filter criteria
* @return list of filters for which match was not found, else empty list
*/
static std::vector<std::string> GetFilteredContexts(
const std::vector<std::string>& allContexts,
const std::string& contextFilter);
};

#endif // PROJMGRUTILS_H
7 changes: 5 additions & 2 deletions tools/projmgr/include/ProjMgrWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,12 @@ class ProjMgrWorker {
/**
* @brief parse context selection
* @param contexts pattern (wildcards are allowed)
* @param context replacement pattern (wildcards are allowed)
* @return true if executed successfully
*/
bool ParseContextSelection(const std::vector<std::string>& contextSelection);
bool ParseContextSelection(
const std::vector<std::string>& contextSelection,
const std::string& contextReplace = RteUtils::EMPTY_STRING);

/**
* @brief check if context is selected
Expand Down Expand Up @@ -559,7 +562,7 @@ class ProjMgrWorker {
std::vector<std::string> m_ymlOrderedContexts;
std::map<std::string, ContextItem> m_contexts;
std::map<std::string, ContextItem>* m_contextsPtr;
std::list<std::string> m_selectedContexts;
std::vector<std::string> m_selectedContexts;
std::string m_outputDir;
std::string m_packRoot;
std::string m_compilerRoot;
Expand Down
91 changes: 48 additions & 43 deletions tools/projmgr/src/ProjMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,37 @@ static constexpr const char* USAGE = "\n\
Usage:\n\
csolution <command> [<name>.csolution.yml] [options]\n\n\
Commands:\n\
convert Convert user input *.yml files to *.cprj files\n\
list boards Print list of available board names\n\
list contexts Print list of contexts in a <name>.csolution.yml\n\
list components Print list of available components\n\
list dependencies Print list of unresolved project dependencies\n\
list devices Print list of available device names\n\
list environment Print list of environment configurations\n\
list generators Print list of code generators of a given context\n\
list layers Print list of available, referenced and compatible layers\n\
list packs Print list of used packs from the pack repository\n\
list toolchains Print list of supported toolchains\n\
run Run code generator\n\
update-rte Create/update configuration files and validate solution\n\n\
convert Convert user input *.yml files to *.cprj files\n\
list boards Print list of available board names\n\
list contexts Print list of contexts in a <name>.csolution.yml\n\
list components Print list of available components\n\
list dependencies Print list of unresolved project dependencies\n\
list devices Print list of available device names\n\
list environment Print list of environment configurations\n\
list generators Print list of code generators of a given context\n\
list layers Print list of available, referenced and compatible layers\n\
list packs Print list of used packs from the pack repository\n\
list toolchains Print list of supported toolchains\n\
run Run code generator\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\
-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\
-f, --filter arg Filter words\n\
-g, --generator arg Code generator identifier\n\
-l, --load arg Set policy for packs loading [latest | all | required]\n\
-L, --clayer-path arg Set search path for external clayers\n\
-m, --missing List only required packs that are missing in the pack repository\n\
-n, --no-check-schema Skip schema check\n\
-N, --no-update-rte Skip creation of RTE directory and files\n\
-o, --output arg Output directory\n\
-t, --toolchain arg Selection of the toolchain used in the project optionally with version\n\
-v, --verbose Enable verbose messages\n\
-V, --version Print version\n\n\
Use 'csolution <command> -h' for more information about a command.\
-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\
-f, --filter arg Filter words\n\
-g, --generator arg Code generator identifier\n\
-l, --load arg Set policy for packs loading [latest | all | required]\n\
-L, --clayer-path arg Set search path for external clayers\n\
-m, --missing List only required packs that are missing in the pack repository\n\
-n, --no-check-schema Skip schema check\n\
-N, --no-update-rte Skip creation of RTE directory and files\n\
-o, --output arg Output directory\n\
-t, --toolchain arg Selection of the toolchain used in the project optionally with version\n\
-v, --verbose Enable verbose messages\n\
-V, --version Print version\n\n\
Use 'csolution <command> -h' for more information about a command.\n\
";

ProjMgr::ProjMgr(void) : m_checkSchema(false), m_updateRteFiles(true) {
Expand Down Expand Up @@ -119,6 +120,7 @@ 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 @@ -148,16 +150,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, debug, load, schemaCheck, toolchain, verbose}}},
{"list layers", { false, {context, debug, load, clayerSearchPath, schemaCheck, toolchain, verbose}}},
{"list toolchains", { false, {context, debug, toolchain, verbose}}},
{"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 environment", { true, {}}},
};

try {
options.add_options("", {
{"positional", "", cxxopts::value<vector<string>>()},
solution, context, filter, generator,
solution, context, contextReplacement, filter, generator,
load, clayerSearchPath, missing, schemaCheck, noUpdateRte, output,
help, version, verbose, debug, dryRun, exportSuffix, toolchain, ymlOrder
});
Expand Down Expand Up @@ -213,6 +215,9 @@ 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 @@ -419,7 +424,7 @@ bool ProjMgr::RunConfigure(bool printConfig) {
return false;
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
return false;
}
// Get context pointers
Expand Down Expand Up @@ -512,7 +517,7 @@ bool ProjMgr::RunListPacks(void) {
}
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
return false;
}
vector<string> packs;
Expand All @@ -531,7 +536,7 @@ bool ProjMgr::RunListBoards(void) {
}
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
return false;
}
vector<string> boards;
Expand All @@ -553,7 +558,7 @@ bool ProjMgr::RunListDevices(void) {
}
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
return false;
}
vector<string> devices;
Expand All @@ -575,7 +580,7 @@ bool ProjMgr::RunListComponents(void) {
}
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
return false;
}
vector<string> components;
Expand All @@ -595,7 +600,7 @@ bool ProjMgr::RunListDependencies(void) {
return false;
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
return false;
}
vector<string> dependencies;
Expand Down Expand Up @@ -631,7 +636,7 @@ bool ProjMgr::RunListGenerators(void) {
return false;
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
return false;
}
// Get generators
Expand All @@ -653,7 +658,7 @@ bool ProjMgr::RunListLayers(void) {
}
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
return false;
}
// Get layers
Expand All @@ -678,7 +683,7 @@ bool ProjMgr::RunCodeGenerator(void) {
return false;
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
return false;
}
// Run code generator
Expand All @@ -696,7 +701,7 @@ bool ProjMgr::RunListToolchains(void) {
}
}
// Parse context selection
if (!m_worker.ParseContextSelection(m_context)) {
if (!m_worker.ParseContextSelection(m_context, m_contextReplacement)) {
return false;
}
vector<ToolchainItem> toolchains;
Expand Down
Loading

0 comments on commit 5e9b9ec

Please sign in to comment.