Skip to content

Commit 0a36fb9

Browse files
authored
[csolution-rpc] Extend PackReference with optional locked and missing nodes
1 parent 0b16215 commit 0a36fb9

7 files changed

Lines changed: 71 additions & 7 deletions

File tree

tools/projmgr/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ include(FetchContent)
2424
FetchContent_Declare(
2525
rpc-interface
2626
DOWNLOAD_EXTRACT_TIMESTAMP ON
27-
URL https://github.com/Open-CMSIS-Pack/csolution-rpc/releases/download/v0.0.10/csolution-rpc.zip
28-
URL_HASH SHA256=246e1f6e5c1a6e269aeadf37f6bf62897c5bb9d374b7fbfdf0e19af61449379e
27+
URL https://github.com/Open-CMSIS-Pack/csolution-rpc/releases/download/v0.0.11/csolution-rpc.zip
28+
URL_HASH SHA256=1999e1a158922c319626959384643a8490bac4a716a88fa8868b2fd6701097df
2929
)
3030
FetchContent_MakeAvailable(rpc-interface)
3131

tools/projmgr/include/ProjMgrWorker.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,17 @@ struct ToolchainItem {
9696
* pack information pack,
9797
* path to pack path,
9898
* origin file,
99+
* selected-by entry,
100+
* resolved pack identifier,
101+
* missing flag,
99102
*/
100103
struct PackageItem {
101104
PackInfo pack;
102105
std::string path;
103106
std::string origin;
104107
std::string selectedBy;
105108
std::string resolvedTo;
109+
bool missing = false;
106110
};
107111

108112
/**
@@ -581,6 +585,7 @@ struct ContextItem {
581585
std::set<RteComponentInstance*> unresolvedComponents;
582586
StrMap availablePackVersions;
583587
StrMap absPathSequences;
588+
StrVec lockedPacks;
584589
};
585590

586591
/**

tools/projmgr/src/ProjMgrRpcServer.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,24 +445,32 @@ PackReferenceVector RpcHandler::CollectPackReferences(const string& context) {
445445
PackReferenceVector packRefs;
446446
auto contextItem = GetContext(context);
447447
for(const auto& packItem : contextItem.packRequirements) {
448-
const auto& packId = packItem.resolvedTo;
449-
450448
RpcArgs::PackReference packRef;
451449
packRef.pack = packItem.selectedBy;
452450
if(!packItem.path.empty()) {
453451
packRef.resolvedPack = packItem.selectedBy;
454452
packRef.path = packItem.path;
455-
} else if(!packId.empty()) {
456-
packRef.resolvedPack = packId;
453+
} else if(!packItem.resolvedTo.empty()) {
454+
packRef.resolvedPack = packItem.resolvedTo;
457455
}
458456
packRef.origin = packItem.origin;
459457
packRef.selected = true; // initially pack is selected;
458+
const auto& packId = packItem.pack.vendor + "::" + packItem.pack.name + "@" + packItem.pack.version;
460459
if(packItem.path.empty() && !packId.empty()) {
461460
const auto availableVersionIt = contextItem.availablePackVersions.find(packId);
462461
if(availableVersionIt != contextItem.availablePackVersions.end() && !availableVersionIt->second.empty()) {
463462
packRef.upgrade = availableVersionIt->second;
464463
}
465464
}
465+
// set optional 'locked' pack identifier if pack is not resolved and locked pack identifier is tracked
466+
if (packItem.resolvedTo.empty() && find(contextItem.lockedPacks.begin(),
467+
contextItem.lockedPacks.end(), packId) != contextItem.lockedPacks.end()) {
468+
packRef.locked = packId;
469+
}
470+
// set optional 'missing' if pack is not found
471+
if (packItem.missing) {
472+
packRef.missing = true;
473+
}
466474
packRefs.push_back(packRef);
467475
}
468476
return packRefs;

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ bool ProjMgrWorker::CollectRequiredPdscFiles(ContextItem& context, const std::st
411411
auto pdsc = m_kernel->GetEffectivePdscFile(attributes);
412412
const string& pdscFile = pdsc.second;
413413
packItem.resolvedTo = pdsc.first; // store resolved ID if any
414+
packItem.missing = pdsc.first.empty();
414415
if (pdscFile.empty()) {
415416
if (!bPackFilter) {
416417
std::string packageName =
@@ -1861,9 +1862,12 @@ void ProjMgrWorker::ResolvePackRequirement(ContextItem& context, const PackItem&
18611862
if (!locked.empty()) {
18621863
// TODO: When wildcards will be fully stored in cbuild-pack there may be multiple matches
18631864
const auto& lockedId = locked.front();
1865+
CollectionUtils::PushBackUniquely(context.lockedPacks, lockedId);
18641866
if (lockedId != packId) {
18651867
// Save available version if different from locked
1866-
context.availablePackVersions[lockedId] = package.pack.version;
1868+
if (!packId.empty()) {
1869+
context.availablePackVersions[lockedId] = package.pack.version;
1870+
}
18671871
// Keep the locked pack
18681872
packId = lockedId;
18691873
package.pack.version = RtePackage::VersionFromId(lockedId);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cbuild-pack:
2+
resolved-packs:
3+
- resolved-pack: ARM::RteTest_DFP@0.1.0
4+
selected-by-pack:
5+
- ARM::RteTest_DFP
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json
2+
3+
solution:
4+
target-types:
5+
- type: CM0
6+
device: RteTest_ARMCM0
7+
packs:
8+
- pack: ARM::RteTest_DFP
9+
projects:
10+
- project: ./project_with_dfp_components.cproject.yml

tools/projmgr/test/src/ProjMgrRpcTests.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,38 @@ TEST_F(ProjMgrRpcTests, RpcGetUsedItemsLocked) {
10891089
EXPECT_EQ(packs[0]["upgrade"], "0.2.0");
10901090
}
10911091

1092+
TEST_F(ProjMgrRpcTests, PackReferenceLocked) {
1093+
string context = "project_with_dfp_components+CM0";
1094+
vector<string> contextList = { context };
1095+
auto requests = CreateLoadRequests("/TestSolution/PackLocking/pack_reference_locked.csolution.yml", "", contextList);
1096+
requests += FormatRequest(3, "GetUsedItems", json({ { "context", context } }));
1097+
const auto& responses = RunRpcMethods(requests);
1098+
EXPECT_TRUE(responses[2]["result"]["success"]);
1099+
auto packs = responses[2]["result"]["packs"];
1100+
EXPECT_EQ(packs.size(), 1);
1101+
// Locked field should be present as string containing locked packId
1102+
EXPECT_TRUE(packs[0].contains("locked"));
1103+
EXPECT_EQ(packs[0]["locked"], "ARM::RteTest_DFP@0.1.0");
1104+
}
1105+
1106+
TEST_F(ProjMgrRpcTests, PackReferenceMissing) {
1107+
string context = "project+Miss";
1108+
vector<string> contextList = { context };
1109+
auto requests = CreateLoadRequests("/TestSolution/PackMissing/missing_pack.csolution.yml", "", contextList);
1110+
requests += FormatRequest(3, "GetUsedItems", json({{ "context", context }}));
1111+
const auto& responses = RunRpcMethods(requests);
1112+
EXPECT_TRUE(responses[2]["result"]["success"]);
1113+
auto packs = responses[2]["result"]["packs"];
1114+
// Verify missing field for unresolved packs
1115+
for(const auto& pack : packs) {
1116+
if(!pack.contains("resolvedPack")) {
1117+
EXPECT_TRUE(pack.contains("missing"));
1118+
EXPECT_TRUE(pack["missing"].is_boolean());
1119+
EXPECT_TRUE(pack["missing"].get<bool>());
1120+
}
1121+
}
1122+
}
1123+
10921124
TEST_F(ProjMgrRpcTests, RpcGetPacksInfoSimple) {
10931125
string context = "selectable+CM0";
10941126
vector<string> contextList = {

0 commit comments

Comments
 (0)