Skip to content

Commit

Permalink
PLM of config files
Browse files Browse the repository at this point in the history
  • Loading branch information
grasci-arm authored Oct 20, 2022
1 parent cfde215 commit be7796c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 29 deletions.
33 changes: 24 additions & 9 deletions libs/rtemodel/src/RteProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,27 @@ void RteProject::UpdateConfigFileBackups(RteFileInstance* fi, RteFile* f)
{
string src = f->GetOriginalAbsolutePath();
string absPath = RteFsUtils::AbsolutePath(fi->GetAbsolutePath()).generic_string();
const string& baseVersion = fi->GetVersionString();
string dir = RteUtils::ExtractFilePath(absPath, false);
string name = RteUtils::ExtractFileName(absPath);
string baseVersion = fi->GetVersionString();
if (baseVersion.empty() || baseVersion == "0.0.0") {
// try to find base version from the version files
string baseName = name + '.' + RteUtils::BASE_STRING;
list<string> backupFileNames;
RteFsUtils::GrepFileNames(backupFileNames, dir, baseName + "@*");
if (!backupFileNames.empty()) {
// sort by version descending
backupFileNames.sort([](const string& s0, const string& s1) {
string v0 = RteUtils::GetSuffix(s0, '@');
string v1 = RteUtils::GetSuffix(s1, '@');
return VersionCmp::Compare(v0, v1) > 0;
});
baseVersion = RteUtils::GetSuffix(*backupFileNames.begin(), '@'); // use the top version
fi->AddAttribute("version", baseVersion, false);
backupFileNames.clear();
}
}

const string& updateVersion = f->GetVersionString();
string baseFile = RteUtils::AppendFileBaseVersion(absPath, baseVersion);
if (!RteFsUtils::Exists(baseFile)) {
Expand All @@ -515,16 +535,11 @@ void RteProject::UpdateConfigFileBackups(RteFileInstance* fi, RteFile* f)
}

// remove redundant current and origin files
string dir = RteUtils::ExtractFilePath(absPath, false);
string name = RteUtils::ExtractFileName(absPath);
string baseName = name + '.' + RteUtils::BASE_STRING;
string updateName = name + '.' + RteUtils::UPDATE_STRING;
string dotName = '.' + name;

list<string> backupFileNames;
RteFsUtils::GrepFileNames(backupFileNames, dir, updateName + "@*");
if (!baseFile.empty()) {
RteFsUtils::GrepFileNames(backupFileNames, dir, baseName + "@*");
}
RteFsUtils::GrepFileNames(backupFileNames, dir, name + "*@*");
RteFsUtils::GrepFileNames(backupFileNames, dir, dotName + "*@*");
for (string fileName : backupFileNames) {
error_code ec;
if (!fs::equivalent(fileName, baseFile, ec) && !fs::equivalent(fileName, updateFile, ec)) {
Expand Down
16 changes: 8 additions & 8 deletions libs/rtemodel/test/src/RteModelTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,17 @@ TEST_F(RteModelPrjTest, LoadCprj) {
const fs::perms write_mask = fs::perms::owner_write | fs::perms::group_write | fs::perms::others_write;
// check config file PLM: existence and permissions
const string deviceDir = rteDir + "Device/RteTest_ARMCM3/";
EXPECT_TRUE(RteFsUtils::Exists(deviceDir + "ARMCM3_ac6.sct.base@1.0.0"));
EXPECT_EQ((fs::status(deviceDir + "ARMCM3_ac6.sct.base@1.0.0", ec).permissions() & write_mask), fs::perms::none);

EXPECT_TRUE(RteFsUtils::Exists(deviceDir + "startup_ARMCM3.c.base@2.0.3"));
EXPECT_EQ((fs::status(deviceDir + "startup_ARMCM3.c.base@2.0.3", ec).permissions() & write_mask), fs::perms::none);
EXPECT_FALSE(RteFsUtils::Exists(deviceDir + "ARMCM3_ac6.sct.base@1.0.0"));
EXPECT_TRUE(RteFsUtils::Exists(deviceDir + "ARMCM3_ac6.sct.update@1.2.0"));

EXPECT_FALSE(RteFsUtils::Exists(deviceDir + "system_ARMCM3.c.base@1.0.1"));
EXPECT_FALSE(RteFsUtils::Exists(deviceDir + "system_ARMCM3.c.base@1.0.2"));

EXPECT_TRUE(RteFsUtils::Exists(deviceDir + "system_ARMCM3.c.update@1.0.2"));
EXPECT_EQ((fs::status(deviceDir + "system_ARMCM3.c.update@1.0.2", ec).permissions() & write_mask), fs::perms::none);
EXPECT_TRUE(RteFsUtils::Exists(deviceDir + "startup_ARMCM3.c.base@2.0.3"));
EXPECT_EQ((fs::status(deviceDir + "startup_ARMCM3.c.base@2.0.3", ec).permissions() & write_mask), fs::perms::none);

EXPECT_TRUE(RteFsUtils::Exists(deviceDir + "system_ARMCM3.c.update@1.2.2"));
EXPECT_EQ((fs::status(deviceDir + "system_ARMCM3.c.update@1.2.2", ec).permissions() & write_mask), fs::perms::none);
}

TEST_F(RteModelPrjTest, LoadCprj_PackPath) {
Expand Down Expand Up @@ -307,7 +307,7 @@ TEST_F(RteModelPrjTest, LoadCprjConfigVer) {
EXPECT_TRUE(RteFsUtils::Exists(deviceDir + "startup_ARMCM3.c.base@2.0.3"));
EXPECT_TRUE(RteFsUtils::Exists(deviceDir + "system_ARMCM3.c.base@1.0.1"));
EXPECT_FALSE(RteFsUtils::Exists(deviceDir + "system_ARMCM3.c.base@1.0.2"));
EXPECT_TRUE(RteFsUtils::Exists(deviceDir + "system_ARMCM3.c.update@1.0.2"));
EXPECT_TRUE(RteFsUtils::Exists(deviceDir + "system_ARMCM3.c.update@1.2.2"));

const string depsDir = rteDir + "Dependency/RteTest_ARMCM3/";
EXPECT_TRUE(RteFsUtils::Exists(depsDir + "DeviceDependency.c.base@1.1.1"));
Expand Down
16 changes: 8 additions & 8 deletions test/packs/ARM/RteTest_DFP/0.2.0/ARM.RteTest_DFP.pdsc
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,10 @@
<file category="doc" name="https://arm-software.github.io/CMSIS_5/Core_A/html/startup_c_pg.html"/>
<!-- startup / system file -->
<file category="sourceC" name="Device/ARM/ARMCM3/Source/startup_ARMCM3.c" version="2.0.3" attr="config"/>
<file category="linkerScript" name="Device/ARM/ARMCM3/Source/ARM/ARMCM3_ac5.sct" version="1.0.0" attr="config" condition="ARMCC5"/>
<file category="linkerScript" name="Device/ARM/ARMCM3/Source/ARM/ARMCM3_ac6.sct" version="1.0.0" attr="config" condition="ARMCC6"/>
<file category="linkerScript" name="Device/ARM/ARMCM3/Source/GCC/gcc_arm.ld" version="2.0.0" attr="config" condition="GCC"/>
<file category="sourceC" name="Device/ARM/ARMCM3/Source/system_ARMCM3.c" version="1.0.2" attr="config"/>
<file category="linkerScript" name="Device/ARM/ARMCM3/Source/ARM/ARMCM3_ac5.sct" version="1.2.0" attr="config" condition="ARMCC5"/>
<file category="linkerScript" name="Device/ARM/ARMCM3/Source/ARM/ARMCM3_ac6.sct" version="1.2.0" attr="config" condition="ARMCC6"/>
<file category="linkerScript" name="Device/ARM/ARMCM3/Source/GCC/gcc_arm.ld" version="2.2.0" attr="config" condition="GCC"/>
<file category="sourceC" name="Device/ARM/ARMCM3/Source/system_ARMCM3.c" version="1.2.2" attr="config"/>
</files>
</component>

Expand All @@ -345,10 +345,10 @@
<file category="doc" name="https://arm-software.github.io/CMSIS_5/Core_A/html/startup_c_pg.html"/>
<!-- startup / system file -->
<file category="sourceC" name="Device/ARM/ARMCM4/Source/startup_ARMCM4.c" version="2.0.3" attr="config"/>
<file category="linkerScript" name="Device/ARM/ARMCM4/Source/ARM/ARMCM4_ac5.sct" version="1.0.0" attr="config" condition="ARMCC5"/>
<file category="linkerScript" name="Device/ARM/ARMCM4/Source/ARM/ARMCM4_ac6.sct" version="1.0.0" attr="config" condition="ARMCC6"/>
<file category="linkerScript" name="Device/ARM/ARMCM4/Source/GCC/gcc_arm.ld" version="2.0.0" attr="config" condition="GCC"/>
<file category="sourceC" name="Device/ARM/ARMCM4/Source/system_ARMCM4.c" version="1.0.1" attr="config"/>
<file category="linkerScript" name="Device/ARM/ARMCM4/Source/ARM/ARMCM4_ac5.sct" version="1.2.0" attr="config" condition="ARMCC5"/>
<file category="linkerScript" name="Device/ARM/ARMCM4/Source/ARM/ARMCM4_ac6.sct" version="1.2.0" attr="config" condition="ARMCC6"/>
<file category="linkerScript" name="Device/ARM/ARMCM4/Source/GCC/gcc_arm.ld" version="2.2.0" attr="config" condition="GCC"/>
<file category="sourceC" name="Device/ARM/ARMCM4/Source/system_ARMCM4.c" version="1.2.1" attr="config"/>
</files>
</component>

Expand Down
4 changes: 2 additions & 2 deletions tools/projmgr/test/data/TestSolution/ref/test2.Debug+CM3.cprj
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

<components>
<component Cclass="Device" Cgroup="Startup" Cvariant="RteTest Startup" Cvendor="ARM" Cversion="2.0.3">
<file attr="config" category="linkerScript" name="Device/ARM/ARMCM3/Source/ARM/ARMCM3_ac6.sct" version="1.0.0"/>
<file attr="config" category="linkerScript" name="Device/ARM/ARMCM3/Source/ARM/ARMCM3_ac6.sct" version="1.2.0"/>
<file attr="config" category="sourceC" name="Device/ARM/ARMCM3/Source/startup_ARMCM3.c" version="2.0.3"/>
<file attr="config" category="sourceC" name="Device/ARM/ARMCM3/Source/system_ARMCM3.c" version="1.0.2"/>
<file attr="config" category="sourceC" name="Device/ARM/ARMCM3/Source/system_ARMCM3.c" version="1.2.2"/>
</component>
<component Cclass="RteTest" Cgroup="CORE" Cvendor="ARM" Cversion="0.1.1"/>
</components>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

<components>
<component Cclass="Device" Cgroup="Startup" Cvariant="RteTest Startup" Cvendor="ARM" Cversion="2.0.3">
<file attr="config" category="linkerScript" name="Device/ARM/ARMCM3/Source/ARM/ARMCM3_ac6.sct" version="1.0.0"/>
<file attr="config" category="linkerScript" name="Device/ARM/ARMCM3/Source/ARM/ARMCM3_ac6.sct" version="1.2.0"/>
<file attr="config" category="sourceC" name="Device/ARM/ARMCM3/Source/startup_ARMCM3.c" version="2.0.3"/>
<file attr="config" category="sourceC" name="Device/ARM/ARMCM3/Source/system_ARMCM3.c" version="1.0.2"/>
<file attr="config" category="sourceC" name="Device/ARM/ARMCM3/Source/system_ARMCM3.c" version="1.2.2"/>
</component>
<component Cclass="RteTest" Cgroup="CORE" Cvendor="ARM" Cversion="0.1.1"/>
</components>
Expand Down

0 comments on commit be7796c

Please sign in to comment.