Skip to content

Commit 7fdad74

Browse files
authored
[projmgr] Check specified linker script existence
1 parent a19f95f commit 7fdad74

File tree

7 files changed

+48
-9
lines changed

7 files changed

+48
-9
lines changed

tools/projmgr/include/ProjMgrWorker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ class ProjMgrWorker {
833833

834834
bool LoadPacks(ContextItem& context);
835835
bool CheckMissingPackRequirements(const std::string& contextName);
836+
void CheckMissingLinkerScript(ContextItem& context);
836837
bool CollectRequiredPdscFiles(ContextItem& context, const std::string& packRoot);
837838
bool CheckBoardDeviceInLayer(const ContextItem& context, const ClayerItem& clayer);
838839
bool CheckCompiler(const std::vector<std::string>& forCompiler, const std::string& selectedCompiler);

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,15 +2093,19 @@ bool ProjMgrWorker::ProcessConfigFiles(ContextItem& context) {
20932093
ProjMgrLogger::Get().Warn("conflict: automatic linker script generation overrules specified script '" + context.linker.script + "'", context.name);
20942094
context.linker.script.clear();
20952095
}
2096-
}
2097-
else if (context.linker.script.empty() && context.linker.regions.empty() && context.linker.defines.empty()) {
2098-
const auto& groups = context.rteActiveTarget->GetProjectGroups();
2099-
for (auto group : groups) {
2100-
for (auto file : group.second) {
2101-
if (file.second.m_cat == RteFile::Category::LINKER_SCRIPT) {
2102-
error_code ec;
2103-
context.linker.script = fs::relative(context.cproject->directory + "/" + file.first, context.directories.cprj, ec).generic_string();
2104-
break;
2096+
} else {
2097+
// check user specified linker script
2098+
CheckMissingLinkerScript(context);
2099+
// search for linker script among selected component files
2100+
if (context.linker.script.empty() && context.linker.regions.empty() && context.linker.defines.empty()) {
2101+
const auto& groups = context.rteActiveTarget->GetProjectGroups();
2102+
for (auto group : groups) {
2103+
for (auto file : group.second) {
2104+
if (file.second.m_cat == RteFile::Category::LINKER_SCRIPT) {
2105+
error_code ec;
2106+
context.linker.script = fs::relative(context.cproject->directory + "/" + file.first, context.directories.cprj, ec).generic_string();
2107+
break;
2108+
}
21052109
}
21062110
}
21072111
}
@@ -5243,6 +5247,19 @@ bool ProjMgrWorker::CheckMissingFiles() {
52435247
return !error;
52445248
}
52455249

5250+
void ProjMgrWorker::CheckMissingLinkerScript(ContextItem& context) {
5251+
// check linker script existence
5252+
if (!context.linker.script.empty()) {
5253+
string script = context.linker.script;
5254+
if (RteFsUtils::IsRelative(context.linker.script)) {
5255+
RteFsUtils::NormalizePath(script, context.directories.cprj);
5256+
}
5257+
if (!RteFsUtils::Exists(script)) {
5258+
m_missingFiles.insert({ script, FileNode() });
5259+
}
5260+
}
5261+
}
5262+
52465263
void ProjMgrWorker::CollectUnusedPacks() {
52475264
for (const auto& contextName : m_selectedContexts) {
52485265
auto& context = m_contexts[contextName];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Dummy */

tools/projmgr/test/data/TestSolution/LinkerOptions/linker.cproject.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ project:
1212
- LD_PP_GCC_CPROJECT_DEF0
1313
- LD_PP_GCC_CPROJECT_DEF1
1414
for-compiler: GCC
15+
- script: ./unknown.sct
16+
for-context: .Missing
1517

1618
setups:
1719
- linker:

tools/projmgr/test/data/TestSolution/LinkerOptions/linker.csolution.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ solution:
1919
compiler: AC6
2020
- type: AutoGenWarning
2121
compiler: AC6
22+
- type: Missing
23+
compiler: AC6
2224

2325
target-types:
2426
- type: RteTest_ARMCM3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Dummy */

tools/projmgr/test/src/ProjMgrUnitTests.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4483,6 +4483,21 @@ TEST_F(ProjMgrUnitTests, RunProjMgr_LinkerOptions) {
44834483
testinput_folder + "/TestSolution/LinkerOptions/ref/linker.Debug_GCC+RteTest_ARMCM3.cbuild.yml");
44844484
}
44854485

4486+
TEST_F(ProjMgrUnitTests, RunProjMgr_MissingLinkerScript) {
4487+
char* argv[7];
4488+
const string& csolution = testinput_folder + "/TestSolution/LinkerOptions/linker.csolution.yml";
4489+
argv[1] = (char*)"convert";
4490+
argv[2] = (char*)csolution.c_str();
4491+
argv[3] = (char*)"-o";
4492+
argv[4] = (char*)testoutput_folder.c_str();
4493+
argv[5] = (char*)"-c";
4494+
argv[6] = (char*)"linker.Missing+RteTest_ARMCM3";
4495+
EXPECT_EQ(1, RunProjMgr(7, argv, m_envp));
4496+
const string& expected = "file '.*/TestSolution/LinkerOptions/unknown.sct' was not found";
4497+
const YAML::Node& cbuild = YAML::LoadFile(testoutput_folder + "/linker.cbuild-idx.yml");
4498+
EXPECT_TRUE(regex_search(cbuild["build-idx"]["cbuilds"][0]["messages"]["errors"][0].as<string>(), regex(expected)));
4499+
}
4500+
44864501
TEST_F(ProjMgrUnitTests, RunProjMgr_LinkerOptions_Auto) {
44874502
char* argv[8];
44884503
const string& csolution = testinput_folder + "/TestSolution/LinkerOptions/linker.csolution.yml";

0 commit comments

Comments
 (0)