Skip to content

Commit 2054682

Browse files
authored
[projmgr] Adjust relative paths in misc nodes
1 parent a60f5d6 commit 2054682

10 files changed

Lines changed: 199 additions & 10 deletions

File tree

tools/projmgr/include/ProjMgrUtils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ class ProjMgrUtils {
284284
*/
285285
static const std::string FormatPath(const std::string& original, const std::string& directory, bool useAbsolutePaths = false);
286286

287+
/**
288+
* @brief adjust relative path fragments in a list of values
289+
* @param vec list of strings that may contain relative paths
290+
* @param ref reference path for formatting
291+
* @param outDir output directory for path formatting
292+
*/
293+
static void AdjustRelativePaths(std::vector<std::string>& vec, const std::string& ref, const std::string& outDir);
294+
287295
/**
288296
* @brief check if list contains incompatible version of pack requirement
289297
* @param list of packs

tools/projmgr/src/ProjMgrUtils.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,3 +493,16 @@ const std::string ProjMgrUtils::GetWestBoard(const std::string& board) {
493493
std::replace(westBoard.begin(), westBoard.end(), '-', '_');
494494
return westBoard;
495495
}
496+
497+
void ProjMgrUtils::AdjustRelativePaths(vector<string>& vec, const string& ref, const string& outDir) {
498+
static const regex pattern(R"((\.{1,2}/.*))");
499+
for (string& value : vec) {
500+
if (!value.empty()) {
501+
smatch match;
502+
if (regex_search(value, match, pattern)) {
503+
const auto& replacement = RteFsUtils::RelativePath(ref + "/" + match.str(), outDir, true);
504+
value.replace(match.position(), match.length(), replacement);
505+
}
506+
}
507+
}
508+
}

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5132,16 +5132,11 @@ bool ProjMgrWorker::ProcessSequencesRelatives(ContextItem& context, BuildType& b
51325132
return false;
51335133
}
51345134
for (auto& misc : build.misc) {
5135-
if (!ProcessSequencesRelatives(context, misc.as, "", "", true) ||
5136-
!ProcessSequencesRelatives(context, misc.c, "", "", true) ||
5137-
!ProcessSequencesRelatives(context, misc.cpp, "", "", true) ||
5138-
!ProcessSequencesRelatives(context, misc.c_cpp, "", "", true) ||
5139-
!ProcessSequencesRelatives(context, misc.lib, "", "", true) ||
5140-
!ProcessSequencesRelatives(context, misc.library, "", "", true) ||
5141-
!ProcessSequencesRelatives(context, misc.link, "", "", true) ||
5142-
!ProcessSequencesRelatives(context, misc.link_c, "", "", true) ||
5143-
!ProcessSequencesRelatives(context, misc.link_cpp, "", "", true)) {
5144-
return false;
5135+
for (auto* vec : { &misc.as, &misc.c, &misc.cpp, &misc.c_cpp, &misc.lib, &misc.library, &misc.link, &misc.link_c, &misc.link_cpp }) {
5136+
ProjMgrUtils::AdjustRelativePaths(*vec, ref, context.directories.cprj);
5137+
if (!ProcessSequencesRelatives(context, *vec, "", "", true)) {
5138+
return false;
5139+
}
51455140
}
51465141
}
51475142
return true;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/clayer.schema.json
2+
3+
layer:
4+
misc:
5+
- C-CPP:
6+
- --misc-layer=./relative/from-layer
7+
8+
groups:
9+
- group: Sources
10+
files:
11+
- file: ../main.c
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int main(void) {
2+
return 0;
3+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json
2+
3+
solution:
4+
target-types:
5+
- type: TEST_TARGET
6+
device: RteTest_ARMCM0
7+
misc:
8+
- C-CPP:
9+
- --misc-sol=./relative/from-solution
10+
11+
build-types:
12+
- type: Debug
13+
14+
projects:
15+
- project: ./project/misc-relative.cproject.yml
16+
17+
packs:
18+
- pack: ARM::RteTest
19+
- pack: ARM::RteTest_DFP
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/cproject.schema.json
2+
3+
project:
4+
compiler: AC6
5+
components:
6+
- component: CORE
7+
8+
misc:
9+
- C-CPP:
10+
- --misc-proj=./relative/from-project
11+
12+
layers:
13+
- layer: ../layers/misc-relative.clayer.yml
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
build:
2+
generated-by: csolution version 0.0.0
3+
solution: ../../../../../../data/TestMiscRelativePaths/misc-relative.csolution.yml
4+
project: ../../../../../../data/TestMiscRelativePaths/project/misc-relative.cproject.yml
5+
context: misc-relative.Debug+TEST_TARGET
6+
compiler: AC6
7+
device: ARM::RteTest_ARMCM0
8+
device-pack: ARM::RteTest_DFP@0.2.0
9+
device-books:
10+
- name: http://infocenter.arm.com/help/topic/com.arm.doc.dui0497a/index.html
11+
title: Cortex-M0 Device Generic Users Guide
12+
dbgconf:
13+
- file: ../../../../../../data/TestMiscRelativePaths/.cmsis/misc-relative+TEST_TARGET.dbgconf
14+
version: 0.0.2
15+
processor:
16+
fpu: off
17+
core: Cortex-M0
18+
packs:
19+
- pack: ARM::RteTest_DFP@0.2.0
20+
path: ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0
21+
misc:
22+
C:
23+
- --misc-proj=../../../../../../data/TestMiscRelativePaths/project/relative/from-project
24+
- --misc-sol=../../../../../../data/TestMiscRelativePaths/relative/from-solution
25+
- --misc-layer=../../../../../../data/TestMiscRelativePaths/layers/relative/from-layer
26+
CPP:
27+
- --misc-proj=../../../../../../data/TestMiscRelativePaths/project/relative/from-project
28+
- --misc-sol=../../../../../../data/TestMiscRelativePaths/relative/from-solution
29+
- --misc-layer=../../../../../../data/TestMiscRelativePaths/layers/relative/from-layer
30+
define:
31+
- ARMCM0
32+
- _RTE_
33+
define-asm:
34+
- ARMCM0
35+
- _RTE_
36+
add-path:
37+
- ../../../../../../data/TestMiscRelativePaths/project/RTE/_Debug_TEST_TARGET
38+
- ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Device/ARM/ARMCM0/Include
39+
add-path-asm:
40+
- ../../../../../../data/TestMiscRelativePaths/project/RTE/_Debug_TEST_TARGET
41+
- ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Device/ARM/ARMCM0/Include
42+
output-dirs:
43+
intdir: ../../../../tmp
44+
outdir: .
45+
rtedir: ../../../../../../data/TestMiscRelativePaths/project/RTE
46+
output:
47+
- type: elf
48+
file: misc-relative.axf
49+
- type: comp-db
50+
file: compile_commands.json
51+
- type: comp-db
52+
file: compile_macros.h
53+
components:
54+
- component: ARM::RteTest:CORE@0.1.1
55+
condition: Cortex-M Device
56+
from-pack: ARM::RteTest_DFP@0.2.0
57+
selected-by: CORE
58+
implements: RteTest:CORE@1.1.2
59+
files:
60+
- file: ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Doc/html/index.html
61+
category: doc
62+
version: 0.1.1
63+
apis:
64+
- api: RteTest:CORE@1.1.2
65+
from-pack: ARM::RteTest_DFP@0.2.0
66+
implemented-by: ARM::RteTest:CORE@0.1.1
67+
files:
68+
- file: https://arm-software.github.io/CMSIS_5/Pack/html/pdsc_apis_pg.html
69+
category: doc
70+
version: 1.1.2
71+
linker:
72+
script: ../../../../../../data/TestMiscRelativePaths/project/RTE/Device/RteTest_ARMCM0/ac6_linker_script.sct.src
73+
regions: ../../../../../../data/TestMiscRelativePaths/project/RTE/Device/RteTest_ARMCM0/regions_RteTest_ARMCM0.h
74+
groups:
75+
- group: Sources
76+
files:
77+
- file: ../../../../../../data/TestMiscRelativePaths/main.c
78+
category: sourceC
79+
constructed-files:
80+
- file: ../../../../../../data/TestMiscRelativePaths/project/RTE/_Debug_TEST_TARGET/RTE_Components.h
81+
category: header
82+
licenses:
83+
- license: <unknown>
84+
license-agreement: ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Doc/license.txt
85+
packs:
86+
- pack: ARM::RteTest_DFP@0.2.0
87+
components:
88+
- component: ARM::RteTest:CORE@0.1.1
89+
- component: RteTest:CORE(API)

tools/projmgr/test/src/ProjMgrUnitTests.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,22 @@ TEST_F(ProjMgrUnitTests, RunProjMgrLayers) {
10361036
EXPECT_TRUE(RteFsUtils::Exists(testinput_folder + "/TestLayers/Layer3/RTE/RteTest/MyDir"));
10371037
}
10381038

1039+
TEST_F(ProjMgrUnitTests, MiscRelativePathsAtAllLevels) {
1040+
char* argv[5];
1041+
1042+
const string csolution = testinput_folder + "/TestMiscRelativePaths/misc-relative.csolution.yml";
1043+
const string output = testoutput_folder + "/misc-relative";
1044+
argv[1] = (char*)"convert";
1045+
argv[2] = (char*)csolution.c_str();
1046+
argv[3] = (char*)"-o";
1047+
argv[4] = (char*)output.c_str();
1048+
EXPECT_EQ(0, RunProjMgr(5, argv, m_envp));
1049+
1050+
const string cbuildFile = output + "/out/misc-relative/TEST_TARGET/Debug/misc-relative.Debug+TEST_TARGET.cbuild.yml";
1051+
ProjMgrTestEnv::CompareFile(cbuildFile,
1052+
testinput_folder + "/TestMiscRelativePaths/ref/misc-relative.Debug+TEST_TARGET.cbuild.yml");
1053+
}
1054+
10391055
TEST_F(ProjMgrUnitTests, RunProjMgrSolution_CbuildFailedToCreate) {
10401056
char* argv[7];
10411057
StdStreamRedirect streamRedirect;

tools/projmgr/test/src/ProjMgrUtilsUnitTests.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,28 @@ TEST_F(ProjMgrUtilsUnitTests, ReplaceDelimiters) {
459459
EXPECT_EQ("path_with_spaces", ProjMgrUtils::ReplaceDelimiters("path/with spaces"));
460460
}
461461

462+
TEST_F(ProjMgrUtilsUnitTests, AdjustRelativePaths) {
463+
const string baseDir = testoutput_folder + "/AdjustRelativePaths";
464+
const string refDir = baseDir + "/ref";
465+
const string outDir = baseDir + "/out/sub";
466+
467+
RteFsUtils::CreateDirectories(refDir + "/assets");
468+
RteFsUtils::CreateDirectories(baseDir + "/shared");
469+
RteFsUtils::CreateDirectories(outDir);
470+
471+
vector<string> paths = {
472+
"prefix ./assets/file.txt suffix",
473+
"copy ../shared/config.yml",
474+
"absolute/path/unchanged",
475+
};
476+
477+
ProjMgrUtils::AdjustRelativePaths(paths, refDir, outDir);
478+
479+
EXPECT_EQ("prefix ../../ref/assets/file.txt suffix", paths[0]);
480+
EXPECT_EQ("copy ../../shared/config.yml", paths[1]);
481+
EXPECT_EQ("absolute/path/unchanged", paths[2]);
482+
}
483+
462484
TEST_F(ProjMgrUtilsUnitTests, FindReferencedContext) {
463485
const vector<string> selectedContexts = {
464486
"Project1.Debug+Target",

0 commit comments

Comments
 (0)