Skip to content

Commit 597de91

Browse files
authored
[projmgr] Check loaded pack requirements
1 parent 295825a commit 597de91

File tree

8 files changed

+100
-12
lines changed

8 files changed

+100
-12
lines changed

tools/projmgr/include/ProjMgrUtils.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,15 @@ class ProjMgrUtils {
265265
*/
266266
static const std::string FormatPath(const std::string& original, const std::string& directory, bool useAbsolutePaths = false);
267267

268+
/**
269+
* @brief check if list contains incompatible version of pack requirement
270+
* @param list of packs
271+
* @param string pack requirement
272+
* @return true if incompatible pack is found
273+
*/
274+
static bool ContainsIncompatiblePack(const std::list<RtePackage*>& packs, const std::string& requirement);
275+
268276
protected:
269-
static std::string ConstructID(const std::vector<std::pair<const char*, const std::string&>>& elements);
270277
/**
271278
* @brief get filtered list of contexts
272279
* @param allContexts list of all available contexts

tools/projmgr/src/ProjMgrUtils.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,19 @@ const string ProjMgrUtils::FormatPath(const string& original, const string& dire
416416
}
417417
return path;
418418
}
419+
420+
bool ProjMgrUtils::ContainsIncompatiblePack(const std::list<RtePackage*>& packs, const std::string& requirement) {
421+
bool incompatible = false;
422+
for (const auto& p : packs) {
423+
const auto& id = p->GetPackageID();
424+
if (RtePackage::VendorFromId(id) == RtePackage::VendorFromId(requirement) &&
425+
RtePackage::NameFromId(id) == RtePackage::NameFromId(requirement)) {
426+
if (VersionCmp::RangeCompare(RtePackage::VersionFromId(id), RtePackage::VersionFromId(requirement)) != 0) {
427+
incompatible = true;
428+
} else {
429+
return false;
430+
}
431+
}
432+
}
433+
return incompatible;
434+
}

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -504,17 +504,14 @@ bool ProjMgrWorker::LoadPacks(ContextItem& context) {
504504

505505
bool ProjMgrWorker::CheckMissingPackRequirements(const std::string& contextName)
506506
{
507-
if(!m_debug) {
508-
// perform check only in debug mode
509-
return true;
510-
}
511507
bool bRequiredPacksLoaded = true;
512508
// check if all pack requirements are fulfilled
513509
for(auto pack : m_loadedPacks) {
514510
RtePackageMap allRequiredPacks;
515511
pack->GetRequiredPacks(allRequiredPacks, m_model);
516512
for(auto [id, p] : allRequiredPacks) {
517-
if(!p) {
513+
bool incompatible = ProjMgrUtils::ContainsIncompatiblePack(m_loadedPacks, id);
514+
if((!p && m_debug) || incompatible) {
518515
bRequiredPacksLoaded = false;
519516
string msg;
520517
if(!contextName.empty()) {
@@ -3673,13 +3670,11 @@ bool ProjMgrWorker::ProcessContext(ContextItem& context, bool loadGenFiles, bool
36733670
ret &= ProcessConfigFiles(context);
36743671
ret &= ProcessComponentFiles(context);
36753672
ret &= ProcessExecutes(context);
3676-
bool bUnresolvedDependencies = false;
36773673
if (resolveDependencies) {
36783674
// TODO: Add uniquely identified missing dependencies to RTE Model
36793675

36803676
// Get dependency validation results
36813677
if (!ValidateContext(context)) {
3682-
bUnresolvedDependencies = true;
36833678
string msg = "dependency validation for context '" + context.name + "' failed:";
36843679
set<string> results;
36853680
FormatValidationResults(results, context);
@@ -3693,9 +3688,7 @@ bool ProjMgrWorker::ProcessContext(ContextItem& context, bool loadGenFiles, bool
36933688
}
36943689
}
36953690
}
3696-
if(!ret || bUnresolvedDependencies) {
3697-
CheckMissingPackRequirements(context.name);
3698-
}
3691+
CheckMissingPackRequirements(context.name);
36993692
return ret;
37003693
}
37013694

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/cproject.schema.json
2+
3+
project:
4+
components:
5+
- component: Startup
6+
- component: CORE
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
8+
build-types:
9+
- type: Debug
10+
compiler: AC6
11+
12+
packs:
13+
- pack: ARM::[email protected]
14+
- pack: ARM::RteTestRequired
15+
path: ./packs/required
16+
17+
projects:
18+
- project: ./incompatible.cproject.yml
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<package schemaVersion="1.3" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="PACK.xsd">
4+
<name>RteTestRequired</name>
5+
<description>Local pack 1.0</description>
6+
<vendor>ARM</vendor>
7+
8+
<releases>
9+
<release version="1.0.0" date="2024-11-27">
10+
Local version
11+
</release>
12+
</releases>
13+
14+
<requirements>
15+
<packages>
16+
<package vendor="ARM" name="RteTest_DFP" version="3.0.0"/>
17+
</packages>
18+
</requirements>
19+
20+
</package>

tools/projmgr/test/src/ProjMgrUnitTests.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,27 @@ TEST_F(ProjMgrUnitTests, RunProjMgr_Packs_Required_Warning) {
219219
}
220220
streamRedirect.ClearStringStreams();
221221
argv[7] = (char*)"test1.Release+CM0";
222-
EXPECT_EQ(0, RunProjMgr(9, argv, m_envp)); // succeeds regardless missing pack requirement => no pack warnings
222+
EXPECT_EQ(0, RunProjMgr(8, argv, m_envp)); // succeeds regardless missing pack requirement => no pack warnings
223223
errStr = streamRedirect.GetErrorString();
224224
for(auto& w : warnings) {
225225
EXPECT_FALSE(errStr.find(w) != string::npos);
226226
}
227227
}
228228

229+
TEST_F(ProjMgrUnitTests, RunProjMgr_Incompatible_Packs_Required_Warning) {
230+
StdStreamRedirect streamRedirect;
231+
const string warning = {
232+
"pack 'ARM::[email protected]' required by pack 'ARM::[email protected]' is not specified"
233+
};
234+
const string csolution = testinput_folder + "/TestSolution/PackRequirements/incompatible.csolution.yml";
235+
char* argv[3];
236+
argv[1] = (char*)"convert";
237+
argv[2] = (char*)csolution.c_str();
238+
EXPECT_EQ(0, RunProjMgr(3, argv, m_envp));
239+
auto errStr = streamRedirect.GetErrorString();
240+
EXPECT_TRUE(errStr.find(warning) != string::npos);
241+
}
242+
229243
TEST_F(ProjMgrUnitTests, RunProjMgr_ListPacks) {
230244
map<std::pair<string, string>, string> testInputs = {
231245
{{"TestSolution/test.csolution.yml", "test1.Debug+CM0"}, "ARM::[email protected]" },

tools/projmgr/test/src/ProjMgrUtilsUnitTests.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,3 +510,17 @@ TEST_F(ProjMgrUtilsUnitTests, FormatPath) {
510510
EXPECT_EQ("X:/Non_Existent/Absolute", ProjMgrUtils::FormatPath("X:/Non_Existent/Absolute", testoutput_folder));
511511
}
512512
}
513+
514+
TEST_F(ProjMgrUtilsUnitTests, ContainsIncompatiblePack) {
515+
ProjMgrKernel::Get()->SetCmsisPackRoot(testcmsispack_folder);
516+
std::list<std::string> pdscFiles;
517+
std::list<RtePackage*> loadedPacks;
518+
auto kernel = ProjMgrKernel::Get();
519+
kernel->GetEffectivePdscFiles(pdscFiles);
520+
kernel->LoadAndInsertPacks(loadedPacks, pdscFiles);
521+
522+
EXPECT_FALSE(ProjMgrUtils::ContainsIncompatiblePack(loadedPacks, "ARM::[email protected]:0.2.0"));
523+
EXPECT_FALSE(ProjMgrUtils::ContainsIncompatiblePack(loadedPacks, "ARM::[email protected]"));
524+
EXPECT_TRUE(ProjMgrUtils::ContainsIncompatiblePack(loadedPacks, "ARM::[email protected]"));
525+
EXPECT_FALSE(ProjMgrUtils::ContainsIncompatiblePack(loadedPacks, "Unknown::[email protected]"));
526+
}

0 commit comments

Comments
 (0)