Skip to content

Commit

Permalink
list yml ordered contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
grasci-arm authored Feb 21, 2023
1 parent 41efb28 commit 684a419
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 52 deletions.
1 change: 1 addition & 0 deletions tools/projmgr/include/ProjMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class ProjMgr {
bool m_updateRteFiles;
bool m_verbose;
bool m_debug;
bool m_ymlOrder;
GroupNode m_files;

bool RunConvert(void);
Expand Down
11 changes: 9 additions & 2 deletions tools/projmgr/include/ProjMgrWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class ProjMgrWorker {
* @param filter words to filter results
* @return true if executed successfully
*/
bool ListContexts(std::vector<std::string>& contexts, const std::string& filter = RteUtils::EMPTY_STRING);
bool ListContexts(std::vector<std::string>& contexts, const std::string& filter = RteUtils::EMPTY_STRING, const bool ymlOrder = false);

/**
* @brief list generators of a given context
Expand Down Expand Up @@ -400,6 +400,12 @@ class ProjMgrWorker {
*/
void GetContexts(std::map<std::string, ContextItem>* &contexts);

/**
* @brief get yml ordered contexts
* @param reference to contexts
*/
void GetYmlOrderedContexts(std::vector<std::string> &contexts);

/**
* @brief set output directory
* @param reference to output directory
Expand Down Expand Up @@ -474,6 +480,7 @@ class ProjMgrWorker {
ProjMgrKernel* m_kernel = nullptr;
RteGlobalModel* m_model = nullptr;
std::list<RtePackage*> m_loadedPacks;
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;
Expand Down Expand Up @@ -526,7 +533,7 @@ class ProjMgrWorker {
bool AddFile(const FileNode& src, std::vector<FileNode>& dst, ContextItem& context, const std::string root);
bool AddComponent(const ComponentItem& src, const std::string& layer, std::vector<std::pair<ComponentItem, std::string>>& dst, TypePair type);
static std::set<std::string> SplitArgs(const std::string& args, const std::string& delimiter = " ");
static void ApplyFilter(const std::set<std::string>& origin, const std::set<std::string>& filter, std::set<std::string>& result);
static void ApplyFilter(const std::vector<std::string>& origin, const std::set<std::string>& filter, std::vector<std::string>& result);
static bool FullMatch(const std::set<std::string>& installed, const std::set<std::string>& required);
bool AddRequiredComponents(ContextItem& context);
void GetDeviceItem(const std::string& element, DeviceItem& device) const;
Expand Down
19 changes: 12 additions & 7 deletions tools/projmgr/src/ProjMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,15 @@ int ProjMgr::RunProjMgr(int argc, char **argv) {
cxxopts::Option generator("g,generator", "Code generator identifier", cxxopts::value<string>());
cxxopts::Option load("l,load", "Set policy for packs loading [latest|all|required]", cxxopts::value<string>());
cxxopts::Option clayerSearchPath("L,clayer-path", "Set search path for external clayers", cxxopts::value<string>());
cxxopts::Option missing( "m,missing", "List only required packs that are missing in the pack repository", cxxopts::value<bool>()->default_value("false"));
cxxopts::Option schemaCheck( "n,no-check-schema", "Skip schema check", cxxopts::value<bool>()->default_value("false"));
cxxopts::Option noUpdateRte( "U,no-update-rte", "Skip creation of RTE directory and files", cxxopts::value<bool>()->default_value("false"));
cxxopts::Option missing("m,missing", "List only required packs that are missing in the pack repository", cxxopts::value<bool>()->default_value("false"));
cxxopts::Option schemaCheck("n,no-check-schema", "Skip schema check", cxxopts::value<bool>()->default_value("false"));
cxxopts::Option noUpdateRte("U,no-update-rte", "Skip creation of RTE directory and files", cxxopts::value<bool>()->default_value("false"));
cxxopts::Option output("o,output", "Output directory", cxxopts::value<string>());
cxxopts::Option version("V,version", "Print version");
cxxopts::Option verbose("v,verbose", "Enable verbose messages", cxxopts::value<bool>()->default_value("false"));
cxxopts::Option debug("d,debug", "Enable debug messages", cxxopts::value<bool>()->default_value("false"));
cxxopts::Option exportSuffix("e,export", "Set suffix for exporting <context><suffix>.cprj retaining only specified versions", cxxopts::value<string>());
cxxopts::Option ymlOrder("yml-order", "Preserve order as specified in input yml", cxxopts::value<bool>()->default_value("false"));

// command options dictionary
map<string, vector<cxxopts::Option>> optionsDict = {
Expand All @@ -123,7 +124,7 @@ int ProjMgr::RunProjMgr(int argc, char **argv) {
{"list devices", {solution, context, filter, load, verbose, debug, schemaCheck}},
{"list components", {solution, context, filter, load, verbose, debug, schemaCheck}},
{"list dependencies", {solution, context, filter, load, verbose, debug, schemaCheck}},
{"list contexts", {solution, filter, verbose, debug, schemaCheck}},
{"list contexts", {solution, filter, verbose, debug, schemaCheck, ymlOrder}},
{"list generators", {solution, context, load, verbose, debug, schemaCheck}},
{"list layers", {solution, context, load, verbose, debug, schemaCheck, clayerSearchPath}},
{"list toolchains", {solution, verbose, debug,}},
Expand All @@ -134,7 +135,7 @@ int ProjMgr::RunProjMgr(int argc, char **argv) {
{"positional", "", cxxopts::value<vector<string>>()},
solution, context, filter, generator,
load, clayerSearchPath, missing, schemaCheck, noUpdateRte, output,
help, version, verbose, debug, exportSuffix
help, version, verbose, debug, exportSuffix, ymlOrder
});
options.parse_positional({ "positional" });

Expand All @@ -147,6 +148,7 @@ int ProjMgr::RunProjMgr(int argc, char **argv) {
manager.m_worker.SetVerbose(manager.m_verbose);
manager.m_debug = parseResult.count("d");
manager.m_worker.SetDebug(manager.m_debug);
manager.m_ymlOrder = parseResult.count("yml-order");

vector<string> positionalArguments;
if (parseResult.count("positional")) {
Expand Down Expand Up @@ -361,10 +363,13 @@ bool ProjMgr::RunConvert(void) {
if (!m_worker.InitializeModel()) {
return false;
}
vector<string> orderedContexts;
m_worker.GetYmlOrderedContexts(orderedContexts);
// Process contexts
bool error = false;
vector<ContextItem*> processedContexts;
for (auto& [contextName, contextItem] : *contexts) {
for (auto& contextName : orderedContexts) {
auto& contextItem = (*contexts)[contextName];
if (!m_worker.IsContextSelected(contextName)) {
continue;
}
Expand Down Expand Up @@ -529,7 +534,7 @@ bool ProjMgr::RunListContexts(void) {
return false;
}
vector<string> contexts;
if (!m_worker.ListContexts(contexts, m_filter)) {
if (!m_worker.ListContexts(contexts, m_filter, m_ymlOrder)) {
ProjMgrLogger::Error("processing contexts list failed");
return false;
}
Expand Down
79 changes: 45 additions & 34 deletions tools/projmgr/src/ProjMgrWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ bool ProjMgrWorker::AddContext(ProjMgrParser& parser, ContextDesc& descriptor, c
}
}
}

ProjMgrUtils::PushBackUniquely(m_ymlOrderedContexts, context.name);
m_contexts[context.name] = context;
}
return true;
Expand All @@ -176,6 +176,10 @@ void ProjMgrWorker::GetContexts(map<string, ContextItem>* &contexts) {
contexts = m_contextsPtr;
}

void ProjMgrWorker::GetYmlOrderedContexts(vector<string> &contexts) {
contexts = m_ymlOrderedContexts;
}

void ProjMgrWorker::SetOutputDir(const std::string& outputDir) {
m_outputDir = outputDir;
}
Expand Down Expand Up @@ -1222,7 +1226,7 @@ bool ProjMgrWorker::ProcessComponents(ContextItem& context) {
}
// Filter components
RteComponentMap filteredComponents;
set<string> filteredIds;
vector<string> filteredIds;
string componentDescriptor = item.component;

set<string> filterSet;
Expand All @@ -1234,7 +1238,8 @@ bool ProjMgrWorker::ProcessComponents(ContextItem& context) {
filterSet = SplitArgs(componentDescriptor);
}

ApplyFilter(componentIds, filterSet, filteredIds);
vector<string> componentIdVec(componentIds.begin(), componentIds.end());
ApplyFilter(componentIdVec, filterSet, filteredIds);
for (const auto& filteredId : filteredIds) {
filteredComponents[filteredId] = componentMap[filteredId];
}
Expand Down Expand Up @@ -2200,7 +2205,7 @@ bool ProjMgrWorker::ProcessContext(ContextItem& context, bool loadGpdsc, bool re
return true;
}

void ProjMgrWorker::ApplyFilter(const set<string>& origin, const set<string>& filter, set<string>& result) {
void ProjMgrWorker::ApplyFilter(const vector<string>& origin, const set<string>& filter, vector<string>& result) {
result.clear();
for (const auto& item : origin) {
bool match = true;
Expand All @@ -2214,7 +2219,7 @@ void ProjMgrWorker::ApplyFilter(const set<string>& origin, const set<string>& fi
}
}
if (match) {
result.insert(item);
ProjMgrUtils::PushBackUniquely(result, item);
}
}
}
Expand Down Expand Up @@ -2299,16 +2304,17 @@ bool ProjMgrWorker::ListPacks(vector<string>&packs, bool missingPacks, const str
reqOk = false;
}
}
vector<string> packsVec(packsSet.begin(), packsSet.end());
if (!filter.empty()) {
set<string> filteredPacks;
ApplyFilter(packsSet, SplitArgs(filter), filteredPacks);
vector<string> filteredPacks;
ApplyFilter(packsVec, SplitArgs(filter), filteredPacks);
if (filteredPacks.empty()) {
ProjMgrLogger::Error("no pack was found with filter '" + filter + "'");
return false;
}
packsSet = filteredPacks;
packsVec = filteredPacks;
}
packs.assign(packsSet.begin(), packsSet.end());
packs.assign(packsVec.begin(), packsVec.end());
return reqOk;
}

Expand All @@ -2332,16 +2338,17 @@ bool ProjMgrWorker::ListBoards(vector<string>& boards, const string& filter) {
ProjMgrLogger::Error("no installed board was found");
return false;
}
vector<string> boardsVec(boardsSet.begin(), boardsSet.end());
if (!filter.empty()) {
set<string> matchedBoards;
ApplyFilter(boardsSet, SplitArgs(filter), matchedBoards);
vector<string> matchedBoards;
ApplyFilter(boardsVec, SplitArgs(filter), matchedBoards);
if (matchedBoards.empty()) {
ProjMgrLogger::Error("no board was found with filter '" + filter + "'");
return false;
}
boardsSet = matchedBoards;
boardsVec = matchedBoards;
}
boards.assign(boardsSet.begin(), boardsSet.end());
boards.assign(boardsVec.begin(), boardsVec.end());
return true;
}

Expand Down Expand Up @@ -2372,16 +2379,17 @@ bool ProjMgrWorker::ListDevices(vector<string>& devices, const string& filter) {
ProjMgrLogger::Error("no installed device was found");
return false;
}
vector<string> devicesVec(devicesSet.begin(), devicesSet.end());
if (!filter.empty()) {
set<string> matchedDevices;
ApplyFilter(devicesSet, SplitArgs(filter), matchedDevices);
vector<string> matchedDevices;
ApplyFilter(devicesVec, SplitArgs(filter), matchedDevices);
if (matchedDevices.empty()) {
ProjMgrLogger::Error("no device was found with filter '" + filter + "'");
return false;
}
devicesSet = matchedDevices;
devicesVec = matchedDevices;
}
devices.assign(devicesSet.begin(), devicesSet.end());
devices.assign(devicesVec.begin(), devicesVec.end());
return true;
}

Expand Down Expand Up @@ -2423,16 +2431,17 @@ bool ProjMgrWorker::ListComponents(vector<string>& components, const string& fil
componentMap[componentId] = component.second;
}
}
vector<string> componentIdsVec(componentIds.begin(), componentIds.end());
if (!filter.empty()) {
set<string> filteredIds;
ApplyFilter(componentIds, SplitArgs(filter), filteredIds);
vector<string> filteredIds;
ApplyFilter(componentIdsVec, SplitArgs(filter), filteredIds);
if (filteredIds.empty()) {
ProjMgrLogger::Error("no component was found with filter '" + filter + "'");
return false;
}
componentIds = filteredIds;
componentIdsVec = filteredIds;
}
for (const auto& componentId : componentIds) {
for (const auto& componentId : componentIdsVec) {
components.push_back(componentId + " (" + ProjMgrUtils::GetPackageID(componentMap[componentId]->GetPackage()) + ")");
}
return true;
Expand All @@ -2455,16 +2464,17 @@ bool ProjMgrWorker::ListDependencies(vector<string>& dependencies, const string&
}
}
}
vector<string> dependenciesVec(dependenciesSet.begin(), dependenciesSet.end());
if (!filter.empty()) {
set<string> filteredDependencies;
ApplyFilter(dependenciesSet, SplitArgs(filter), filteredDependencies);
vector<string> filteredDependencies;
ApplyFilter(dependenciesVec, SplitArgs(filter), filteredDependencies);
if (filteredDependencies.empty()) {
ProjMgrLogger::Error("no unresolved dependency was found with filter '" + filter + "'");
return false;
}
dependenciesSet = filteredDependencies;
dependenciesVec = filteredDependencies;
}
dependencies.assign(dependenciesSet.begin(), dependenciesSet.end());
dependencies.assign(dependenciesVec.begin(), dependenciesVec.end());
return true;
}

Expand Down Expand Up @@ -2500,24 +2510,25 @@ bool ProjMgrWorker::FormatValidationResults(set<string>& results, const ContextI
return true;
}

bool ProjMgrWorker::ListContexts(vector<string>& contexts, const string& filter) {
bool ProjMgrWorker::ListContexts(vector<string>& contexts, const string& filter, const bool ymlOrder) {
if (m_contexts.empty()) {
return false;
}
set<string>contextsSet;
for (auto& context : m_contexts) {
contextsSet.insert(context.first);
}
vector<string> contextsVec = m_ymlOrderedContexts;
if (!filter.empty()) {
set<string> filteredContexts;
ApplyFilter(contextsSet, SplitArgs(filter), filteredContexts);
vector<string> filteredContexts;
ApplyFilter(contextsVec, SplitArgs(filter), filteredContexts);
if (filteredContexts.empty()) {
ProjMgrLogger::Error("no context was found with filter '" + filter + "'");
return false;
}
contextsSet = filteredContexts;
contextsVec = filteredContexts;
}
contexts.assign(contextsVec.begin(), contextsVec.end());

if (!ymlOrder) {
std::sort(contexts.begin(), contexts.end());
}
contexts.assign(contextsSet.begin(), contextsSet.end());
return true;
}

Expand Down
10 changes: 9 additions & 1 deletion tools/projmgr/src/ProjMgrYamlEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ ProjMgrYamlCbuild::ProjMgrYamlCbuild(YAML::Node node, const vector<ContextItem*>
const string& csolutionFilename = fs::relative(parser.GetCsolution().path, directory, ec).generic_string();
SetNodeValue(node[YAML_CSOLUTION], csolutionFilename);

for (const auto& [cprojectName, cproject] : parser.GetCprojects()) {
const auto& cprojects = parser.GetCprojects();
const auto& csolution = parser.GetCsolution();

for (const auto& cprojectFile : csolution.cprojects) {
auto itr = std::find_if(cprojects.begin(), cprojects.end(),
[&](const pair<std::string, CprojectItem>& elem) {
return (elem.first.find(fs::path(cprojectFile).filename().string()) != std::string::npos);
});
auto cproject = itr->second;
YAML::Node cprojectNode;
const string& cprojectFilename = fs::relative(cproject.path, directory, ec).generic_string();
SetNodeValue(cprojectNode[YAML_CPROJECT], cprojectFilename);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
build-idx:
csolution: ../data/TestSolution/test.csolution.yml
cprojects:
- cproject: ../data/TestSolution/TestProject1/test1.cproject.yml
- cproject: ../data/TestSolution/TestProject2/test2.cproject.yml
- cproject: ../data/TestSolution/TestProject1/test1.cproject.yml
cbuilds:
- cbuild: test1.Debug+CM0.cbuild.yml
- cbuild: test1.Release+CM0.cbuild.yml
- cbuild: test2.Debug+CM0.cbuild.yml
- cbuild: test2.Debug+CM3.cbuild.yml
- cbuild: test1.Debug+CM0.cbuild.yml
- cbuild: test1.Release+CM0.cbuild.yml
4 changes: 2 additions & 2 deletions tools/projmgr/test/data/TestSolution/test.csolution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ solution:
- pack: ARM::[email protected]

projects:
- project: ./TestProject1/test1.cproject.yml
for-context: +CM0
- project: ./TestProject2/test2.cproject.yml
not-for-context: .Release
- project: ./TestProject1/test1.cproject.yml
for-context: +CM0

define:
- DEF-solution
Expand Down
Loading

0 comments on commit 684a419

Please sign in to comment.