Skip to content

Commit d327733

Browse files
grasci-armedriouk
andauthored
Set Bname to empty string if not defined (#1351) (#2270)
* Set Bname empty in RteTarget ProcessAttributes * Fix RPC tests * Remove ambiguity in XmlItem::SetAttributes() by making two XmlItem constructors explicit * Make ubuntu C++ compiler happy * Try to fix the tests * Fix test data end test * Change one overload of SetAttributes to CopyAttributes To satisfy compiler. Co-authored-by: Evgueni Driouk <[email protected]>
1 parent d2501c9 commit d327733

30 files changed

+110
-139
lines changed

libs/rtemodel/include/RteInstance.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ class RteItemInstance : public RteItem
428428
* @param attr attributes to set as XmlItem reference
429429
* @return true if changed
430430
*/
431-
virtual bool SetPackageAttributes(const XmlItem& attr) { return m_packageAttributes.SetAttributes(attr); }
431+
virtual bool SetPackageAttributes(const XmlItem& attr) { return m_packageAttributes.CopyAttributes(attr); }
432432

433433
/**
434434
* @brief get pointer to resolved RtePackage
@@ -594,7 +594,7 @@ class RtePackageInstanceInfo : public RteItemInstance
594594
* @param attr pack attributes to set
595595
* @return true if attribute values have changed
596596
*/
597-
bool SetPackageAttributes(const XmlItem& attr) override { return SetAttributes(attr); }
597+
bool SetPackageAttributes(const XmlItem& attr) override { return CopyAttributes(attr); }
598598

599599
/**
600600
* @brief check if this object contains pack attributes directly rather than in a dedicated child
@@ -714,7 +714,7 @@ class RteGpdscInfo : public RteItemInstance
714714
* @param attr pack attributes
715715
* @return true if changed
716716
*/
717-
bool SetPackageAttributes(const XmlItem& attr) override { return SetAttributes(attr); }
717+
bool SetPackageAttributes(const XmlItem& attr) override { return CopyAttributes(attr); }
718718

719719
/**
720720
* @brief check if this object contains pack attributes directly rather than in a dedicated child

libs/rtemodel/include/RteModel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ class RteModel : public RteItem
446446
* @param books collection of file path mapped to book title to fill
447447
* @param deviceAttributes device attributes
448448
*/
449-
void GetBoardBooks(std::map<std::string, std::string>& books, const std::map<std::string, std::string>& deviceAttributes) const;
449+
void GetBoardBooks(std::map<std::string, std::string>& books, const XmlItem& deviceAttributes) const;
450450

451451
public:
452452
/**

libs/rtemodel/src/RteInstance.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ void RteInstanceTargetInfo::CopySettings(const RteInstanceTargetInfo& other)
157157
SetVersionMatchMode(other.GetVersionMatchMode());
158158
SetExcluded(other.IsExcluded());
159159
SetIncludeInLib(other.IsIncludeInLib());
160-
m_memOpt.SetAttributes(other.GetMemOpt());
161-
m_cOpt.SetAttributes(other.GetCOpt());
162-
m_asmOpt.SetAttributes(other.GetAsmOpt());
160+
m_memOpt.CopyAttributes(other.GetMemOpt());
161+
m_cOpt.CopyAttributes(other.GetCOpt());
162+
m_asmOpt.CopyAttributes(other.GetAsmOpt());
163163
}
164164

165165

@@ -700,7 +700,7 @@ void RteFileInstance::Update(RteItem* f, bool bUpdateComponent)
700700
for (auto [targetName, ti] : m_targetInfos) {
701701
RteComponentInstance* ci = GetComponentInstance(targetName);
702702
if (ci) {
703-
ci->SetAttributes(m_componentAttributes);
703+
ci->CopyAttributes(m_componentAttributes);
704704
ci->SetPackageAttributes(m_packageAttributes);
705705
}
706706
}

libs/rtemodel/src/RteModel.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,13 +800,14 @@ void RteModel::GetBoardBooks(map<string, string>& books, const string& device, c
800800
return;
801801
XmlItem ea;
802802
d->GetEffectiveAttributes(ea);
803-
GetBoardBooks(books, ea.GetAttributes());
803+
GetBoardBooks(books, ea);
804804
}
805805

806-
void RteModel::GetBoardBooks(map<string, string>& books, const map<string, string>& deviceAttributes) const
806+
void RteModel::GetBoardBooks(map<string, string>& books, const XmlItem& deviceAttributes) const
807807
{
808-
if (m_boards.empty())
808+
if(m_boards.empty()) {
809809
return;
810+
}
810811
for (auto [_, b] : m_boards) {
811812
if (b->HasCompatibleDevice(deviceAttributes)) {
812813
b->GetBooks(books);

libs/rtemodel/src/RteProject.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ RteLicenseInfo* RteLicenseInfoCollection::EnsureLicenseInfo(RteItem* item, RteIt
137137
m_LicensInfos[licId] = info;
138138
string licFile;
139139
if (license) {
140-
info->SetAttributes(*license);
140+
info->CopyAttributes(*license);
141141
if(!info->HasAttribute("spdx")) {
142142
licFile = license->GetName();
143143
}
@@ -399,7 +399,7 @@ RteComponentInstance* RteProject::AddComponent(RteComponent* c, int instanceCoun
399399
if (c->IsGenerated() && c->HasAttribute("selectable") ) {
400400
RteItem* packInfo = c->GetFirstChild("package");
401401
if (packInfo) {
402-
ci->SetPackageAttributes(packInfo->GetAttributes());
402+
ci->SetPackageAttributes(*packInfo);
403403
}
404404
}
405405

@@ -1460,18 +1460,18 @@ RteItem::ConditionResult RteProject::ResolveComponents(bool bFindReplacementForA
14601460
}
14611461

14621462
// first try to find a component from the same vendor
1463-
t->GetComponentAggregates(componentAttributes.GetAttributes(), aggregates);
1463+
t->GetComponentAggregates(componentAttributes, aggregates);
14641464

14651465
// try to find a component from any vendor
14661466
if (aggregates.empty()) {
14671467
componentAttributes.RemoveAttribute("Cvendor");
1468-
t->GetComponentAggregates(componentAttributes.GetAttributes(), aggregates);
1468+
t->GetComponentAggregates(componentAttributes, aggregates);
14691469
}
14701470

14711471
// try to find a component with any variant
14721472
if (aggregates.empty() && !componentAttributes.GetCvariantName().empty()) {
14731473
componentAttributes.RemoveAttribute("Cvariant");
1474-
t->GetComponentAggregates(componentAttributes.GetAttributes(), aggregates);
1474+
t->GetComponentAggregates(componentAttributes, aggregates);
14751475
}
14761476

14771477
}
@@ -1601,7 +1601,7 @@ bool RteProject::AddTarget(const string& name, const map<string, string>& attrib
16011601
targetAttributes.RemoveAttribute("Bversion");
16021602
}
16031603

1604-
bool changed = target->SetAttributes(targetAttributes);
1604+
bool changed = target->CopyAttributes(targetAttributes);
16051605
if (supported) {
16061606
if (bNewTarget) {
16071607
AddTargetInfo(name);

libs/rtemodel/src/RteTarget.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,13 @@ void RteTarget::ProcessAttributes() // called from SetAttributes(), AddAttribute
582582
{
583583
if (m_bDestroy)
584584
return;
585+
586+
// set empty board name to filter-out board-specific items if device is selected
587+
if(HasAttribute("Dname") &&
588+
!HasAttribute("Bname")) {
589+
AddAttribute("Bname", "");
590+
}
591+
585592
m_device = 0;
586593
RteModel *model = GetFilteredModel();
587594
if (!model)

libs/rtemodel/test/src/RteChkTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ From DFP: 24\n\
3636
From BSP: 0\n\
3737
\n\
3838
Devices: 10\n\
39-
Boards: 14\n\
39+
Boards: 15\n\
4040
\n\
4141
completed\n";
4242

@@ -53,7 +53,7 @@ completed\n";
5353
EXPECT_EQ(rteChk.GetPackCount(), 8);
5454
EXPECT_EQ(rteChk.GetComponentCount(), 60);
5555
EXPECT_EQ(rteChk.GetDeviceCount(), 10);
56-
EXPECT_EQ(rteChk.GetBoardCount(), 14);
56+
EXPECT_EQ(rteChk.GetBoardCount(), 15);
5757

5858
string s = RteUtils::EnsureLf(ss.str());
5959
EXPECT_EQ(s, summary);

libs/rtemodel/test/src/RteItemTest.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,33 @@ TEST(RteItemTest, GetInstancePathName) {
262262
EXPECT_EQ(instanceFile, "MySolDir/.cmsis/MySolName+MyTarget.dbgconf");
263263
}
264264

265+
TEST(RteTargetTest, ProcessAttributes_Bname) {
266+
RteTarget target(nullptr, nullptr, "test", {});
267+
268+
// Bname is not set by default
269+
EXPECT_FALSE(target.HasAttribute("Bname"));
270+
271+
// Bname is not set when no Dname
272+
target.SetAttributes({{"Dfpu", "NO_FPU"}});
273+
EXPECT_FALSE(target.HasAttribute("Bname"));
274+
target.ClearAttributes();
275+
276+
// Bname is set to empty if Dname and no Bname
277+
target.SetAttributes({{"Dname", "MyDevice"}});
278+
EXPECT_TRUE(target.HasAttribute("Bname"));
279+
EXPECT_EQ(target.GetAttribute("Bname"), "");
280+
target.ClearAttributes();
281+
282+
// Bname only
283+
target.SetAttributes({{"Bname", "MyBoard"}});
284+
EXPECT_TRUE(target.HasAttribute("Bname"));
285+
EXPECT_EQ(target.GetAttribute("Bname"), "MyBoard");
286+
target.ClearAttributes();
287+
288+
// Bname with Dname
289+
target.SetAttributes({{"Bname", "MyBoard"}, {"Dname", "MyDevice"}});
290+
EXPECT_TRUE(target.HasAttribute("Bname"));
291+
EXPECT_EQ(target.GetAttribute("Bname"), "MyBoard");
292+
}
293+
265294
// end of RteItemTest.cpp

libs/rtemodel/test/src/RteModelTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ TEST_F(RteModelPrjTest, LoadCprj) {
433433
EXPECT_EQ(boardName, "RteTest Test board");
434434
// get layers
435435
auto& allLayerDescriptors = rteKernel.GetGlobalModel()->GetLayerDescriptors();
436-
EXPECT_EQ(allLayerDescriptors.size(), 10);
436+
EXPECT_EQ(allLayerDescriptors.size(), 13);
437437
auto& filteredLayerDescriptors = activeTarget->GetFilteredModel()->GetLayerDescriptors();
438438
EXPECT_EQ(filteredLayerDescriptors.size(), 8);
439439

@@ -1077,7 +1077,7 @@ TEST_F(RteModelPrjTest, LoadCprjM4) {
10771077
EXPECT_TRUE(boardName.empty());
10781078
// get layers
10791079
auto& allLayerDescriptors = rteKernel.GetGlobalModel()->GetLayerDescriptors();
1080-
EXPECT_EQ(allLayerDescriptors.size(), 10);
1080+
EXPECT_EQ(allLayerDescriptors.size(), 13);
10811081
auto& filteredLayerDescriptors = activeTarget->GetFilteredModel()->GetLayerDescriptors();
10821082
EXPECT_EQ(filteredLayerDescriptors.size(), 7);
10831083
ca = activeTarget->GetComponentAggregate("ARM::Device:Startup");
@@ -1160,7 +1160,7 @@ TEST_F(RteModelPrjTest, LoadCprjM4_Board) {
11601160
EXPECT_EQ(boardName, "RteTest CM4 board");
11611161
// get layers
11621162
auto& allLayerDescriptors = rteKernel.GetGlobalModel()->GetLayerDescriptors();
1163-
EXPECT_EQ(allLayerDescriptors.size(), 10);
1163+
EXPECT_EQ(allLayerDescriptors.size(), 13);
11641164
auto& filteredLayerDescriptors = activeTarget->GetFilteredModel()->GetLayerDescriptors();
11651165
EXPECT_EQ(filteredLayerDescriptors.size(), 7);
11661166

libs/xmltree/include/XmlItem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ class XmlItem
4747
* @brief parametrized constructor
4848
* @param tag XML tag
4949
*/
50-
XmlItem(const std::string& tag) : m_tag(tag), m_lineNumber(0) {};
50+
explicit XmlItem(const std::string& tag) : m_tag(tag), m_lineNumber(0) {};
5151

5252
/**
5353
* @brief parametrized constructor to instantiate with given attributes
5454
* @param attributes collection as key to value pairs
5555
*/
56-
XmlItem(const std::map<std::string, std::string>& attributes) : m_attributes(attributes), m_lineNumber(0) {};
56+
explicit XmlItem(const std::map<std::string, std::string>& attributes) : m_attributes(attributes), m_lineNumber(0) {};
5757

5858
/**
5959
* @brief virtual destructor
@@ -163,7 +163,7 @@ class XmlItem
163163
* @param attributes instance of XmlItem containing attributes to assign
164164
* @return true if attributes are set
165165
*/
166-
bool SetAttributes(const XmlItem &attributes);
166+
bool CopyAttributes(const XmlItem &attributes);
167167

168168
/**
169169
* @brief assign specified attribute value from supplied object to this one

0 commit comments

Comments
 (0)