Skip to content

Commit d4df01d

Browse files
committed
[projmgr] Handle LoadSolution method request with activeTarget parameter
1 parent 0709443 commit d4df01d

File tree

6 files changed

+36
-21
lines changed

6 files changed

+36
-21
lines changed

tools/projmgr/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ include(FetchContent)
1717
FetchContent_Declare(
1818
rpc-interface
1919
DOWNLOAD_EXTRACT_TIMESTAMP ON
20-
URL https://github.com/Open-CMSIS-Pack/csolution-rpc/releases/download/v0.0.3/csolution-rpc.zip
21-
URL_HASH SHA256=edc762373b3b7dad5b966ecb271f03866b12841675e0967a809c10c9883f29f4
20+
URL https://github.com/brondani/csolution-rpc/releases/download/v0.0.4/csolution-rpc.zip
21+
URL_HASH SHA256=643ab30d25f47b55735bc6fecd3622ad1c7619d8fac901e2b19cd594a01df8b2
2222
)
2323
FetchContent_MakeAvailable(rpc-interface)
2424

tools/projmgr/include/ProjMgr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ class ProjMgr {
6565
/**
6666
* @brief load solution
6767
* @param path to <solution>.csolution.yml file
68+
* @param active target set in the format <target-type>[@<set>]
6869
* @return processing status
6970
*/
70-
bool LoadSolution(const std::string& csolution);
71+
bool LoadSolution(const std::string& csolution, const std::string& activeTargetSet);
7172

7273
protected:
7374
/**

tools/projmgr/src/ProjMgr.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,15 +1286,20 @@ void ProjMgr::Clear() {
12861286
ProjMgrLogger::Get().Clear();
12871287
}
12881288

1289-
bool ProjMgr::LoadSolution(const std::string& csolution) {
1289+
bool ProjMgr::LoadSolution(const std::string& csolution, const std::string& activeTargetSet) {
12901290
Clear();
12911291

12921292
m_csolutionFile = csolution;
12931293
m_rootDir = RteUtils::ExtractFilePath(m_csolutionFile, false);
1294-
1295-
m_contextSet = true;
12961294
m_updateRteFiles = false;
12971295

1296+
if (activeTargetSet.empty()) {
1297+
// fallback to 'context-set' for backward compatibility
1298+
m_contextSet = true;
1299+
} else {
1300+
m_activeTargetSet = activeTargetSet;
1301+
}
1302+
12981303
if (!PopulateContexts()) {
12991304
return false;
13001305
}

tools/projmgr/src/ProjMgrRpcServer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class RpcHandler : public RpcMethods {
8181
RpcArgs::SuccessResult Apply(const string& context) override;
8282
RpcArgs::SuccessResult Resolve(const string& context) override;
8383
RpcArgs::SuccessResult LoadPacks(void) override;
84-
RpcArgs::SuccessResult LoadSolution(const string& solution) override;
84+
RpcArgs::SuccessResult LoadSolution(const string& solution, const string& activeTarget) override;
8585
RpcArgs::UsedItems GetUsedItems(const string& context) override;
8686
RpcArgs::PacksInfo GetPacksInfo(const string& context) override;
8787
RpcArgs::DeviceList GetDeviceList(const string& context, const string& namePattern, const string& vendor) override;
@@ -201,6 +201,7 @@ RpcArgs::GetVersionResult RpcHandler::GetVersion(void) {
201201
RpcArgs::GetVersionResult res = {{true}};
202202
res.message = string("Running ") + INTERNAL_NAME + " " + VERSION_STRING;
203203
res.version = VERSION_STRING;
204+
res.apiVersion = RPC_API_VERSION;
204205
return res;
205206
}
206207

@@ -279,7 +280,7 @@ RpcArgs::SuccessResult RpcHandler::LoadPacks(void) {
279280
return result;
280281
}
281282

282-
RpcArgs::SuccessResult RpcHandler::LoadSolution(const string& solution) {
283+
RpcArgs::SuccessResult RpcHandler::LoadSolution(const string& solution, const string& activeTarget) {
283284
RpcArgs::SuccessResult result = {false};
284285
const auto csolutionFile = RteFsUtils::MakePathCanonical(solution);
285286
if (!regex_match(csolutionFile, regex(".*\\.csolution\\.(yml|yaml)"))) {
@@ -290,7 +291,7 @@ RpcArgs::SuccessResult RpcHandler::LoadSolution(const string& solution) {
290291
result.message = "Packs must be loaded before loading solution";
291292
return result;
292293
}
293-
result.success = m_solutionLoaded = m_manager.LoadSolution(csolutionFile);
294+
result.success = m_solutionLoaded = m_manager.LoadSolution(csolutionFile, activeTarget);
294295
if (!m_solutionLoaded) {
295296
result.message = "failed to load and process solution " + csolutionFile;
296297
}

tools/projmgr/test/data/TestRpc/minimal.csolution.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ solution:
77
target-types:
88
- type: TestHW
99
device: RteTest_ARMCM4_NOFP
10+
target-set:
11+
- set:
12+
images:
13+
- project-context: minimal
1014

1115
projects:
1216
- project: minimal.cproject.yml

tools/projmgr/test/src/ProjMgrRpcTests.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ class ProjMgrRpcTests : public ProjMgr, public ::testing::Test {
2626
vector<json> RunRpcMethods(const string& strIn);
2727
string RunRpcMethodsWithContent(const string& strIn);
2828

29-
string CreateLoadRequests(const string& solution, const vector<string>& contextList = RteUtils::EMPTY_STRING_VECTOR);
29+
string CreateLoadRequests(const string& solution,
30+
const string& activeTarget = RteUtils::EMPTY_STRING,
31+
const vector<string>& contextList = RteUtils::EMPTY_STRING_VECTOR
32+
);
3033

3134
};
3235

@@ -41,12 +44,12 @@ string ProjMgrRpcTests::FormatRequest(const int id, const string& method, const
4144
return request.dump();
4245
}
4346

44-
string ProjMgrRpcTests::CreateLoadRequests(const string& solution, const vector<string>& contextList)
47+
string ProjMgrRpcTests::CreateLoadRequests(const string& solution, const string& activeTarget, const vector<string>& contextList)
4548
{
4649
string loadSolutionRequest;
4750
if(!solution.empty()) {
4851
auto csolutionPath = testinput_folder + solution;
49-
loadSolutionRequest = FormatRequest(2, "LoadSolution", json({{ "solution", csolutionPath }}));
52+
loadSolutionRequest = FormatRequest(2, "LoadSolution", json({{ "solution", csolutionPath }, { "activeTarget", activeTarget } }));
5053
if(!contextList.empty()) {
5154
YAML::Node cbuildset;
5255
cbuildset["cbuild-set"]["generated-by"] = "ProjMrgUnitTests";
@@ -110,6 +113,7 @@ TEST_F(ProjMgrRpcTests, RpcGetVersion) {
110113
EXPECT_EQ(1, responses[0]["id"]);
111114
EXPECT_TRUE(responses[0]["result"]["success"]);
112115
EXPECT_EQ(string(VERSION_STRING), responses[0]["result"]["version"]);
116+
EXPECT_EQ(string(RPC_API_VERSION), responses[0]["result"]["apiVersion"]);
113117
}
114118

115119
TEST_F(ProjMgrRpcTests, RpcGetVersionWithContent) {
@@ -119,7 +123,7 @@ TEST_F(ProjMgrRpcTests, RpcGetVersionWithContent) {
119123
}
120124

121125
TEST_F(ProjMgrRpcTests, RpcLoadSolution) {
122-
const auto& requests = CreateLoadRequests("/TestRpc/minimal.csolution.yml");
126+
const auto& requests = CreateLoadRequests("/TestRpc/minimal.csolution.yml", "TestHW");
123127
const auto& responses = RunRpcMethods(requests);
124128
EXPECT_TRUE(responses[0]["result"]["success"]);
125129
EXPECT_TRUE(responses[1]["result"]["success"]);
@@ -145,7 +149,7 @@ TEST_F(ProjMgrRpcTests, RpcLoadNotSolution) {
145149

146150
TEST_F(ProjMgrRpcTests, RpcLoadSolutionNoPacks) {
147151
auto csolutionPath = testinput_folder + "/TestRpc/minimal.csolution.yml";
148-
const auto& requests = FormatRequest(1, "LoadSolution", json({ { "solution", csolutionPath } }));
152+
const auto& requests = FormatRequest(1, "LoadSolution", json({ { "solution", csolutionPath }, { "activeTarget", "TestHW" } }));
149153
const auto& responses = RunRpcMethods(requests);
150154
EXPECT_FALSE(responses[0]["result"]["success"]);
151155
string msg = responses[0]["result"]["message"];
@@ -207,7 +211,7 @@ TEST_F(ProjMgrRpcTests, RpcDeviceListContext) {
207211
vector<string> contextList = {
208212
context
209213
};
210-
auto requests = CreateLoadRequests("/Validation/dependencies.csolution.yml", contextList);
214+
auto requests = CreateLoadRequests("/Validation/dependencies.csolution.yml", "", contextList);
211215
// all devices
212216
requests += FormatRequest(3, "GetDeviceList", json({{"context", "selectable+CM0"},{ "namePattern", ""}, {"vendor", ""}}));
213217
requests += FormatRequest(4, "GetDeviceList", json({{"context", "selectable+CM0"},{ "namePattern", "*Dual*"}, {"vendor", ""}}));
@@ -336,7 +340,7 @@ TEST_F(ProjMgrRpcTests, RpcBoardListContext) {
336340
vector<string> contextList = {
337341
context
338342
};
339-
auto requests = CreateLoadRequests("/Validation/dependencies.csolution.yml", contextList);
343+
auto requests = CreateLoadRequests("/Validation/dependencies.csolution.yml", "", contextList);
340344

341345
// all boards
342346
requests += FormatRequest(2, "GetBoardList", json({{"context", "selectable+CM0"},{ "namePattern", ""}, {"vendor", ""}}));
@@ -442,7 +446,7 @@ TEST_F(ProjMgrRpcTests, RpcValidateComponents) {
442446
"incompatible+CM0",
443447
"incompatible-variant+CM0",
444448
};
445-
auto requests = CreateLoadRequests("/Validation/dependencies.csolution.yml", contextList);
449+
auto requests = CreateLoadRequests("/Validation/dependencies.csolution.yml", "", contextList);
446450
int id = 3;
447451
for (const auto& context : contextList) {
448452
requests += FormatRequest(id++, "ValidateComponents", json({ { "context", context } }));
@@ -497,7 +501,7 @@ TEST_F(ProjMgrRpcTests, RpcResolveComponents) {
497501
vector<string> contextList = {
498502
context
499503
};
500-
auto requests = CreateLoadRequests("/Validation/dependencies.csolution.yml", contextList);
504+
auto requests = CreateLoadRequests("/Validation/dependencies.csolution.yml", "", contextList);
501505
requests += FormatRequest(3, "ValidateComponents", json({{ "context", context }}));
502506
requests += FormatRequest(4, "Resolve", json({{ "context", context }}));
503507
requests += FormatRequest(5, "ValidateComponents", json({{ "context", context }}));
@@ -528,7 +532,7 @@ TEST_F(ProjMgrRpcTests, RpcSelectComponent) {
528532
param["count"] = 1;
529533
param["options"] = json::object();
530534

531-
auto requests = CreateLoadRequests("/Validation/dependencies.csolution.yml", contextList);
535+
auto requests = CreateLoadRequests("/Validation/dependencies.csolution.yml", "", contextList);
532536
requests += FormatRequest(3, "ValidateComponents", json({{ "context", context }}));
533537
requests += FormatRequest(4, "GetComponentsTree", json({{ "context", context }, {"all", false}}));
534538
requests += FormatRequest(5, "SelectComponent", param);
@@ -561,7 +565,7 @@ TEST_F(ProjMgrRpcTests, RpcSelectVariant) {
561565
param["id"] = "ARM::RteTest:Dependency:Variant";
562566
param["variant"] = "Compatible";
563567

564-
auto requests = CreateLoadRequests("/Validation/dependencies.csolution.yml", contextList);
568+
auto requests = CreateLoadRequests("/Validation/dependencies.csolution.yml", "", contextList);
565569
requests += FormatRequest(3, "ValidateComponents", json({{ "context", context }}));
566570
requests += FormatRequest(4, "SelectVariant", param);
567571
requests += FormatRequest(5, "ValidateComponents", json({{ "context", context }}));
@@ -598,7 +602,7 @@ TEST_F(ProjMgrRpcTests, RpcGetUsedItems) {
598602
param["count"] = 1;
599603
RpcArgs::to_json(param["options"], opt);
600604

601-
auto requests = CreateLoadRequests("/Validation/dependencies.csolution.yml", contextList);
605+
auto requests = CreateLoadRequests("/Validation/dependencies.csolution.yml", "", contextList);
602606
requests += FormatRequest(3, "GetUsedItems", json({{ "context", context }}));
603607
requests += FormatRequest(4, "SelectComponent", param);
604608
requests += FormatRequest(5, "Apply", param);

0 commit comments

Comments
 (0)