Skip to content

Commit c27c469

Browse files
spcaipers-armthorstendb-ARMedriouk
authored
[packchk] Validate overview attribute of <description> element is a reference to a markdown file contained in the pack that exists #1682 (#1134) (#1962)
* [packchk] Validate overview attribute of <description> element is a reference to a markdown file contained in the pack that exists #1682 * Test MD file (from middleware) has errors, so shrinked. * foxed md file Co-authored-by: Thorsten de Buhr <[email protected]> Co-authored-by: Evgueni Driouk <[email protected]>
1 parent b7d9059 commit c27c469

File tree

8 files changed

+97
-3
lines changed

8 files changed

+97
-3
lines changed

tools/packchk/src/CheckFiles.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ bool CheckFiles::GetFileName(RteItem* item, std::string& filename, FileType& fil
148148
filename = item->GetText();
149149
return true;
150150
}
151+
else if(tag == "description") {
152+
filename = item->GetAttribute("overview");
153+
if(filename.length()) {
154+
return true;
155+
}
156+
}
151157

152158
return false;
153159
}

tools/packchk/src/PackChk_Msgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ const MsgTable PackChk::msgTable = {
152152
" No condition id set to specify a rule filtering for a device or set of devices." } },
153153
{ "M336", { MsgLevel::LEVEL_WARNING, CRLF_B, "Component 'Cclass=%CCLASS%, Cgroup=%CGROUP%, Cversion=%CVER%, condition=%COND%' is member of the Cclass='%CCLASS%' which shall contain device specific components.\n"\
154154
" The referenced condition id does not contain a rule filtering for a device or set of devices." } }, // No reference to a device or device not found
155-
{ "M337", { MsgLevel::LEVEL_WARNING, CRLF_B, "File with category '%CAT%' has wrong extension '%EXT%': '%PATH%'" } },
155+
{ "M337", { MsgLevel::LEVEL_WARNING, CRLF_B, "File with category '%CAT%' has wrong extension '%EXT%': '%PATH%'%MSG%" } },
156156
{ "M338", { MsgLevel::LEVEL_WARNING, CRLF_B, "No releases found!" } },
157157
{ "M339", { MsgLevel::LEVEL_WARNING, CRLF_B, "Include Path '%PATH%' must not be a file!" } },
158158
{ "M340", { MsgLevel::LEVEL_WARNING, CRLF_B, "Include Path '%PATH%' must end with '/'" } },

tools/packchk/src/ValidateSyntax.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,19 @@ bool ValidateSyntax::CheckInfo(RtePackage* pKg)
239239
bInfoComplete = false;
240240
}
241241

242+
// Check for <description overview="MyPack.md" ...
243+
const auto packDescription = pKg->GetFirstChild("description");
244+
if(packDescription) {
245+
const auto overview = packDescription->GetAttribute("overview");
246+
if(!overview.empty()) {
247+
const auto ext = RteUtils::ExtractFileExtension(overview);
248+
if(ext != "md") {
249+
LogMsg("M337", VAL("CAT", "overview"), EXT(ext), PATH(overview), MSG(", should be .md"));
250+
}
251+
}
252+
}
253+
254+
242255
string pdscRef = pKg->GetAttribute("vendor") + "." + pKg->GetName();
243256
const string& pdscPkg = RteUtils::ExtractFileBaseName(fileName);
244257

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# MDK-Middleware
2+
3+
The MDK-Middleware software pack.
4+
5+
The MDK-Middleware can be used by any user application.
6+
7+
## Availability
8+
9+
The MDK-Middleware is available free-of-charge.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//header 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// tests1.c
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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>DescriptionOverviewPack</name>
7+
<description overview="./Documentation/README.md">Keil MDK Middleware: File System, Network IPv4/IPv6, USB Device/Host</description>
8+
9+
<releases>
10+
<release version="0.0.1" date="2021-09-06">>
11+
Initial release of DescriptionOverview.
12+
</release>
13+
</releases>
14+
15+
<keywords>
16+
<keyword>DescriptionOverview</keyword>
17+
</keywords>
18+
19+
<conditions>
20+
<condition id="Test_Condition">
21+
<description>Test Device</description>
22+
<require Dvendor="ARM:82"/>
23+
</condition>
24+
</conditions>
25+
26+
<components>
27+
<component Cclass="TestClass" Cgroup="TestGlobal" Cversion="1.0.0" condition="Test_Condition">
28+
<description>TestGlobal</description>
29+
<files>
30+
<file category="TestGlobal" name="Files/header1.h"/>
31+
</files>
32+
</component>
33+
</components>
34+
35+
</package>

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,37 @@ TEST_F(PackChkIntegTests, CheckDuplicateFlashAlgo) {
753753
}
754754
}
755755

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

@@ -782,7 +812,6 @@ TEST_F(PackChkIntegTests, CheckConfigFileInIncludePath) {
782812
}
783813
}
784814

785-
786815
// Test schema validation
787816
TEST_F(PackChkIntegTests, CheckSchemaValidation) {
788817
const char* argv[3];

0 commit comments

Comments
 (0)