Skip to content

Commit 7878b72

Browse files
authored
[devtools] Handle pack identifiers as case insensitive
1 parent 93e18f8 commit 7878b72

File tree

10 files changed

+149
-126
lines changed

10 files changed

+149
-126
lines changed

libs/rtemodel/include/RteKernel.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
/******************************************************************************/
1010
/*
11-
* Copyright (c) 2020-2021 Arm Limited. All rights reserved.
11+
* Copyright (c) 2020-2025 Arm Limited. All rights reserved.
1212
*
1313
* SPDX-License-Identifier: Apache-2.0
1414
*/
@@ -241,21 +241,6 @@ class RteKernel
241241
*/
242242
void GetInstalledPdscFiles(std::map<std::string, std::string, RtePackageComparator>& pdscMap) const;
243243

244-
/**
245-
* @brief getter for pdsc file determined by pack ID, pack path and pack attributes
246-
* @param attributes pack attributes
247-
* @param packId pack ID
248-
* @return pair of pack ID to pdsc file
249-
*/
250-
std::pair<std::string, std::string> GetInstalledPdscFile(const XmlItem& attributes) const;
251-
252-
/**
253-
* @brief getter for pdsc file pointed by the local repository index and determined by pack attributes, pack path and pack ID.
254-
* @param attributes pack attributes
255-
* @return pair of pack ID to pdsc file
256-
*/
257-
std::pair<std::string, std::string> GetLocalPdscFile(const XmlItem& attributes) const;
258-
259244
/**
260245
* @brief get local or installed pdsc file corresponding to supplied pack ID, pack path and pack attributes
261246
* @param attributes pack attributes

libs/rtemodel/include/RtePackage.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
/******************************************************************************/
1010
/*
11-
* Copyright (c) 2020-2021 Arm Limited. All rights reserved.
11+
* Copyright (c) 2020-2025 Arm Limited. All rights reserved.
1212
*
1313
* SPDX-License-Identifier: Apache-2.0
1414
*/
@@ -1333,11 +1333,33 @@ class RtePackRegistry
13331333
*/
13341334
const std::map<std::string, RtePackage*>& GetLoadedPacks() const { return m_loadedPacks;}
13351335

1336+
/**
1337+
* @brief get collection of effective pdscs
1338+
* @return const map of effective pdscs
1339+
*/
1340+
const std::map<std::string, std::string, RtePackageComparator>& GetPdscMap() const { return m_pdscMap; }
1341+
1342+
/**
1343+
* @brief set collection of effective pdscs
1344+
* @param map of effective pdscs
1345+
*/
1346+
void SetPdscMap(const std::map<std::string, std::string, RtePackageComparator>& pdscMap) { m_pdscMap = pdscMap; }
1347+
1348+
/**
1349+
* @brief clear collection of effective pdscs
1350+
*/
1351+
void ClearPdscMap() { m_pdscMap.clear(); }
1352+
13361353
protected:
13371354
/**
13381355
* @brief collection of loaded packs: absolute pdsc filename -> RtePackage*
13391356
*/
13401357
std::map<std::string, RtePackage*> m_loadedPacks;
1358+
1359+
/**
1360+
* @brief collection of effective pdscs: lower-case pack id -> absolute pdsc filename
1361+
*/
1362+
std::map<std::string, std::string, RtePackageComparator> m_pdscMap;
13411363
};
13421364

13431365

libs/rtemodel/src/RteKernel.cpp

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
/******************************************************************************/
88
/*
9-
* Copyright (c) 2020-2021 Arm Limited. All rights reserved.
9+
* Copyright (c) 2020-2025 Arm Limited. All rights reserved.
1010
*
1111
* SPDX-License-Identifier: Apache-2.0
1212
*/
@@ -80,6 +80,7 @@ bool RteKernel::SetCmsisPackRoot(const string& cmsisPackRoot)
8080
if (m_cmsisPackRoot == cmsisPackRoot)
8181
return false;
8282
m_cmsisPackRoot = cmsisPackRoot;
83+
RteFsUtils::NormalizePath(m_cmsisPackRoot);
8384
return true;
8485
}
8586

@@ -413,12 +414,19 @@ bool RteKernel::GetEffectivePdscFilesAsMap(map<string, string, RtePackageCompara
413414
if(cmsisPackRoot.empty()) {
414415
return false;
415416
}
416-
// Get all installed files
417-
RteKernel::GetInstalledPdscFiles(pdscMap);
418417

419-
// Overwrite entries with local pdsc files if any
420-
XmlItem emptyAttributes;
421-
GetLocalPdscFiles(emptyAttributes, pdscMap);
418+
// Get pdsc map
419+
RtePackRegistry* packRegistry = GetPackRegistry();
420+
pdscMap = packRegistry->GetPdscMap();
421+
if (pdscMap.empty()) {
422+
// Get all installed files
423+
GetInstalledPdscFiles(pdscMap);
424+
// Overwrite entries with local pdsc files if any
425+
XmlItem emptyAttributes;
426+
GetLocalPdscFiles(emptyAttributes, pdscMap);
427+
// Store pdsc map
428+
packRegistry->SetPdscMap(pdscMap);
429+
}
422430

423431
// purge entries if only latest are required
424432
if(latest) {
@@ -482,51 +490,54 @@ void RteKernel::GetInstalledPdscFiles(std::map<std::string, std::string, RtePack
482490
{
483491
list<string> allFiles;
484492
RteFsUtils::GetPackageDescriptionFiles(allFiles, GetCmsisPackRoot(), 3);
485-
for(auto& f : allFiles) {
486-
string id = RtePackage::PackIdFromPath(f);
493+
for (auto& f : allFiles) {
494+
string id = RteUtils::ToLower(RtePackage::PackIdFromPath(f));
487495
pdscMap[id] = f;
488496
}
489497
}
490498

491-
pair<string, string> RteKernel::GetInstalledPdscFile(const XmlItem& attributes) const
499+
pair<string, string> RteKernel::GetEffectivePdscFile(const XmlItem& attributes) const
492500
{
493501
const string& name = attributes.GetAttribute("name");
494502
const string& vendor = attributes.GetAttribute("vendor");
495-
if(!name.empty() && !vendor.empty()) {
496-
string path = GetCmsisPackRoot() + '/' + vendor + '/' + name;
497-
const string& versionRange = attributes.GetAttribute("version");
498-
string installedVersion = RteFsUtils::GetInstalledPackVersion(path, versionRange);
499-
if(!installedVersion.empty()) {
500-
string packId = RtePackage::ComposePackageID(vendor, name, installedVersion);
501-
path += '/' + installedVersion + '/' + vendor + '.' + name + ".pdsc";
502-
return make_pair(packId, path);
503+
if (!name.empty() && !vendor.empty()) {
504+
const string& packId = RteUtils::ToLower(vendor + RteConstants::SUFFIX_PACK_VENDOR + name);
505+
// get map of effective pdscs with lower-case ids
506+
map<string, string, RtePackageComparator> pdscMap;
507+
GetEffectivePdscFilesAsMap(pdscMap, false);
508+
StrPairVec pdscs;
509+
// get subset of pdscs for the searched packId
510+
for (const auto& pdsc : pdscMap) {
511+
if (RtePackage::CommonIdFromId(pdsc.first) == packId) {
512+
pdscs.push_back(pdsc);
513+
}
514+
}
515+
if (!pdscs.empty()) {
516+
const string& versionRange = attributes.GetAttribute("version");
517+
StrPair effectivePdsc;
518+
if (versionRange.empty()) {
519+
// required version range is empty = get greatest effective version
520+
effectivePdsc = *pdscs.begin();
521+
} else {
522+
for (const auto& pdsc : pdscs) {
523+
// find the greatest effective version in the required version range
524+
if (VersionCmp::RangeCompare(RtePackage::VersionFromId(pdsc.first), versionRange) == 0) {
525+
effectivePdsc = pdsc;
526+
break;
527+
}
528+
}
529+
}
530+
auto& id = effectivePdsc.first;
531+
if (!id.empty()) {
532+
// preserve name::vendor as given in input attributes
533+
id = RtePackage::ComposePackageID(vendor, name, RtePackage::VersionFromId(id));
534+
return effectivePdsc;
535+
}
503536
}
504537
}
505538
return make_pair(RteUtils::EMPTY_STRING, RteUtils::EMPTY_STRING);
506539
}
507540

508-
pair<string, string> RteKernel::GetLocalPdscFile(const XmlItem& attributes) const
509-
{
510-
map<string, string, RtePackageComparator> pdscMap;
511-
if(!attributes.IsEmpty() && GetLocalPdscFiles(attributes, pdscMap)) {
512-
return *pdscMap.begin();
513-
}
514-
return make_pair(RteUtils::EMPTY_STRING, RteUtils::EMPTY_STRING);
515-
}
516-
517-
pair<string, string> RteKernel::GetEffectivePdscFile(const XmlItem& attributes) const
518-
{
519-
auto localPdsc = GetLocalPdscFile(attributes);
520-
auto installedPdsc = GetInstalledPdscFile(attributes);
521-
522-
string localVersion = RtePackage::VersionFromId(localPdsc.first);
523-
string installedVersion = RtePackage::VersionFromId(installedPdsc.first);
524-
if(!localVersion.empty() && VersionCmp::Compare(localVersion, installedVersion) >= 0) {
525-
return localPdsc;
526-
}
527-
return installedPdsc;
528-
}
529-
530541

531542
pair<string, string> RteKernel::GetPdscFileFromPath(const XmlItem& attributes, const string& prjPath) const
532543
{
@@ -579,7 +590,7 @@ bool RteKernel::GetLocalPdscFiles(const XmlItem& attr, std::map<std::string, std
579590
if(pack) {
580591
const string& version = pack->GetVersionString();
581592
if(versionRange.empty() || VersionCmp::RangeCompare(version, versionRange) == 0) {
582-
pdscMap[pack->GetID()] = localPdscFile;
593+
pdscMap[RteUtils::ToLower(pack->GetID())] = localPdscFile;
583594
found = true;
584595
}
585596
}

libs/rtemodel/test/src/RteModelTest.cpp

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2021 Arm Limited. All rights reserved.
2+
* Copyright (c) 2020-2025 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -725,60 +725,13 @@ TEST_F(RteModelPrjTest, LoadCprjConfigVer) {
725725

726726
}
727727

728-
TEST_F(RteModelPrjTest, GetLocalPdscFile) {
729-
RteKernelSlim rteKernel;
730-
rteKernel.SetCmsisPackRoot(packsDir);
731-
732-
XmlItem attributes;
733-
auto pdsc = rteKernel.GetLocalPdscFile(attributes);
734-
EXPECT_TRUE(pdsc.first.empty());
735-
EXPECT_TRUE(pdsc.second.empty());
736-
737-
attributes.AddAttribute("name", "LocalPack");
738-
attributes.AddAttribute("vendor", "LocalVendor");
739-
pdsc = rteKernel.GetLocalPdscFile(attributes);
740-
741-
// check returned packId
742-
EXPECT_EQ(pdsc.first, "LocalVendor::[email protected]");
743-
744-
// check returned pdsc
745-
const string expectedPdsc =
746-
RteFsUtils::MakePathCanonical(RteFsUtils::AbsolutePath(localPacks + "/L/LocalVendor.LocalPack.pdsc").generic_string());
747-
error_code ec;
748-
EXPECT_TRUE(fs::equivalent(pdsc.second, expectedPdsc, ec));
749-
}
750-
751-
TEST_F(RteModelPrjTest, GetInstalledPdscFile) {
752-
RteKernelSlim rteKernel;
753-
rteKernel.SetCmsisPackRoot(packsDir);
754-
755-
XmlItem attributes;
756-
auto pdsc = rteKernel.GetInstalledPdscFile(attributes);
757-
EXPECT_TRUE(pdsc.first.empty());
758-
EXPECT_TRUE(pdsc.second.empty());
759-
760-
attributes.AddAttribute("name", "RteTestRequired");
761-
attributes.AddAttribute("vendor", "ARM");
762-
pdsc = rteKernel.GetInstalledPdscFile(attributes);
763-
764-
// check returned packId
765-
EXPECT_EQ(pdsc.first, "ARM::[email protected]");
766-
767-
// check returned pdsc
768-
const string expectedPdsc =
769-
RteFsUtils::MakePathCanonical(RteFsUtils::AbsolutePath(packsDir +
770-
"/ARM/RteTestRequired/1.0.0/ARM.RteTestRequired.pdsc").generic_string());
771-
error_code ec;
772-
EXPECT_TRUE(fs::equivalent(pdsc.second, expectedPdsc, ec));
773-
}
774-
775728
TEST_F(RteModelPrjTest, GetEffectivePdscFile) {
776729
RteKernelSlim rteKernel;
777730
rteKernel.SetCmsisPackRoot(packsDir);
778731
XmlItem attributes;
779732

780733
// nothing has found for empty attributes
781-
auto pdsc = rteKernel.GetInstalledPdscFile(attributes);
734+
auto pdsc = rteKernel.GetEffectivePdscFile(attributes);
782735
EXPECT_TRUE(pdsc.first.empty());
783736
EXPECT_TRUE(pdsc.second.empty());
784737

@@ -821,14 +774,14 @@ TEST_F(RteModelPrjTest, GetEffectivePdscFile) {
821774

822775
// outside range
823776
attributes.AddAttribute("version", "2.0.0");
824-
pdsc = rteKernel.GetInstalledPdscFile(attributes);
777+
pdsc = rteKernel.GetEffectivePdscFile(attributes);
825778
EXPECT_TRUE(pdsc.first.empty());
826779
EXPECT_TRUE(pdsc.second.empty());
827780

828781
// unknown name
829782
attributes.RemoveAttribute("version");
830783
attributes.AddAttribute("name", "Unknown");
831-
pdsc = rteKernel.GetInstalledPdscFile(attributes);
784+
pdsc = rteKernel.GetEffectivePdscFile(attributes);
832785
EXPECT_TRUE(pdsc.first.empty());
833786
EXPECT_TRUE(pdsc.second.empty());
834787
}

tools/projmgr/include/ProjMgrWorker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,7 @@ class ProjMgrWorker {
12841284
bool HasCompatibleEnvironment(const Collection<RteItem*>& environments, const StrVec& filter);
12851285
template<class T> bool CheckFilter(const std::string& filter, const T& item);
12861286
void ResolvePackRequirement(ContextItem& context, const PackItem& packEntry);
1287+
void FormatResolvedPackIds();
12871288
};
12881289

12891290
#endif // PROJMGRWORKER_H

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,9 @@ string ProjMgrWorker::GetPackRoot() {
453453

454454
bool ProjMgrWorker::InitializeModel() {
455455
if(m_kernel) {
456-
return true; // already initialized
456+
// kernel is already initialized, clear pdsc map
457+
m_kernel->GetPackRegistry()->ClearPdscMap();
458+
return true;
457459
}
458460
m_packRoot = GetPackRoot();
459461
m_kernel = ProjMgrKernel::Get();
@@ -527,6 +529,8 @@ bool ProjMgrWorker::LoadAllRelevantPacks() {
527529
ProjMgrLogger::Get().Error("failed to load and insert packs");
528530
return CheckRteErrors();
529531
}
532+
// Required packs are loaded: update pack-ids in 'userInputToResolvedPackIdMap'
533+
FormatResolvedPackIds();
530534
if (!m_model->Validate()) {
531535
RtePrintErrorVistior visitor(m_kernel->GetCallback());
532536
m_model->AcceptVisitor(&visitor);
@@ -5949,3 +5953,25 @@ bool ProjMgrWorker::ElaborateVariablesConfigurations() {
59495953
}
59505954
return configurationFound;
59515955
}
5956+
5957+
void ProjMgrWorker::FormatResolvedPackIds() {
5958+
StrMap realPackIds;
5959+
for (const auto& loadedPack : m_loadedPacks) {
5960+
const auto& realPackId = loadedPack->GetPackageID();
5961+
realPackIds[RteUtils::ToLower(realPackId)] = realPackId;
5962+
}
5963+
for (auto& contextName : m_selectedContexts) {
5964+
auto& contextItem = m_contexts[contextName];
5965+
for (auto& [_, resolvedPackIds] : contextItem.userInputToResolvedPackIdMap) {
5966+
StrSet formattedPackIds;
5967+
for (auto& resolvedPackId : resolvedPackIds) {
5968+
const auto& lowerCasePackId = RteUtils::ToLower(resolvedPackId);
5969+
const auto& packId = realPackIds.find(lowerCasePackId) != realPackIds.end() ?
5970+
realPackIds.at(lowerCasePackId) : resolvedPackId;
5971+
formattedPackIds.insert(packId);
5972+
}
5973+
resolvedPackIds = formattedPackIds;
5974+
}
5975+
}
5976+
}
5977+

tools/projmgr/test/data/TestSolution/pack_case_sensitive.csolution.yml renamed to tools/projmgr/test/data/TestSolution/pack_case_insensitive.csolution.yml

File renamed without changes.

tools/projmgr/test/src/ProjMgrTestEnv.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ void ProjMgrTestEnv::SetUp() {
143143
RteFsUtils::CreateDirectories(destInvalidPacks);
144144
fs::copy(fs::path(srcInvalidPacks), fs::path(destInvalidPacks), fs::copy_options::recursive, ec);
145145

146+
// copy PDSCs for case insensitiveness check
147+
string packsCaseInsensitive = testinput_folder + "/packs-case-insensitive";
148+
if (RteFsUtils::Exists(packsCaseInsensitive)) {
149+
RteFsUtils::RemoveDir(packsCaseInsensitive);
150+
}
151+
RteFsUtils::CopyFileExAutoRetry(testcmsispack_folder + "/ARM/RteTest_DFP/0.2.0/ARM.RteTest_DFP.pdsc",
152+
packsCaseInsensitive + "/Arm/RteTest_dfp/0.2.0/arm.rtetest_DFP.pdsc");
153+
RteFsUtils::CopyFileExAutoRetry(testcmsispack_folder + "/ARM/RteTest_DFP/0.1.1/ARM.RteTest_DFP.pdsc",
154+
packsCaseInsensitive + "/ARM/RTETEST_DFP/0.1.1/Arm.RTETEST_DFP.pdsc");
155+
146156
CrossPlatformUtils::SetEnv("CMSIS_PACK_ROOT", testcmsispack_folder);
147157

148158
// create dummy cmsis compiler root
@@ -231,7 +241,13 @@ std::map<std::string, std::string, RtePackageComparator> ProjMgrTestEnv::GetEffe
231241
std::map<std::string, std::string, RtePackageComparator> pdscMap;
232242
RteKernelSlim rteKernel;
233243
rteKernel.SetCmsisPackRoot(GetCmsisPackRoot());
234-
rteKernel.GetEffectivePdscFilesAsMap(pdscMap, bLatestsOnly);
244+
std::list<std::string> pdscFiles;
245+
std::list<RtePackage*> packs;
246+
rteKernel.GetEffectivePdscFiles(pdscFiles, bLatestsOnly);
247+
rteKernel.LoadAndInsertPacks(packs, pdscFiles);
248+
for (const auto& pack : packs) {
249+
pdscMap[pack->GetID()] = pack->GetPackageFileName();
250+
}
235251
return pdscMap;
236252
}
237253

0 commit comments

Comments
 (0)