Skip to content

Commit 7f0633f

Browse files
[packchk] Add validation that a source module cannot be concurrently added to a project by multiple components #1499 (#1158)
* [packchk] Add validation that a source module cannot be concurrently added to a project by multiple components #1499
1 parent 4c82f1f commit 7f0633f

File tree

13 files changed

+175
-1
lines changed

13 files changed

+175
-1
lines changed

tools/packchk/include/CheckComponents.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ class CheckComponent
2121
bool CheckComp(RteItem* item);
2222
bool ConditionRefToDevice(RteItem* item);
2323
bool TestSubConditions(RteCondition* cond);
24+
bool CheckAllCompFiles(RteItem* item);
2425

2526
private:
2627
std::string m_packagePath;
2728
RteGlobalModel& m_rteModel;
29+
std::map<std::string, RteItem*> m_allFiles;
2830
};
2931

3032
class ComponentsVisitor : public RteVisitor

tools/packchk/src/CheckComponents.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "CheckComponents.h"
77
#include "CheckFiles.h"
88

9+
#include "RteComponent.h"
910
#include "RteModel.h"
1011
#include "RteUtils.h"
1112
#include "ErrLog.h"
@@ -21,10 +22,60 @@ using namespace std;
2122
VISIT_RESULT ComponentsVisitor::Visit(RteItem* item)
2223
{
2324
m_checkComponent.CheckComp(item);
25+
m_checkComponent.CheckAllCompFiles(item);
2426

2527
return VISIT_RESULT::CONTINUE_VISIT;
2628
}
2729

30+
/**
31+
* @brief Check all files of all component. Physically the same files should not be referenced by multiple components.
32+
* @param item element to test
33+
* @return passed / failed
34+
*/
35+
bool CheckComponent::CheckAllCompFiles(RteItem* component)
36+
{
37+
bool ok = true;
38+
if(!component) {
39+
return ok;
40+
}
41+
42+
int lineNo = component->GetLineNumber();
43+
string tag = component->GetTag();
44+
if(tag != "component") {
45+
return true;
46+
}
47+
48+
const auto& compName = component->GetID();
49+
const auto files = component->GetGrandChildren("files");
50+
for(const auto file : files) {
51+
const auto& category = file->GetAttribute("category");
52+
if(category == "library" ||
53+
category == "object" ||
54+
category == "source" ||
55+
category == "sourceC" ||
56+
category == "sourceCpp" ||
57+
category == "sourceAsm" ||
58+
category == "genSource") {
59+
const auto key = file->GetName()
60+
+ ':' + file->GetConditionID()
61+
+ ':' + component->GetCvariantName()
62+
+ ':' + component->GetCbundleName()
63+
+ ':' + component->GetConditionID();
64+
65+
const auto foundIt = m_allFiles.find(key);
66+
if(foundIt != m_allFiles.end()) {
67+
const auto& foundFilename = foundIt->first;
68+
const auto foundItem = foundIt->second;
69+
LogMsg("M610", VAL("CAT", category), NAME(foundFilename), NAME2(compName), LINE(lineNo), foundItem->GetLineNumber());
70+
continue;
71+
}
72+
m_allFiles[key] = file;
73+
}
74+
}
75+
76+
return ok;
77+
}
78+
2879
/**
2980
* @brief Check a component. Iterate over all tests.
3081
* @param item element to test

tools/packchk/src/PackChk_Msgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ const MsgTable PackChk::msgTable = {
242242
{ "M607", { MsgLevel::LEVEL_WARNING, CRLF_B, "Tag '%TAG%' does not allow wildcard specification: '%NAME%'" } },
243243
{ "M608", { MsgLevel::LEVEL_WARNING, CRLF_B, "Memory '%NAME%' with '%ATTR%'='%VALUE%' must have '%ATTR2%'='%VALUE2%'" } },
244244
{ "M609", { MsgLevel::LEVEL_WARNING, CRLF_B, "Processor '%NAME%': Exact one memory with attribute \"startup=1\" must be configured, but found %NUM%" } },
245-
{ "M610", { MsgLevel::LEVEL_WARNING, CRLF_B, "" } },
245+
{ "M610", { MsgLevel::LEVEL_WARNING, CRLF_B, "File category '%CAT%': '%NAME%' redefined in component '%NAME2%', see Line %LINE%" } },
246246

247247
};
248248

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<package schemaVersion="1.4.9" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="PACK.xsd">
4+
<vendor>ARM</vendor>
5+
<url>https://www.keil.com/pack/</url>
6+
<name>ConcurrentComponentFiles</name>
7+
<description>[packchk] Add validation that a source module cannot be concurrently added to a project by multiple components #1499</description>
8+
<license>TestLicense.txt</license>
9+
10+
<releases>
11+
<release version="1.0.0" date="2025-02-24">
12+
Added test
13+
</release>
14+
</releases>
15+
16+
<conditions>
17+
<condition id="TestDevices">
18+
<description>Test devices</description>
19+
<require Dvendor="ARM:82" Dname="Test*"/>
20+
</condition>
21+
<condition id="TestDevices2">
22+
<description>Test devices</description>
23+
<require Dvendor="ARM:82" Dname="Test2*"/>
24+
</condition>
25+
<condition id="Test ARMCC">
26+
<description>filter for Test Device and the ARM compiler</description>
27+
<require condition="TestDevices"/>
28+
<require Tcompiler="ARMCC"/>
29+
</condition>
30+
</conditions>
31+
32+
<devices>
33+
<family Dfamily="TestFamily" Dvendor="ARM:82">
34+
<algorithm name="Flash/ARMCMx_512.FLM" start="0x00000000" size="0x00040000" default="1"/>
35+
36+
<!-- ****************************** TestSubFamily ****************************** -->
37+
<subFamily DsubFamily="TestSubFamily">
38+
<compile header="Files/TestDevices.h" define="TESTDEVICES"/>
39+
40+
<description>
41+
The TestSubFamily is ...
42+
</description>
43+
44+
<!-- ****************************** TestDeviceOk ***************************** -->
45+
<device Dname="TestDeviceOk">
46+
<processor Dcore="Cortex-M4" DcoreVersion="r0p1" Dfpu="SP_FPU" Dmpu="MPU" Ddsp="NO_DSP" Dendian="Little-endian" Dclock="204000000"/>
47+
<memory name="Flash" access="rx" start="0x08000000" size="0x00080000" default="1" startup="1" />
48+
<memory name="IRAM1" access="rwx" start="0x10000000" size="0x00010000" default="1" />
49+
<memory name="IRAM2" access="rwx" start="0x20000000" size="0x00010000" default="0" />
50+
</device>
51+
52+
<!-- ****************************** TestDeviceOk ***************************** -->
53+
<device Dname="Test2DeviceOk">
54+
<processor Dcore="Cortex-M4" DcoreVersion="r0p1" Dfpu="SP_FPU" Dmpu="MPU" Ddsp="NO_DSP" Dendian="Little-endian" Dclock="204000000"/>
55+
<memory name="Flash" access="rx" start="0x08000000" size="0x00080000" default="1" startup="1" />
56+
<memory name="IRAM1" access="rwx" start="0x10000000" size="0x00010000" default="1" />
57+
<memory name="IRAM2" access="rwx" start="0x20000000" size="0x00010000" default="0" />
58+
</device>
59+
60+
</subFamily>
61+
</family>
62+
</devices>
63+
64+
<components>
65+
<component Cclass="Device" Cgroup="Startup" Cversion="1.0.0" condition="TestDevices">
66+
<description>System Startup for STMicroelectronics STM32F1xx device series</description>
67+
<files>
68+
<file category="include" name="Files/"/>
69+
<file category="source" name="Files/startup_Test.s" attr="config" version="1.0.0" condition="Test ARMCC"/>
70+
<file category="source" name="Files/system_Test.c" attr="config" version="1.0.0" />
71+
</files>
72+
</component>
73+
74+
<component Cclass="Device" Cgroup="TestComponent1" Cversion="1.0.0" condition="TestDevices">
75+
<description>Test Component 1</description>
76+
<files>
77+
<file category="source" name="Files/startup_Test.s" condition="Test ARMCC" />
78+
<file category="source" name="Files/system_Test.c" condition="Test ARMCC" />
79+
</files>
80+
</component>
81+
82+
<component Cclass="Device" Cgroup="TestComponent2" Cversion="1.0.0" condition="TestDevices2">
83+
<description>Test Component 1</description>
84+
<files>
85+
<file category="source" name="Files/startup_Test.s" condition="Test ARMCC" />
86+
<file category="source" name="Files/system_Test.c" condition="Test ARMCC" />
87+
</files>
88+
</component>
89+
90+
</components>
91+
92+
93+
</package>

tools/packchk/test/data/ConcurrentComponentFiles/Files/TestDevices.h

Whitespace-only changes.

tools/packchk/test/data/ConcurrentComponentFiles/Files/startup_Test.s

Whitespace-only changes.

tools/packchk/test/data/ConcurrentComponentFiles/Files/system_Test.c

Whitespace-only changes.

tools/packchk/test/data/ConcurrentComponentFiles/Files/system_Test.h

Whitespace-only changes.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)