Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tools/packchk/include/CheckFiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class CheckFiles {
std::string GetFullFilename(const std::string& fileName);
bool GatherIncPathVsAttrConfig(RteItem* item);
bool CheckAttrConfigFiles();
bool CheckCSolutionEntries(RteItem* item);
bool CheckCsolutionLayer(RteItem* item);
bool CheckCsolutionTemplate(RteItem* item);
bool CheckForTag(RteItem* item, const std::list<std::string>& searchAttributes);


private:
std::string m_packagePath;
Expand Down
107 changes: 105 additions & 2 deletions tools/packchk/src/CheckFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ VISIT_RESULT CheckFilesVisitor::Visit(RteItem* item)
m_checkFiles.CheckDeprecated(item);
m_checkFiles.CheckDescription(item);
m_checkFiles.GatherIncPathVsAttrConfig(item);
m_checkFiles.CheckCSolutionEntries(item);


return VISIT_RESULT::CONTINUE_VISIT;
}
Expand Down Expand Up @@ -421,6 +423,11 @@ bool CheckFiles::CheckFileExists(const string& fileName, int lineNo, bool associ

string checkPath = GetFullFilename(fileName);

if(XmlValueAdjuster::IsAbsolute(fileName)) {
LogMsg("M326", PATH(fileName), lineNo); // error : absolute paths are not permitted
return false;
}

bool ok = true;
if(!RteFsUtils::Exists(checkPath)) {
if(associated) {
Expand Down Expand Up @@ -533,7 +540,7 @@ bool CheckFiles::CheckCaseSense(const string& fileName, int lineNo)
}
else {
string errMsg = string("file/folder \"") + seg + "\" not found";
LogMsg("M103", VAL("REF", errMsg));
LogMsg("M103", VAL("REF", errMsg), lineNo);
return false;
}
}
Expand Down Expand Up @@ -899,7 +906,6 @@ bool CheckFiles::CheckFileExtension(RteItem* item)
return ok;
}


bool CheckFiles::GatherIncPathVsAttrConfig(RteItem* item)
{
const auto file = dynamic_cast<RteFile*>(item);
Expand Down Expand Up @@ -952,3 +958,100 @@ bool CheckFiles::CheckAttrConfigFiles()
return bOk;
}

bool CheckFiles::CheckCSolutionEntries(RteItem* item)
{
if(item->GetTag() != "csolution") {
return true;
}

bool bOk = true;
const auto lineNo = item->GetLineNumber();

const auto& children = item->GetChildren();
if(children.empty()) {
LogMsg("M100", lineNo); // No entries for %TAG% found
return false;
}

for(const auto& child : children) {
const auto& tag = child->GetTag();
if(tag == "clayer") {
CheckCsolutionLayer(child);
}
else if(tag == "template") {
CheckCsolutionTemplate(child);
}
}

return bOk;
}

bool CheckFiles::CheckForTag(RteItem* item, const list<string>& searchAttributes)
{
const auto lineNo = item->GetLineNumber();
const auto& tag = item->GetTag();
bool bOk = true;

for(const auto& searchAttr : searchAttributes) {
if(item->GetAttribute(searchAttr) == "") {
LogMsg("M601", TAG(searchAttr), TAG2(tag), lineNo); // '%TAG%' missing on '%TAG2%'
bOk = false;
}
}

return bOk;
}

bool CheckFiles::CheckCsolutionLayer(RteItem* item)
{
CheckForTag(item, list<string>({"type", "path", "file"}));

const auto lineNo = item->GetLineNumber();
const auto& path = item->GetAttribute("path");
const auto& file = item->GetAttribute("file");

if(!path.empty() && !file.empty()) {
const auto fileName = path + "/" + file;
CheckForSpaces(fileName, lineNo);
if(CheckFileExists(fileName, lineNo)) {
CheckCaseSense(fileName, lineNo);
CheckFileIsInPack(fileName, lineNo);
}
}


return true;
}

bool CheckFiles::CheckCsolutionTemplate(RteItem* item)
{
CheckForTag(item, list<string>({"name", "path", "file"}));

const auto lineNo = item->GetLineNumber();
const auto& tag = item->GetTag();
const auto& children = item->GetChildren();
const auto& path = item->GetAttribute("path");
const auto& file = item->GetAttribute("file");

if(!path.empty() && !file.empty()) {
const auto fileName = path + "/" + file;
CheckForSpaces(fileName, lineNo);
if(CheckFileExists(fileName, lineNo)) {
CheckCaseSense(fileName, lineNo);
CheckFileIsInPack(fileName, lineNo);
}
}

bool bFound = false;
for(const auto child : children) {
if(child->GetTag() == "description") {
bFound = true;
}
}

if(!bFound) {
LogMsg("M601", TAG("description"), TAG2(tag), lineNo); // '%TAG%' missing on '%TAG2%'
}

return bFound;
}
1 change: 1 addition & 0 deletions tools/packchk/test/data/CsolutionTag/Files/header1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//header 1
1 change: 1 addition & 0 deletions tools/packchk/test/data/CsolutionTag/Files/test1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// tests1.c
2 changes: 2 additions & 0 deletions tools/packchk/test/data/CsolutionTag/License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
License

56 changes: 56 additions & 0 deletions tools/packchk/test/data/CsolutionTag/TestVendor.CsolutionTag.pdsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>

<package schemaVersion="1.4" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="PACK.xsd">
<vendor>TestVendor</vendor>
<url>https://www.testurl.com/pack/</url>
<name>CsolutionTag</name>
<description>CsolutionTag</description>
<license>License.txt</license>

<releases>
<release version="0.0.1" date="2025-03-05">>
Initial release of CsolutionTag.
</release>
</releases>

<keywords>
<keyword>TestInvalidPack</keyword>
</keywords>

<conditions>
<condition id="Test_Condition">
<description>Test Device</description>
<require Dvendor="ARM:82"/>
</condition>
</conditions>

<components>
<component Cclass="TestClass" Cgroup="TestGlobal" Cversion="1.0.0" condition="Test_Condition">
<description>TestGlobal</description>
<files>
<file category="source" name="Files/test1.c"/>
<file category="TestGlobal" name="Files/header1.h"/>
</files>
</component>
</components>

<csolution>
<clayer type="Board" path="boards/myboard/cmsis/layers/baremetal" file="Board.clayer.yml" copy-to="Board/myboard" condition="Test_Condition"/>
<clayer copy-to="Board/myboard" condition="Not_Exist"/>
<clayer type="Board" path="boards/myboard/cmsis/layers/baremetal" file="NotExist.clayer.yml" copy-to="Board/myboard" condition="Test_Condition"/>
<clayer type="Board" path="/boards/myboard/cmsis/layers/baremetal" file="Board.clayer.yml" copy-to="Board/myboard" condition="Test_Condition"/>

<template name="Simple Device project" path="boards/myboard/cmsis/templates/Device/Simple" file="Simple.csolution.yml" condition="Test_Condition">
<description>Single-core project with no TrustZone </description>
</template>
<template condition="Not_Exist">
</template>
<template name="Simple Device project" path="boards/myboard/cmsis/templates/Device/Simple" file="NotExist.csolution.yml" condition="Test_Condition">
<description>Single-core project with no TrustZone </description>
</template>
<template name="Simple Device project" path="/boards/myboard/cmsis/templates/Device/Simple" file="Simple.csolution.yml" condition="Test_Condition">
<description>Single-core project with no TrustZone </description>
</template>
</csolution>

</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//yaml file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//yaml file
47 changes: 47 additions & 0 deletions tools/packchk/test/integtests/src/PackChkIntegTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,53 @@ TEST_F(PackChkIntegTests, CheckConcurrentComponentFiles) {
}
}

TEST_F(PackChkIntegTests, CheckCsolutionTag) {
const char* argv[3];

string pdscFile = PackChkIntegTestEnv::localtestdata_dir +
"/CsolutionTag/TestVendor.CsolutionTag.pdsc";
ASSERT_TRUE(RteFsUtils::Exists(pdscFile));

argv[0] = (char*)"";
argv[1] = (char*)pdscFile.c_str();
argv[2] = (char*)"--disable-validation";

PackChk packChk;
EXPECT_EQ(1, packChk.Check(3, argv, nullptr));

auto errMsgs = ErrLog::Get()->GetLogMessages();
int M110_foundCnt = 0;
int M500_foundCnt = 0;
int M601_foundCnt = 0;
int M323_foundCnt = 0;
int M326_foundCnt = 0;
int M332_foundCnt = 0;

for (const string& msg : errMsgs) {
if (msg.find("M110", 0) != string::npos) {
M110_foundCnt++;
}
if (msg.find("M500", 0) != string::npos) {
M500_foundCnt++;
}
if (msg.find("M601", 0) != string::npos) {
M601_foundCnt++;
}
if (msg.find("M323", 0) != string::npos) {
M323_foundCnt++;
}
if (msg.find("M326", 0) != string::npos) {
M326_foundCnt++;
}
if (msg.find("M332", 0) != string::npos) {
M332_foundCnt++;
}
}

if(M110_foundCnt != 1 || M500_foundCnt != 2 || M601_foundCnt != 7 || M323_foundCnt != 2 || M326_foundCnt != 2 || M332_foundCnt != 2 ) {
FAIL() << "error: Missing messages testing <csolution> tag";
}
}

TEST_F(PackChkIntegTests, CheckConditionComponentDependency_Pos) {
const char* argv[7];
Expand Down