Skip to content

Commit b93c61a

Browse files
[packchk] Report warning when deprecated attribute attr="copy" is used in <file> element #1371 (#1143) (#1967)
* [packchk] Report warning when deprecated attribute attr="copy" is used in <file> element #1371 Co-authored-by: Thorsten de Buhr <[email protected]>
1 parent edb794c commit b93c61a

File tree

6 files changed

+113
-4
lines changed

6 files changed

+113
-4
lines changed

tools/packchk/include/CheckFiles.h

Lines changed: 2 additions & 1 deletion
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
*/
@@ -31,6 +31,7 @@ class CheckFiles {
3131
const std::string& GetPackagePath() const;
3232
bool CheckFile(RteItem* item);
3333
bool CheckUrls(RteItem* item);
34+
bool CheckDeprecated(RteItem* item);
3435
bool CheckDescription(RteItem* item);
3536
bool CheckFileExists(const std::string& fileName, int lineNo, bool associated = false);
3637
bool CheckCaseSense(const std::string& fileName, int lineNo);

tools/packchk/src/CheckFiles.cpp

Lines changed: 27 additions & 1 deletion
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
*/
@@ -41,6 +41,7 @@ VISIT_RESULT CheckFilesVisitor::Visit(RteItem* item)
4141
{
4242
m_checkFiles.CheckFile(item);
4343
m_checkFiles.CheckUrls(item);
44+
m_checkFiles.CheckDeprecated(item);
4445
m_checkFiles.CheckDescription(item);
4546

4647
return VISIT_RESULT::CONTINUE_VISIT;
@@ -172,6 +173,31 @@ bool CheckFiles::ToUpper(string& text)
172173
return true;
173174
}
174175

176+
/**
177+
* @brief check deprecated aspects of an RTE item
178+
* @param item RteItem item to check
179+
* @return passed / failed
180+
*/
181+
bool CheckFiles::CheckDeprecated(RteItem* item)
182+
{
183+
if(!item || item->GetTag() == "package") {
184+
return true;
185+
}
186+
187+
bool bOk = true;
188+
const auto lineNo = item->GetLineNumber();
189+
190+
const auto& tag = item->GetTag();
191+
if(tag == "file") {
192+
if(item->GetAttribute("attr") == "copy") {
193+
LogMsg("M600", VAL("ATTR", "copy"), TAG(tag), lineNo);
194+
bOk = false;
195+
}
196+
}
197+
198+
return bOk;
199+
}
200+
175201
/**
176202
* @brief check aspects of an RTE url item
177203
* @param item RteItem item to check

tools/packchk/src/PackChk_Msgs.cpp

Lines changed: 15 additions & 1 deletion
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
*/
@@ -230,6 +230,20 @@ const MsgTable PackChk::msgTable = {
230230

231231
{ "M510", { MsgLevel::LEVEL_WARNING, CRLF_B, "Xerxes reports: %MSG%" } },
232232
{ "M511", { MsgLevel::LEVEL_ERROR, CRLF_B, "Xerxes reports: %MSG%" } },
233+
234+
// 600... further PackCHk Errors
235+
{ "M600", { MsgLevel::LEVEL_WARNING, CRLF_B, "Attribute '%ATTR%' on '%TAG%' is deprecated." } },
236+
{ "M601", { MsgLevel::LEVEL_WARNING, CRLF_B, "" } },
237+
{ "M602", { MsgLevel::LEVEL_WARNING, CRLF_B, "" } },
238+
{ "M603", { MsgLevel::LEVEL_WARNING, CRLF_B, "" } },
239+
{ "M604", { MsgLevel::LEVEL_WARNING, CRLF_B, "" } },
240+
{ "M605", { MsgLevel::LEVEL_WARNING, CRLF_B, "" } },
241+
{ "M606", { MsgLevel::LEVEL_WARNING, CRLF_B, "" } },
242+
{ "M607", { MsgLevel::LEVEL_WARNING, CRLF_B, "" } },
243+
{ "M608", { MsgLevel::LEVEL_WARNING, CRLF_B, "" } },
244+
{ "M609", { MsgLevel::LEVEL_WARNING, CRLF_B, "" } },
245+
{ "M610", { MsgLevel::LEVEL_WARNING, CRLF_B, "" } },
246+
233247
};
234248

235249
const MsgTableStrict PackChk::msgStrictTable = {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//header 1
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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>https://www.testurl.com/pack/</url>
6+
<name>FileAttributeDeprecated</name>
7+
<description>Test for deprecated file attributes</description>
8+
9+
<releases>
10+
<release version="0.0.1" date="2025-02-17">>
11+
Initial release of FileAttributeDeprecated.
12+
</release>
13+
</releases>
14+
15+
<keywords>
16+
<keyword>FileAttributeDeprecated</keyword>
17+
</keywords>
18+
19+
<conditions>
20+
<condition id="TestDevices">
21+
<description>Test devices</description>
22+
<require Dvendor="ARM:82" Dname="Test*"/>
23+
</condition>
24+
<condition id="Test ARMCC">
25+
<description>filter for the Device and the ARM compiler</description>
26+
<require condition="TestDevices"/>
27+
<require Tcompiler="ARMCC"/>
28+
</condition>
29+
</conditions>
30+
31+
<components>
32+
<component Cclass="Device" Cgroup="Startup" Cversion="1.0.0" condition="TestDevices">
33+
<description>Test device series</description>
34+
<files>
35+
<file category="source" name="Files/header1.h" attr="copy" version="1.0.0" condition="Test ARMCC"/>
36+
</files>
37+
</component>
38+
</components>
39+
40+
</package>

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

Lines changed: 28 additions & 1 deletion
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
*/
@@ -996,6 +996,33 @@ TEST_F(PackChkIntegTests, CheckSupportCcFiles) {
996996
}
997997
}
998998

999+
TEST_F(PackChkIntegTests, CheckFileAttributeDeprecated) {
1000+
const char* argv[3];
1001+
1002+
string pdscFile = PackChkIntegTestEnv::localtestdata_dir +
1003+
"/FileAttributeDeprecated/TestVendor.FileAttributeDeprecated.pdsc";
1004+
ASSERT_TRUE(RteFsUtils::Exists(pdscFile));
1005+
1006+
argv[0] = (char*)"";
1007+
argv[1] = (char*)pdscFile.c_str();
1008+
argv[2] = (char*)"--disable-validation";
1009+
1010+
PackChk packChk;
1011+
EXPECT_EQ(0, packChk.Check(3, argv, nullptr));
1012+
1013+
auto errMsgs = ErrLog::Get()->GetLogMessages();
1014+
int M600_foundCnt = 0;
1015+
for (const string& msg : errMsgs) {
1016+
if (msg.find("M600", 0) != string::npos) {
1017+
M600_foundCnt++;
1018+
}
1019+
}
1020+
1021+
if(!M600_foundCnt) {
1022+
FAIL() << "error: Missing message M600: deprecated attributes";
1023+
}
1024+
}
1025+
9991026
TEST_F(PackChkIntegTests, CheckConditionComponentDependency_Pos) {
10001027
const char* argv[7];
10011028

0 commit comments

Comments
 (0)