Skip to content

Commit

Permalink
Merge branch 'Open-CMSIS-Pack:main' into gendir-attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
brondani authored Dec 20, 2022
2 parents 5deb25f + 539fa1e commit 4fd874d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 59 deletions.
4 changes: 2 additions & 2 deletions tools/projmgr/include/ProjMgrWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ typedef std::vector<const ConnectItem*> ConnectPtrVec;
/**
* @brief connections collection item containing
* filename pointer
* layer type
* layer type pointer
* vector of ConnectItem pointers
*/
struct ConnectionsCollection {
const std::string* filename;
std::string type;
const std::string* type;
ConnectPtrVec connections;
};

Expand Down
118 changes: 62 additions & 56 deletions tools/projmgr/src/ProjMgrWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,48 +496,47 @@ bool ProjMgrWorker::DiscoverMatchingLayers(ContextItem& context) {
}
requiredLayerTypes.push_back(clayer.type);
}
if (requiredLayerTypes.empty()) {
// additional layers are not required
return true;
}
// collect generic clayers from loaded packs
StrVecMap genericClayers;
if (!CollectLayersFromPacks(context, genericClayers)) {
return false;
}
// clayers matching required types
StrVecMap matchedTypeClayers;
for (const auto& requiredType : requiredLayerTypes) {
if (genericClayers.find(requiredType) != genericClayers.end()) {
for (const auto& clayer : genericClayers.at(requiredType)) {
matchedTypeClayers[requiredType].push_back(clayer);
}
} else {
ProjMgrLogger::Debug("no clayer matches type '" + requiredType + "' for context '" + context.name + "'");
}
}

// debug message
ProjMgrLogger::Debug("validating connections for context '" + context.name + "'");

// parse matched type layers and collect connections
ConnectionsCollectionVec allConnections;
for (const auto& [type, clayers] : matchedTypeClayers) {
for (const auto& clayer : clayers) {
if (!m_parser->ParseGenericClayer(clayer, m_checkSchema)) {
return false;
}
const ClayerItem& clayerItem = m_parser->GetGenericClayers()[clayer];
if (type != clayerItem.type) {
ProjMgrLogger::Debug("clayer type '" + clayerItem.type + "' does not match type '" + type + "' in pack description");
StrVecMap matchedTypeClayers;

if (!requiredLayerTypes.empty()) {
// collect generic clayers from loaded packs
StrVecMap genericClayers;
if (!CollectLayersFromPacks(context, genericClayers)) {
return false;
}
// clayers matching required types
for (const auto& requiredType : requiredLayerTypes) {
if (genericClayers.find(requiredType) != genericClayers.end()) {
for (const auto& clayer : genericClayers.at(requiredType)) {
matchedTypeClayers[requiredType].push_back(clayer);
}
} else {
ProjMgrLogger::Debug("no clayer matches type '" + requiredType + "'");
}
ConnectionsCollection collection;
collection.filename = &clayerItem.path;
collection.type = type;
for (const auto& connect : clayerItem.connections) {
collection.connections.push_back(&connect);
}
// parse matched type layers and collect connections
for (const auto& [type, clayers] : matchedTypeClayers) {
for (const auto& clayer : clayers) {
if (!m_parser->ParseGenericClayer(clayer, m_checkSchema)) {
return false;
}
const ClayerItem& clayerItem = m_parser->GetGenericClayers()[clayer];
if (type != clayerItem.type) {
ProjMgrLogger::Debug("clayer type '" + clayerItem.type + "' does not match type '" + type + "' in pack description");
}
ConnectionsCollection collection;
collection.filename = &clayerItem.path;
collection.type = &type;
for (const auto& connect : clayerItem.connections) {
collection.connections.push_back(&connect);
}
allConnections.push_back(collection);
}
allConnections.push_back(collection);
}
}

Expand Down Expand Up @@ -576,7 +575,7 @@ bool ProjMgrWorker::DiscoverMatchingLayers(ContextItem& context) {
context.validConnections.push_back(combination);
for (const auto& [type, _] : matchedTypeClayers) {
for (const auto& item : combination) {
if (item.type == type) {
if (*item.type == type) {
ProjMgrUtils::PushBackUniquely(context.compatibleLayers[type], *item.filename);
}
}
Expand All @@ -588,26 +587,28 @@ bool ProjMgrWorker::DiscoverMatchingLayers(ContextItem& context) {
ProjMgrLogger::Debug("connections are " + string(result.valid ? "valid" : "invalid"));
}

// assess validation results
if (!context.compatibleLayers.empty()) {
for (const auto& [type, _] : matchedTypeClayers) {
if (context.compatibleLayers[type].size() == 1) {
// unique match
const auto& clayer = context.compatibleLayers[type].front();
ProjMgrLogger::Debug("clayer of type '" + type + "' was uniquely found:\n " + clayer);
} else if (context.compatibleLayers[type].size() > 1) {
// multiple matches
string msg = "multiple clayers match type '" + type + "':";
for (const auto& clayer : context.compatibleLayers[type]) {
msg += "\n " + clayer;
// assess generic layers validation results
if (!matchedTypeClayers.empty()) {
if (!context.compatibleLayers.empty()) {
for (const auto& [type, _] : matchedTypeClayers) {
if (context.compatibleLayers[type].size() == 1) {
// unique match
const auto& clayer = context.compatibleLayers[type].front();
ProjMgrLogger::Debug("clayer of type '" + type + "' was uniquely found:\n " + clayer);
} else if (context.compatibleLayers[type].size() > 1) {
// multiple matches
string msg = "multiple clayers match type '" + type + "':";
for (const auto& clayer : context.compatibleLayers[type]) {
msg += "\n " + clayer;
}
ProjMgrLogger::Debug(msg);
}
ProjMgrLogger::Debug(msg);
}
} else {
// no valid combination
ProjMgrLogger::Debug("no valid combination of clayers was found");
return false;
}
} else {
// no valid combination
ProjMgrLogger::Debug("no valid combination of clayers was found");
return false;
}

// print all valid configuration options
Expand All @@ -617,10 +618,14 @@ bool ProjMgrWorker::DiscoverMatchingLayers(ContextItem& context) {
for (const auto& combination : context.validConnections) {
bool hasConfigOption = false;
for (const auto& item : combination) {
if (!item.type->empty()) {
hasConfigOption = true;
configurationOptions[index][*item.type][*item.filename];
}
for (const auto& connect : item.connections) {
if (!connect->set.empty()) {
hasConfigOption = true;
configurationOptions[index][item.type][*item.filename].push_back(connect);
configurationOptions[index][*item.type][*item.filename].push_back(connect);
}
}
}
Expand Down Expand Up @@ -674,14 +679,15 @@ void ProjMgrWorker::CollectConnections(ContextItem& context, ConnectionsCollecti
// collect connections from project and layers
ConnectionsCollection projectCollection;
projectCollection.filename = &context.cproject->path;
projectCollection.type = &RteUtils::EMPTY_STRING;
for (const auto& connect : context.cproject->connections) {
projectCollection.connections.push_back(&connect);
}
connections.push_back(projectCollection);
for (const auto& [_, clayerItem] : context.clayers) {
ConnectionsCollection layerCollection;
layerCollection.filename = &clayerItem->path;
layerCollection.type = clayerItem->type;
layerCollection.type = &clayerItem->type;
for (const auto& connect : clayerItem->connections) {
layerCollection.connections.push_back(&connect);
}
Expand All @@ -694,7 +700,7 @@ ConnectionsCollectionMap ProjMgrWorker::ClassifyConnections(const ConnectionsCol
ConnectionsCollectionMap classifiedConnections;
for (const auto& collectionEntry : connections) {
// get type classification
const string& classifiedType = collectionEntry.type.empty() ? to_string(hash<string>{}(*collectionEntry.filename)) : collectionEntry.type;
const string& classifiedType = collectionEntry.type->empty() ? to_string(hash<string>{}(*collectionEntry.filename)) : *collectionEntry.type;
// group connections by config-id
map<string, ConnectPtrVec> connectionsMap;
for (const auto& connect : collectionEntry.connections) {
Expand Down
14 changes: 13 additions & 1 deletion tools/projmgr/test/src/ProjMgrUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,15 @@ debug csolution: multiple clayers match type 'Board':\n\
.*/ARM/RteTest_DFP/0.2.0/Layers/board3.clayer.yml\n\
debug csolution: clayer of type 'TestVariant' was uniquely found:\n\
.*/ARM/RteTest_DFP/0.2.0/Layers/testvariant.clayer.yml\n\
debug csolution: configuration match #1:\n\
Board: .*/ARM/RteTest_DFP/0.2.0/Layers/board1.clayer.yml\n\
TestVariant: .*/ARM/RteTest_DFP/0.2.0/Layers/testvariant.clayer.yml\n\
debug csolution: configuration match #2:\n\
Board: .*/ARM/RteTest_DFP/0.2.0/Layers/board2.clayer.yml\n\
TestVariant: .*/ARM/RteTest_DFP/0.2.0/Layers/testvariant.clayer.yml\n\
debug csolution: configuration match #3:\n\
Board: .*/ARM/RteTest_DFP/0.2.0/Layers/board3.clayer.yml\n\
TestVariant: .*/ARM/RteTest_DFP/0.2.0/Layers/testvariant.clayer.yml\n\
";

const string& errStr = streamRedirect.GetErrorString();
Expand Down Expand Up @@ -770,6 +779,9 @@ debug csolution: clayer of type 'Board' was uniquely found:\n\
.*/ARM/RteTest_DFP/0.2.0/Layers/board3.clayer.yml\n\
debug csolution: clayer of type 'TestVariant' was uniquely found:\n\
.*/ARM/RteTest_DFP/0.2.0/Layers/testvariant.clayer.yml\n\
debug csolution: configuration match #1:\n\
Board: .*/ARM/RteTest_DFP/0.2.0/Layers/board3.clayer.yml\n\
TestVariant: .*/ARM/RteTest_DFP/0.2.0/Layers/testvariant.clayer.yml\n\
";

const string& errStr = streamRedirect.GetErrorString();
Expand Down Expand Up @@ -798,8 +810,8 @@ TEST_F(ProjMgrUnitTests, ListLayersIncompatible) {
EXPECT_EQ(1, RunProjMgr(7, argv));

const string& expected = "\
debug csolution: no clayer matches type 'UnknownType' for context 'genericlayers.IncompatibleLayers\\+AnyBoard'\n\
debug csolution: validating connections for context 'genericlayers.IncompatibleLayers\\+AnyBoard'\n\
debug csolution: no clayer matches type 'UnknownType'\n\
debug csolution: clayer type 'DifferentFromDescriptionInPdsc' does not match type 'PdscType' in pack description\n\
debug csolution: validating combined connections:\n\
.*/TestLayers/genericlayers.cproject.yml\n\
Expand Down

0 comments on commit 4fd874d

Please sign in to comment.