Skip to content

Commit 87c365a

Browse files
grasci-armedriouk
andauthored
Perform Apply for any RPC call changing component selection (#1440) (#2392)
Co-authored-by: Evgueni Driouk <edriouk@arm.com>
1 parent a386185 commit 87c365a

2 files changed

Lines changed: 73 additions & 54 deletions

File tree

tools/projmgr/src/ProjMgrRpcServer.cpp

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ class RpcHandler : public RpcMethods {
126126

127127
map<std::string, PackReferenceVector> m_packReferences; // packsInfo is used to simplify creation and access to references
128128

129-
void StoreSelectedComponents(RteTarget* rteTarget, map<RteComponent*, int>& selectedComponents);
130129
PackReferenceVector& GetPackReferences(const string& context);
131130
PackReferenceVector CollectPackReferences(const string& context);
132131
PackReferenceVector GetPackReferencesForPack(const string& context, const string& packId);
@@ -138,7 +137,6 @@ class RpcHandler : public RpcMethods {
138137
const ContextItem& GetContext(const string& context) const;
139138
RteTarget* GetActiveTarget(const string& context) const;
140139
RteComponentAggregate* GetComponentAggregate(const string& context, const string& id) const;
141-
bool SelectVariantOrVersion(const string& context, const string& id, const string& value, bool bVariant);
142140
bool CheckSolutionArg(string& solution, optional<string>& message) const;
143141
};
144142

@@ -264,6 +262,7 @@ RpcArgs::SuccessResult RpcHandler::Resolve(const string& context) {
264262
auto rteProject = rteTarget->GetProject();
265263
if(rteProject) {
266264
result.success = rteProject->ResolveDependencies(rteTarget);
265+
Apply(context);
267266
}
268267
return result;
269268
}
@@ -299,27 +298,11 @@ RpcArgs::SuccessResult RpcHandler::LoadSolution(const string& solution, const st
299298
return result;
300299
}
301300

302-
void RpcHandler::StoreSelectedComponents(RteTarget* rteTarget, map<RteComponent*, int>& selectedComponents)
303-
{
304-
auto& selectedAggregates = rteTarget->CollectSelectedComponentAggregates();
305-
for(auto [aggregate, count] : selectedAggregates) {
306-
RteComponent* c = aggregate->GetComponent();
307-
if(c) {
308-
// consider only components, instances are added from project anyway
309-
selectedComponents[c] = count;
310-
}
311-
}
312-
}
313-
314301
void RpcHandler::UpdateFilter(const string& context, RteTarget* rteTarget, bool all) {
315302
if(m_bUseAllPacks == all) {
316303
return;
317304
}
318305
m_bUseAllPacks = all;
319-
// store selected components, not aggregates: they will be destroyed
320-
map<RteComponent*, int> selectedComponents;
321-
StoreSelectedComponents(rteTarget, selectedComponents);
322-
323306
RtePackageFilter packFilter;
324307
// construct and apply filter
325308
// use resolved pack ID's from selected references
@@ -337,10 +320,6 @@ void RpcHandler::UpdateFilter(const string& context, RteTarget* rteTarget, bool
337320
rteTarget->SetPackageFilter(packFilter);
338321
rteTarget->UpdateFilterModel(); // updates available components
339322
rteTarget->GetProject()->UpdateModel(); // inserts already instantiated components
340-
// restore selection
341-
for(auto [c, count] : selectedComponents) {
342-
rteTarget->SelectComponent(c, count, false, false);
343-
}
344323
rteTarget->EvaluateComponentDependencies();
345324
}
346325
}
@@ -588,6 +567,7 @@ RpcArgs::SuccessResult RpcHandler::SelectComponent(const string& context, const
588567
auto& packId = rteComponent->GetPackage()->GetID();
589568
EnsurePackReferenceForPack(context, packId, layer, !explicitVersion.empty());
590569
}
570+
Apply(context);
591571
return result;
592572
}
593573

@@ -609,35 +589,10 @@ RpcArgs::SuccessResult RpcHandler::SelectVariant(const string& context, const st
609589
GetActiveTarget(context)->EvaluateComponentDependencies();
610590
}
611591
result.success = true;
592+
Apply(context);
612593
return result;
613594
}
614595

615-
bool RpcHandler::SelectVariantOrVersion(const string& context, const string& id, const string& value, bool bVariant) {
616-
RteComponentAggregate* rteAggregate = GetComponentAggregate(context, id);
617-
618-
auto& selectedValue = bVariant ? rteAggregate->GetSelectedVariant() : rteAggregate->GetSelectedVersion();
619-
if(selectedValue == value) {
620-
return false;
621-
}
622-
623-
if(bVariant || !value.empty()) {
624-
auto availableValues = bVariant ? rteAggregate->GetVariants() : rteAggregate->GetVersions(rteAggregate->GetSelectedVariant());
625-
if(std::find(availableValues.begin(), availableValues.end(), value) == availableValues.end()) {
626-
return false;
627-
}
628-
}
629-
if(bVariant) {
630-
rteAggregate->SetSelectedVariant(value);
631-
} else {
632-
rteAggregate->SetSelectedVersion(value);
633-
}
634-
if(rteAggregate->IsSelected()) {
635-
GetActiveTarget(context)->EvaluateComponentDependencies();
636-
}
637-
return true;
638-
}
639-
640-
641596
RpcArgs::SuccessResult RpcHandler::SelectBundle(const string& context, const string& className, const string& bundleName) {
642597
RpcArgs::SuccessResult result = {false};
643598
RteTarget* rteTarget = GetActiveTarget(context);
@@ -653,6 +608,7 @@ RpcArgs::SuccessResult RpcHandler::SelectBundle(const string& context, const str
653608
return result; // error => false
654609
}
655610
rteClass->SetSelectedBundleName(bundleName, true);
611+
Apply(context);
656612
GetActiveTarget(context)->EvaluateComponentDependencies();
657613
result.success = true;
658614
return result;

tools/projmgr/test/src/ProjMgrRpcTests.cpp

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,69 @@ TEST_F(ProjMgrRpcTests, RpcSelectComponent) {
605605
EXPECT_FALSE(responses[5]["result"].contains("validation"));
606606
}
607607

608+
609+
TEST_F(ProjMgrRpcTests, RpcSelectComponentLayer) {
610+
string context = "selectable+CM0";
611+
vector<string> contextList = {
612+
context
613+
};
614+
RpcArgs::Options opt{"core.clayer.yml", "@>=0.1.0", true};
615+
json param;
616+
param["context"] = context;
617+
param["id"] = "ARM::RteTest:CORE";
618+
param["count"] = 1;
619+
RpcArgs::to_json(param["options"], opt);
620+
621+
auto requests = CreateLoadRequests("/Validation/dependencies.csolution.yml", "", contextList);
622+
requests += FormatRequest(3, "GetUsedItems", json({{ "context", context }}));
623+
requests += FormatRequest(4, "SelectComponent", param);
624+
requests += FormatRequest(5, "GetComponentsTree", json({{ "context", context }, {"all", false}}));
625+
requests += FormatRequest(6, "GetComponentsTree", json({{ "context", context }, {"all", true}}));
626+
requests += FormatRequest(7, "GetComponentsTree", json({{ "context", context }, {"all", false}}));
627+
requests += FormatRequest(8, "Apply", json({{ "context", context }}));
628+
requests += FormatRequest(9, "GetUsedItems", json({{ "context", context }}));
629+
630+
const auto& responses = RunRpcMethods(requests);
631+
632+
EXPECT_TRUE(responses[2]["result"]["success"]);
633+
auto components = responses[2]["result"]["components"];
634+
auto packs = responses[2]["result"]["packs"];
635+
EXPECT_EQ(packs.size(), 2);
636+
EXPECT_EQ(packs[0]["pack"], "ARM::RteTest_DFP@0.2.0");
637+
EXPECT_EQ(packs[0]["resolvedPack"], "ARM::RteTest_DFP@0.2.0");
638+
EXPECT_EQ(components[0]["id"], "Device:Startup&RteTest Startup");
639+
EXPECT_EQ(components[0]["resolvedComponent"]["id"], "ARM::Device:Startup&RteTest Startup@2.0.3");
640+
641+
EXPECT_TRUE(responses[3]["result"]["success"]); // select successful
642+
643+
EXPECT_TRUE(responses[7]["result"]["success"]); // apply successful
644+
645+
components = responses[8]["result"]["components"];
646+
packs = responses[8]["result"]["packs"];
647+
EXPECT_EQ(packs.size(), 3); // added reference to layer file
648+
EXPECT_EQ(packs[0]["pack"], "ARM::RteTest_DFP@0.2.0");
649+
string origin = packs[0]["origin"];
650+
EXPECT_TRUE(origin.find(".csolution.yml") != string::npos);
651+
EXPECT_TRUE(!!packs[0]["selected"]);
652+
EXPECT_EQ(packs[2]["pack"], "ARM::RteTest_DFP@0.2.0");
653+
EXPECT_EQ(packs[2]["origin"], "core.clayer.yml");
654+
EXPECT_TRUE(!!packs[2]["selected"]);
655+
656+
EXPECT_EQ(components[0]["id"], "Device:Startup&RteTest Startup");
657+
EXPECT_EQ(components[0]["resolvedComponent"]["id"], "ARM::Device:Startup&RteTest Startup@2.0.3");
658+
659+
string id = components[1]["id"];
660+
EXPECT_EQ(id, "ARM::RteTest:CORE@>=0.1.0");
661+
EXPECT_EQ(RteUtils::ExtractPrefix(id, "::"), "ARM");
662+
EXPECT_EQ(RteUtils::ExtractSuffix(id, "@", true), "@>=0.1.0");
663+
EXPECT_EQ(components[1]["resolvedComponent"]["id"], "ARM::RteTest:CORE@0.1.1");
664+
EXPECT_EQ(components[1]["options"]["layer"], "core.clayer.yml");
665+
EXPECT_EQ(components[1]["options"]["explicitVersion"], "@>=0.1.0");
666+
EXPECT_TRUE(components[1]["options"]["explicitVendor"]);
667+
}
668+
669+
670+
608671
TEST_F(ProjMgrRpcTests, RpcSelectComponentMissing) {
609672
string context = "missing-component+CM0";
610673
vector<string> contextList = {
@@ -621,11 +684,11 @@ TEST_F(ProjMgrRpcTests, RpcSelectComponentMissing) {
621684
requests += FormatRequest(3, "ValidateComponents", json({{ "context", context }}));
622685
requests += FormatRequest(4, "GetComponentsTree", json({{ "context", context }, {"all", false}}));
623686
requests += FormatRequest(5, "GetUsedItems", json({{ "context", context }}));
624-
// unselect component
625-
requests += FormatRequest(6, "SelectComponent", param);
687+
// change pack filter
688+
requests += FormatRequest(6, "GetComponentsTree", json({{ "context", context }, {"all", true}}));
626689
requests += FormatRequest(7, "ValidateComponents", json({{ "context", context }}));
627-
// select component again
628-
param["count"] = 1;
690+
// select component with another count
691+
param["count"] = 2;
629692
requests += FormatRequest(8, "SelectComponent", param);
630693
requests += FormatRequest(9, "ValidateComponents", json({{ "context", context }}));
631694
// finally unselect and apply
@@ -651,8 +714,8 @@ TEST_F(ProjMgrRpcTests, RpcSelectComponentMissing) {
651714
EXPECT_EQ(components[0]["selectedCount"], 1);
652715

653716
EXPECT_TRUE(responses[5]["result"]["success"]);
654-
EXPECT_EQ(responses[6]["result"]["result"], "IGNORED");
655-
EXPECT_FALSE(responses[6]["result"].contains("validation"));
717+
EXPECT_EQ(responses[6]["result"]["result"], "MISSING");
718+
EXPECT_TRUE(responses[6]["result"].contains("validation"));
656719

657720
EXPECT_EQ(responses[8]["result"]["result"], "MISSING");
658721

0 commit comments

Comments
 (0)