Skip to content

Commit 447b1e5

Browse files
authored
[devtools] Handle automatic rebase of config files
1 parent c779cb3 commit 447b1e5

14 files changed

Lines changed: 145 additions & 45 deletions

File tree

libs/rtefsutils/include/RteFsUtils.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
/******************************************************************************/
1010
/*
11-
* Copyright (c) 2020-2024 Arm Limited. All rights reserved.
11+
* Copyright (c) 2020-2026 Arm Limited. All rights reserved.
1212
*
1313
* SPDX-License-Identifier: Apache-2.0
1414
*/
@@ -84,6 +84,15 @@ class RteFsUtils
8484
* @return true if copying file is processed
8585
*/
8686
static bool CopyMergeFile(const std::string& src, const std::string& dst, int nInstance, bool backup);
87+
88+
/**
89+
* @brief compare files content with normalized line endings
90+
* @param fileName1 name of first file to be compared
91+
* @param fileName2 name of second file to be compared
92+
* @return true if files are equal
93+
*/
94+
static bool CmpFiles(const std::string& fileName1, const std::string& fileName2);
95+
8796
/**
8897
* @brief compare file content with given string 'buffer'
8998
* @param fileName name of file to be compared

libs/rtefsutils/src/RteFsUtils.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
/******************************************************************************/
88
/*
9-
* Copyright (c) 2020-2021 Arm Limited. All rights reserved.
9+
* Copyright (c) 2020-2026 Arm Limited. All rights reserved.
1010
*
1111
* SPDX-License-Identifier: Apache-2.0
1212
*/
@@ -104,6 +104,16 @@ bool RteFsUtils::ReadFile(const string& fileName, string& buffer) {
104104
return true;
105105
}
106106

107+
bool RteFsUtils::CmpFiles(const string& fileName1, const string& fileName2) {
108+
109+
// Open files and read content
110+
string fileBuffer1, fileBuffer2;
111+
if (!ReadFile(fileName1, fileBuffer1) || !ReadFile(fileName2, fileBuffer2)) {
112+
return false;
113+
}
114+
// Compare buffer contents with normalized line endings
115+
return RteUtils::EnsureLf(fileBuffer1) == RteUtils::EnsureLf(fileBuffer2);
116+
}
107117

108118
bool RteFsUtils::CmpFileMem(const string& fileName, const string& buffer) {
109119

libs/rtefsutils/test/src/RteFsUtilsTest.cpp

Lines changed: 20 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-2026 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -165,6 +165,25 @@ TEST_F(RteFsUtilsTest, BackupFile) {
165165
RteFsUtils::RemoveFile(filenameRegular);
166166
}
167167

168+
TEST_F(RteFsUtilsTest, CmpFiles) {
169+
// Test files with same content
170+
RteFsUtils::CreateTextFile(filenameRegular, bufferFoo);
171+
RteFsUtils::CreateTextFile(filenameRegularCopy, bufferFoo);
172+
EXPECT_TRUE(RteFsUtils::CmpFiles(filenameRegular, filenameRegularCopy));
173+
174+
// Test files with different content
175+
RteFsUtils::CreateTextFile(filenameRegularCopy, bufferBar);
176+
EXPECT_FALSE(RteFsUtils::CmpFiles(filenameRegular, filenameRegularCopy));
177+
178+
// Test missing file2
179+
RteFsUtils::RemoveFile(filenameRegularCopy);
180+
EXPECT_FALSE(RteFsUtils::CmpFiles(filenameRegular, filenameRegularCopy));
181+
182+
// Test missing file1
183+
RteFsUtils::RemoveFile(filenameRegular);
184+
EXPECT_FALSE(RteFsUtils::CmpFiles(filenameRegular, filenameRegularCopy));
185+
}
186+
168187
TEST_F(RteFsUtilsTest, CmpFileMem) {
169188
bool ret;
170189

libs/rtemodel/src/RteProject.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
/******************************************************************************/
88
/*
9-
* Copyright (c) 2020-2025 Arm Limited. All rights reserved.
9+
* Copyright (c) 2020-2026 Arm Limited. All rights reserved.
1010
*
1111
* SPDX-License-Identifier: Apache-2.0
1212
*/
@@ -696,8 +696,17 @@ void RteProject::UpdateConfigFileBackups(RteFileInstance* fi, RteItem* f)
696696
// copy current file if version differs
697697
string updateFile = RteUtils::AppendFileUpdateVersion(absPath, updateVersion);
698698
if (!baseFile.empty() && baseVersion != updateVersion) { // only copy update if base exists
699-
RteFsUtils::CopyMergeFile(src, updateFile, fi->GetInstanceIndex(), false);
700-
RteFsUtils::SetFileReadOnly(updateFile, true);
699+
if (RteFsUtils::CmpFiles(baseFile, src)) {
700+
// if base and update contents are equal, rebase it
701+
const string rebaseFile = RteUtils::AppendFileBaseVersion(absPath, updateVersion);
702+
RteFsUtils::MoveFileExAutoRetry(baseFile, rebaseFile);
703+
fi->SetAttribute("version", updateVersion.c_str());
704+
baseFile = rebaseFile;
705+
updateFile.clear();
706+
} else {
707+
RteFsUtils::CopyMergeFile(src, updateFile, fi->GetInstanceIndex(), false);
708+
RteFsUtils::SetFileReadOnly(updateFile, true);
709+
}
701710
} else {
702711
updateFile.clear(); // no need in that
703712
}

libs/rtemodel/test/src/RteModelTest.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2025 Arm Limited. All rights reserved.
2+
* Copyright (c) 2020-2026 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -714,10 +714,11 @@ TEST_F(RteModelPrjTest, LoadCprjConfigVer) {
714714

715715
const string deviceDir = rteDir + "Device/RteTest_ARMCM3/";
716716
EXPECT_TRUE(RteFsUtils::Exists(deviceDir + "ARMCM3_ac6.sct"));
717-
EXPECT_TRUE(RteFsUtils::Exists(deviceDir + "ARMCM3_ac6.sct.base@1.0.0"));
717+
// content of update file is equal to the base file, rebase the version to 1.2.0
718+
EXPECT_TRUE(RteFsUtils::Exists(deviceDir + "ARMCM3_ac6.sct.base@1.2.0"));
718719
// check if file version is taken from base file (project contains "5.5.5")
719720
RteFileInstance* fi = loadedCprjProject->GetFileInstance("CONFIG_FOLDER/Device/RteTest_ARMCM3/ARMCM3_ac6.sct");
720-
EXPECT_TRUE(fi && fi->GetVersionString() == "1.0.0");
721+
EXPECT_TRUE(fi && fi->GetVersionString() == "1.2.0");
721722

722723
EXPECT_TRUE(RteFsUtils::Exists(deviceDir + "startup_ARMCM3.c.base@2.0.3"));
723724
EXPECT_TRUE(RteFsUtils::Exists(deviceDir + "system_ARMCM3.c.base@1.0.1"));

tools/projmgr/include/ProjMgrUtils.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2025 Arm Limited. All rights reserved.
2+
* Copyright (c) 2020-2026 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -314,13 +314,6 @@ class ProjMgrUtils {
314314
*/
315315
static const std::string FileTypeFromExtension(const std::string& file);
316316

317-
/**
318-
* @brief normalize line endings for consistent string comparison
319-
* @param input string
320-
* @return output normalized string
321-
*/
322-
static const std::string NormalizeLineEndings(const std::string& in);
323-
324317
/**
325318
* @brief convert board string to west board string
326319
* @param board string

tools/projmgr/src/ProjMgrUtils.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2025 Arm Limited. All rights reserved.
2+
* Copyright (c) 2020-2026 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -486,19 +486,6 @@ const string ProjMgrUtils::FileTypeFromExtension(const string& file) {
486486
return RteUtils::EMPTY_STRING;
487487
}
488488

489-
const std::string ProjMgrUtils::NormalizeLineEndings(const std::string& in) {
490-
string out = in;
491-
size_t pos = 0;
492-
while ((pos = out.find("\r\n", pos)) != std::string::npos) {
493-
out.replace(pos++, 2, "\n");
494-
}
495-
pos = 0;
496-
while ((pos = out.find("\r", pos)) != std::string::npos) {
497-
out.replace(pos, 1, "\n");
498-
}
499-
return out;
500-
}
501-
502489
const std::string ProjMgrUtils::GetWestBoard(const std::string& board) {
503490
string westBoard = RteUtils::StripSuffix(RteUtils::StripPrefix(board, "::"));
504491
std::transform(westBoard.begin(), westBoard.end(), westBoard.begin(),

tools/projmgr/src/ProjMgrYamlEmitter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2024 Arm Limited. All rights reserved.
2+
* Copyright (c) 2020-2026 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -94,8 +94,8 @@ bool ProjMgrYamlEmitter::CompareFile(const string& filename, const YAML::Node& r
9494
}
9595
YAML::Emitter emitter;
9696
const auto& outBuffer = string((emitter << rootNode).c_str()) + '\n';
97-
return ProjMgrUtils::NormalizeLineEndings(inBuffer) ==
98-
ProjMgrUtils::NormalizeLineEndings(outBuffer);
97+
return RteUtils::EnsureLf(inBuffer) ==
98+
RteUtils::EnsureLf(outBuffer);
9999
}
100100

101101
bool ProjMgrYamlEmitter::CompareNodes(const YAML::Node& lhs, const YAML::Node& rhs) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Dummy file */
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/******************************************************************************
2+
* @file startup_ARMCM3.c
3+
* @brief CMSIS-Core(M) Device Startup File for a Cortex-M3 Device
4+
* @version V2.0.3
5+
* @date 31. March 2020
6+
******************************************************************************/
7+
/*
8+
* Copyright (c) 2009-2020 Arm Limited. All rights reserved.
9+
*
10+
* SPDX-License-Identifier: Apache-2.0
11+
*
12+
* Licensed under the Apache License, Version 2.0 (the License); you may
13+
* not use this file except in compliance with the License.
14+
* You may obtain a copy of the License at
15+
*
16+
* www.apache.org/licenses/LICENSE-2.0
17+
*
18+
* Unless required by applicable law or agreed to in writing, software
19+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
20+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
* See the License for the specific language governing permissions and
22+
* limitations under the License.
23+
*/
24+
25+
#if defined (ARMCM3)
26+
#include "ARMCM3.h"
27+
#else
28+
#error device not specified!
29+
#endif
30+
31+
32+
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
33+
#pragma clang diagnostic push
34+
#pragma clang diagnostic ignored "-Wmissing-noreturn"
35+
#endif
36+
37+
/*----------------------------------------------------------------------------
38+
Reset Handler called on controller reset
39+
*----------------------------------------------------------------------------*/
40+
void Reset_Handler(void)
41+
{
42+
}
43+
44+
/*----------------------------------------------------------------------------
45+
Hard Fault Handler
46+
*----------------------------------------------------------------------------*/
47+
void HardFault_Handler(void)
48+
{
49+
while(1);
50+
}
51+
52+
/*----------------------------------------------------------------------------
53+
Default Handler for Exceptions / Interrupts
54+
*----------------------------------------------------------------------------*/
55+
void Default_Handler(void)
56+
{
57+
while(1);
58+
}
59+
60+
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
61+
#pragma clang diagnostic pop
62+
#endif
63+

0 commit comments

Comments
 (0)