Skip to content

Commit 34a5d2f

Browse files
[packchk] issue warning for explicit include paths in *.pdsc to config files #1644 (#1999)
* [packchk] issue warning for explicit include paths in *.pdsc to config files #1644 * fixed test Co-authored-by: Thorsten de Buhr <[email protected]>
1 parent d2881e2 commit 34a5d2f

File tree

6 files changed

+72
-4
lines changed

6 files changed

+72
-4
lines changed

tools/packchk/include/CheckFiles.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ class CheckFiles {
4949
bool GetFileName(RteItem* item, std::string& filename, FileType& fileType) const;
5050
bool ToUpper(std::string& text);
5151
std::string GetFullFilename(const std::string& fileName);
52+
bool GatherIncPathVsAttrConfig(RteItem* item);
53+
bool CheckAttrConfigFiles();
5254

5355
private:
5456
std::string m_packagePath;
5557
std::string m_packageName;
58+
std::map<std::string, RteItem*> m_includePaths;
59+
std::map<std::string, RteItem*> m_attrConfigFiles;
5660
};
5761

5862
class CheckFilesVisitor : public RteVisitor

tools/packchk/src/CheckFiles.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ CheckFilesVisitor::CheckFilesVisitor(const string& packagePath, const string& pa
3030
*/
3131
CheckFilesVisitor::~CheckFilesVisitor()
3232
{
33+
m_checkFiles.CheckAttrConfigFiles();
3334
}
3435

3536
/**
@@ -43,6 +44,7 @@ VISIT_RESULT CheckFilesVisitor::Visit(RteItem* item)
4344
m_checkFiles.CheckUrls(item);
4445
m_checkFiles.CheckDeprecated(item);
4546
m_checkFiles.CheckDescription(item);
47+
m_checkFiles.GatherIncPathVsAttrConfig(item);
4648

4749
return VISIT_RESULT::CONTINUE_VISIT;
4850
}
@@ -896,3 +898,57 @@ bool CheckFiles::CheckFileExtension(RteItem* item)
896898

897899
return ok;
898900
}
901+
902+
903+
bool CheckFiles::GatherIncPathVsAttrConfig(RteItem* item)
904+
{
905+
const auto file = dynamic_cast<RteFile*>(item);
906+
if(!file) {
907+
return true;
908+
}
909+
910+
if(file->IsTemplate()) { // ignore
911+
return true;
912+
}
913+
914+
const auto category = file->GetCategory();
915+
916+
if(file->IsConfig()) {
917+
const auto path = file->GetOriginalAbsolutePath();
918+
m_attrConfigFiles[path] = file;
919+
return true;
920+
}
921+
922+
if(category == RteFile::Category::HEADER) {
923+
const auto incPath = file->GetIncludePath();
924+
m_includePaths[incPath] = file;
925+
return true;
926+
}
927+
928+
if(category == RteFile::Category::INCLUDE) {
929+
const auto incPath = file->GetOriginalAbsolutePath();
930+
m_includePaths[incPath] = file;
931+
return true;
932+
}
933+
934+
935+
return true;
936+
}
937+
938+
bool CheckFiles::CheckAttrConfigFiles()
939+
{
940+
bool bOk = true;
941+
942+
for(const auto& [path, item] : m_attrConfigFiles) {
943+
const auto lineNo = item->GetLineNumber();
944+
const auto incPathFound = m_includePaths.find(RteUtils::ExtractFilePath(path, false));
945+
if(incPathFound != m_includePaths.end()) {
946+
const auto itemFound = incPathFound->second;
947+
LogMsg("M357", NAME(item->GetName()), LINE(itemFound->GetLineNumber()), lineNo);
948+
bOk = false;
949+
}
950+
}
951+
952+
return bOk;
953+
}
954+

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, "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." } },
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. See Line %LINE%" } },
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%" } },
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//header 1

tools/packchk/test/data/ConfigFileInIncludePath/TestVendor.ConfigFileInIncludePathPack.pdsc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,18 @@ The TestSubFamily is ...
5858
<description>System Startup for STMicroelectronics STM32F1xx device series</description>
5959
<files>
6060
<file category="include" name="Files/"/>
61-
<file category="source" name="Files/header1.h" attr="config" version="1.0.0" condition="Test ARMCC"/>
62-
<file category="header" name="Header/header1.h" version="1.0.0" condition="Test ARMCC"/>
61+
<file category="source" name="Files/header1.h" attr="config" version="1.0.0" condition="Test ARMCC"/>
62+
<file category="header" name="Header/header1.h" version="1.0.0" condition="Test ARMCC"/>
6363
<file category="header" name="Header/header2.h" attr="config" version="1.0.0" condition="Test ARMCC"/>
6464
</files>
6565
</component>
66+
67+
<component Cclass="Device" Cgroup="TestComponent" Cversion="1.0.0" condition="TestDevices">
68+
<description>System Startup for STMicroelectronics STM32F1xx device series</description>
69+
<files>
70+
<file category="header" name="Header/header3.h" attr="config" version="1.0.0" condition="Test ARMCC"/>
71+
</files>
72+
</component>
6673
</components>
6774

6875
</package>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ TEST_F(PackChkIntegTests, CheckConfigFileInIncludePath) {
863863
}
864864
}
865865

866-
if (M357_foundCnt != 2) {
866+
if (M357_foundCnt != 5) {
867867
FAIL() << "error: missing message M357";
868868
}
869869
}

0 commit comments

Comments
 (0)