Skip to content

Commit

Permalink
[rtefsutils] Ensure canonical directory separator
Browse files Browse the repository at this point in the history
  • Loading branch information
spcaipers-arm authored Dec 4, 2024
1 parent a5bb591 commit 781d198
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion libs/rtefsutils/src/RteFsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ using namespace std;
string RteFsUtils::MakePathCanonical(const string& path)
{
error_code ec;
string canonical = fs::weakly_canonical(path, ec).generic_string();
string canonical = fs::weakly_canonical(RteUtils::BackSlashesToSlashes(path), ec).generic_string();
if (ec) {
// canonical call failed, e.g. path does not exist
return path;
Expand Down
14 changes: 10 additions & 4 deletions libs/rtefsutils/test/src/RteFsUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ const string filenameBackup0 = RteUtils::SlashesToOsSlashes(filenameRegular + ".
const string filenameBackup1 = RteUtils::SlashesToOsSlashes(filenameRegular + ".0001");
const string pathInvalid = dirnameSubdir + "/Invalid";

// For Canonical Tests
const string filenameBackslashForCanonical = dirnameSubdirBackslash + "\\file.txt";
const string dirnameSubdirBackslashForCanonical = dirnameBase + "\\dir\\subdir";
const string dirnameMixedWithTrailingForCanonical = dirnameBase + "/dir\\subdir/";
const string dirnameBackslashWithTrailingForCanonical = dirnameBase + "\\dir\\subdir\\";

static set<string, VersionCmp::Greater> sortedFileSet = {
"foo.h",
"bar.h",
Expand Down Expand Up @@ -849,23 +855,23 @@ TEST_F(RteFsUtilsTest, MakePathCanonical) {
EXPECT_EQ(ret, nonExistingFileAbs);

// Test filename with backslashes separators
ret = RteFsUtils::MakePathCanonical(filenameBackslash);
ret = RteFsUtils::MakePathCanonical(filenameBackslashForCanonical);
EXPECT_EQ(ret, filenameCanonical);

// Test filename with mixed separators
ret = RteFsUtils::MakePathCanonical(filenameBackslash);
ret = RteFsUtils::MakePathCanonical(filenameBackslashForCanonical);
EXPECT_EQ(ret, filenameCanonical);

// Test dirname with regular separators and trailing
ret = RteFsUtils::MakePathCanonical(dirnameSubdirWithTrailing);
EXPECT_EQ(ret, dirnameCanonical);

// Test dirname with backslashes separators and trailing
ret = RteFsUtils::MakePathCanonical(dirnameBackslashWithTrailing);
ret = RteFsUtils::MakePathCanonical(dirnameBackslashWithTrailingForCanonical);
EXPECT_EQ(ret, dirnameCanonical);

// Test dirname with mixed separators and trailing
ret = RteFsUtils::MakePathCanonical(dirnameMixedWithTrailing);
ret = RteFsUtils::MakePathCanonical(dirnameMixedWithTrailingForCanonical);
EXPECT_EQ(ret, dirnameCanonical);

// Test path with dot inside
Expand Down
2 changes: 1 addition & 1 deletion libs/rtemodel/src/RteProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ RteLicenseInfo* RteLicenseInfoCollection::EnsureLicenseInfo(RteItem* item, RteIt
licFile = pack->GetChildText("license");
}
if (!licFile.empty()) {
info->AddAttribute("agreement", "${CMSIS_PACK_ROOT}/" + pack->GetPackagePath(true) + licFile);
info->AddAttribute("agreement", pack->GetAbsolutePackagePath() + licFile);
}
} else {
info = it->second;
Expand Down
6 changes: 6 additions & 0 deletions libs/rtemodel/test/src/RteModelTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,12 @@ TEST_F(RteModelPrjTest, LoadCprj) {
loadedCprjProject->CollectLicenseInfos(licences);
string licenseText = licences.ToString();

string packRoot = rteKernel.GetCmsisPackRoot();
size_t index;
while ((index = licenseText.find(packRoot)) != std::string::npos) {
licenseText.replace(index, packRoot.length(), "${CMSIS_PACK_ROOT}");
}

string licRefFile = prjsDir + RteTestM3 + "/license_info_ref.txt";
EXPECT_TRUE(RteFsUtils::CmpFileMem(licRefFile, licenseText));

Expand Down
2 changes: 1 addition & 1 deletion tools/projmgr/src/ProjMgrYamlEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ void ProjMgrYamlCbuild::SetLicenseInfoNode(YAML::Node node, const ContextItem* c
SetNodeValue(licNode[YAML_LICENSE], RteLicenseInfo::ConstructLicenseTitle(licInfo));
const string& license_agreement = licInfo->GetAttribute("agreement");
if (!license_agreement.empty()) {
SetNodeValue(licNode[YAML_LICENSE_AGREEMENT], license_agreement);
SetNodeValue(licNode[YAML_LICENSE_AGREEMENT], FormatPath(license_agreement, context->directories.cbuild));
}
YAML::Node packsNode = licNode[YAML_PACKS];
for (auto pack : licInfo->GetPackIDs()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ build-gen:
components:
- component: ARM::RteTestGenerator:Check Global [email protected]
- license: <unknown>
license-agreement: ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Doc/license.txt
license-agreement: ${DEVTOOLS(packs)}/ARM/RteTest_DFP/0.2.0/Doc/license.txt
packs:
- pack: ARM::[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ build-gen:
components:
- component: ARM::RteTestGenerator:Check Global [email protected]
- license: <unknown>
license-agreement: ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Doc/license.txt
license-agreement: ${DEVTOOLS(packs)}/ARM/RteTest_DFP/0.2.0/Doc/license.txt
packs:
- pack: ARM::[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ build-gen:
- component: ARM::Device:RteTest Generated Component:[email protected]
- component: ARM::Device:RteTest Generated Component:[email protected]
- license: <unknown>
license-agreement: ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Doc/license.txt
license-agreement: ${DEVTOOLS(packs)}/ARM/RteTest_DFP/0.2.0/Doc/license.txt
packs:
- pack: ARM::[email protected]
components:
Expand Down
1 change: 1 addition & 0 deletions tools/projmgr/test/src/ProjMgrUtilsUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ TEST_F(ProjMgrUtilsUnitTests, FormatPath) {
vector<pair<string, string>> testData = {
{ "OriginalPath" , testoutput_folder + "/OriginalPath" },
{ "${CMSIS_PACK_ROOT}/Pack" , testcmsispack_folder + "/Pack" },
{ "${CMSIS_PACK_ROOT}/Backslash" , testcmsispack_folder + "\\Backslash" },
{ "${CMSIS_COMPILER_ROOT}/Toolchain" , testcmsiscompiler_folder + "/Toolchain" },
{ "https://www.url.com" , "https://www.url.com" },
};
Expand Down

0 comments on commit 781d198

Please sign in to comment.