Skip to content

Commit 200d967

Browse files
[packchk] issue warning for explicit include paths in *.pdsc to config files #1644 (#1136) (#1958)
* [packchk] issue warning for explicit include paths in *.pdsc to config files #1644 --------- Co-authored-by: Thorsten de Buhr <[email protected]>
1 parent 048369b commit 200d967

File tree

7 files changed

+118
-3
lines changed

7 files changed

+118
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@
2020
*.opendb
2121
.vscode
2222
/build*/
23-
**/cmake-*
23+
**/cmake-*
24+
/.cache

tools/packchk/include/ValidateSemantic.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class ValidateSemantic : public Validate
4444
bool FindFileFromList(const std::string& systemHeader, const std::set<RteFile*>& targFiles);
4545
bool CheckDeviceDependencies(RteDeviceItem* device, RteProject* rteProject);
4646
bool HasExternalGenerator(RteComponentAggregate* aggregate);
47-
47+
bool FileIsHeader(const std::string& name);
48+
4849
const std::map<std::string, compiler_s>& GetCompilers() {
4950
return m_compilers;
5051
}

tools/packchk/src/PackChk_Msgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ const MsgTable PackChk::msgTable = {
172172
{ "M354", { MsgLevel::LEVEL_WARNING3, CRLF_B, "Multiple '%FILECAT%' Files found for Component '%COMP%' for '[%VENDOR%] %MCU%' (Compiler: %COMPILER% [%OPTION%])" } },
173173
{ "M355", { MsgLevel::LEVEL_WARNING3, CRLF_B, "No '%FILECAT%' Directory found for Component '%COMP%' (%COMPID%) for '[%VENDOR%] %MCU%' (Compiler: %COMPILER% [%OPTION%])" } },
174174
{ "M356", { MsgLevel::LEVEL_ERROR, CRLF_B, "Path '%PATH%' does not specify a file!" } },
175-
{ "M357", { MsgLevel::LEVEL_WARNING, CRLF_B, "" } },
175+
{ "M357", { MsgLevel::LEVEL_WARNING, CRLF_B, "Config File '%NAME%', which gets copied to project, is also found in the include path to the original pack folder. Do not place config header files in the same directory as regular header files." } },
176176
{ "M358", { MsgLevel::LEVEL_WARNING3, CRLF_B, "Header File '%HFILE%' for '%CFILE%', used by Component '%COMP%' (%COMPID%)\n"\
177177
" for Device '[%VENDOR%] %MCU%' (Compiler: %COMPILER% [%OPTION%]) not found on file system in any include paths: %PATH%" } },
178178
{ "M359", { MsgLevel::LEVEL_WARNING, CRLF_B, "Family has no Device(s) or Subfamilies: '%FAMILY%" } },

tools/packchk/src/ValidateSemantic.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,12 @@ bool ValidateSemantic::FindFileFromList(const string& systemHeader, const set<Rt
450450
return false;
451451
}
452452

453+
bool ValidateSemantic::FileIsHeader(const std::string& name)
454+
{
455+
return RteFsUtils::FileCategoryFromExtension(name) == "header";
456+
}
457+
458+
453459
/**
454460
* @brief Check device dependencies. Tests if all dependencies are solved and a minimum
455461
* on support files and configuration has been defined
@@ -526,6 +532,7 @@ bool ValidateSemantic::CheckDeviceDependencies(RteDeviceItem *device, RteProject
526532

527533
for(auto aggregate : startupComponents) {
528534
ErrLog::Get()->SetFileName(aggregate->GetPackage()->GetPackageFileName());
535+
string targetPath = RteUtils::ExtractFilePath(aggregate->GetPackage()->GetPackageFileName(), false);
529536

530537
for(auto &[componentKey, componentMap] : aggregate->GetAllComponents()) {
531538
int foundSystemC = 0, foundStartup = 0;
@@ -569,6 +576,15 @@ bool ValidateSemantic::CheckDeviceDependencies(RteDeviceItem *device, RteProject
569576
}
570577
const string& attribute = file->GetAttribute("attr");
571578

579+
if(attribute == "config" && FileIsHeader(fileName)) {
580+
const string& fullFileName = targetPath + "/" + file->GetName();
581+
const string hPath = RteUtils::ExtractFilePath(fullFileName, false);
582+
const auto incPathFound = incPaths.find(hPath);
583+
if(incPathFound != incPaths.end()) {
584+
LogMsg("M357", NAME(file->GetName()), file->GetLineNumber());
585+
}
586+
}
587+
572588
if(FindName(fileName, "system_", ".c")) {
573589
foundSystemC++;
574590
lineSystem = file->GetLineNumber();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//header 1
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<package schemaVersion="1.4" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="PACK.xsd">
4+
<vendor>TestVendor</vendor>
5+
<url>http://www.testurl.com/pack/</url>
6+
<name>ConfigFileInIncludePathPack</name>
7+
<description>Include Path vs Config File. Files that have attr=config in the *.pdsc are copied to the project. An include path is automatically generated.
8+
It is a potential risk to add an additional include path to original location in the *.pdsc file. This file does not contain configuration settings.
9+
It depends on the search order of the compiler to pickup the right header file (as effectively the same header file name is twice in the search path).</description>
10+
11+
<releases>
12+
<release version="0.0.1" date="2021-09-06">>
13+
Initial release of ConfigFileInIncludePath.
14+
</release>
15+
</releases>
16+
17+
<keywords>
18+
<keyword>ConfigFileInIncludePath</keyword>
19+
</keywords>
20+
21+
<conditions>
22+
<condition id="TestDevices">
23+
<description>Test devices</description>
24+
<require Dvendor="ARM:82" Dname="Test*"/>
25+
</condition>
26+
<condition id="Test ARMCC">
27+
<description>filter for STM32F1xx Value Line Low Density Device and the ARM compiler</description>
28+
<require condition="TestDevices"/>
29+
<require Tcompiler="ARMCC"/>
30+
</condition>
31+
</conditions>
32+
33+
<devices>
34+
<family Dfamily="TestFamily" Dvendor="ARM:82">
35+
<algorithm name="Flash/ARMCMx_512.FLM" start="0x00000000" size="0x00040000" default="1"/>
36+
37+
<!-- ****************************** TestSubFamily ****************************** -->
38+
<subFamily DsubFamily="TestSubFamily">
39+
<compile header="Files/TestDevicesFoo.h" define="TESTDEVICES"/>
40+
41+
<description>
42+
The TestSubFamily is ...
43+
</description>
44+
45+
<!-- ****************************** TestDevice1 ***************************** -->
46+
<device Dname="TestDevice1">
47+
<processor Dcore="Cortex-M4" DcoreVersion="r0p1" Dfpu="SP_FPU" Dmpu="MPU" Dendian="Little-endian" Dclock="204000000"/>
48+
<memory id="IROM1" start="0x00000000" size="0x00040000" default="1" startup="1"/>
49+
<memory id="IRAM1" start="0x10000000" size="0x00010000" default="1" init ="0"/>
50+
<memory id="IRAM2" start="0x20000000" size="0x00010000" default="0" init ="0"/>
51+
</device>
52+
</subFamily>
53+
</family>
54+
</devices>
55+
56+
<components>
57+
<component Cclass="Device" Cgroup="Startup" Cversion="1.0.0" condition="TestDevices">
58+
<description>System Startup for STMicroelectronics STM32F1xx device series</description>
59+
<files>
60+
<file category="include" name="Files/"/>
61+
<file category="source" name="Files/header1.h" attr="config" version="1.0.0" condition="Test ARMCC"/>
62+
</files>
63+
</component>
64+
</components>
65+
66+
</package>

tools/packchk/test/integtests/src/PackChkIntegTests.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,36 @@ TEST_F(PackChkIntegTests, CheckDuplicateFlashAlgo) {
753753
}
754754
}
755755

756+
// Validate invalid file path (file is directory)
757+
TEST_F(PackChkIntegTests, CheckConfigFileInIncludePath) {
758+
const char* argv[3];
759+
760+
const string& pdscFile = PackChkIntegTestEnv::localtestdata_dir +
761+
"/ConfigFileInIncludePath/TestVendor.ConfigFileInIncludePathPack.pdsc";
762+
ASSERT_TRUE(RteFsUtils::Exists(pdscFile));
763+
764+
argv[0] = (char*)"";
765+
argv[1] = (char*)pdscFile.c_str();
766+
argv[2] = (char *)"--disable-validation";
767+
768+
PackChk packChk;
769+
EXPECT_EQ(0, packChk.Check(3, argv, nullptr));
770+
771+
auto errMsgs = ErrLog::Get()->GetLogMessages();
772+
int M357_foundCnt = 0;
773+
for (const string& msg : errMsgs) {
774+
size_t s;
775+
if ((s = msg.find("M357")) != string::npos) {
776+
M357_foundCnt++;
777+
}
778+
}
779+
780+
if (!M357_foundCnt) {
781+
FAIL() << "error: missing message M357";
782+
}
783+
}
784+
785+
756786
// Test schema validation
757787
TEST_F(PackChkIntegTests, CheckSchemaValidation) {
758788
const char* argv[3];

0 commit comments

Comments
 (0)