Skip to content

Commit 25695db

Browse files
[projmgr] add-path: filter out duplicates and tolerate absolute paths (#1142) (#1970)
Address #1938 Update test cases Co-authored-by: Daniel Brondani <[email protected]>
1 parent b5277bf commit 25695db

13 files changed

+325
-109
lines changed

tools/projmgr/include/ProjMgrCbuildBase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class ProjMgrCbuildBase {
2525
ProjMgrCbuildBase(bool useAbsolutePaths = false) : m_useAbsolutePaths(useAbsolutePaths) {};
2626
void SetNodeValue(YAML::Node node, const std::string& value);
2727
void SetNodeValue(YAML::Node node, const std::vector<std::string>& vec);
28+
void SetNodeValueUniquely(YAML::Node node, const std::string& value);
2829
const std::string FormatPath(const std::string& original, const std::string& directory);
2930

3031
bool m_useAbsolutePaths;

tools/projmgr/src/ProjMgrCbuild.cpp

Lines changed: 7 additions & 8 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-2025 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -91,15 +91,14 @@ void ProjMgrCbuild::SetContextNode(YAML::Node contextNode, const ContextItem* co
9191
}
9292
SetDefineNode(contextNode[YAML_DEFINE], defines);
9393
SetDefineNode(contextNode[YAML_DEFINE_ASM], defines);
94-
vector<string> includes;
9594
if (context->rteActiveTarget != nullptr) {
9695
for (auto include : context->rteActiveTarget->GetIncludePaths(RteFile::Language::LANGUAGE_NONE)) {
9796
RteFsUtils::NormalizePath(include, context->cproject->directory);
98-
CollectionUtils::PushBackUniquely(includes, FormatPath(include, context->directories.cbuild));
97+
include = FormatPath(include, context->directories.cbuild);
98+
SetNodeValueUniquely(contextNode[YAML_ADDPATH], include);
99+
SetNodeValueUniquely(contextNode[YAML_ADDPATH_ASM], include);
99100
}
100101
}
101-
SetNodeValue(contextNode[YAML_ADDPATH], includes);
102-
SetNodeValue(contextNode[YAML_ADDPATH_ASM], includes);
103102
SetOutputDirsNode(contextNode[YAML_OUTPUTDIRS], context);
104103
SetOutputNode(contextNode[YAML_OUTPUT], context);
105104
SetComponentsNode(contextNode[YAML_COMPONENTS], context);
@@ -447,15 +446,15 @@ void ProjMgrCbuild::SetControlsNode(YAML::Node node, const ContextItem* context,
447446
SetNodeValue(node[YAML_UNDEFINE], controls.undefines);
448447
for (auto addpath : controls.addpaths) {
449448
RteFsUtils::NormalizePath(addpath, context->directories.cprj);
450-
node[YAML_ADDPATH].push_back(FormatPath(addpath, context->directories.cbuild));
449+
SetNodeValueUniquely(node[YAML_ADDPATH], FormatPath(addpath, context->directories.cbuild));
451450
}
452451
for (auto addpath : controls.addpathsAsm) {
453452
RteFsUtils::NormalizePath(addpath, context->directories.cprj);
454-
node[YAML_ADDPATH_ASM].push_back(FormatPath(addpath, context->directories.cbuild));
453+
SetNodeValueUniquely(node[YAML_ADDPATH_ASM], FormatPath(addpath, context->directories.cbuild));
455454
}
456455
for (auto delpath : controls.delpaths) {
457456
RteFsUtils::NormalizePath(delpath, context->directories.cprj);
458-
node[YAML_DELPATH].push_back(FormatPath(delpath, context->directories.cbuild));
457+
SetNodeValueUniquely(node[YAML_DELPATH], FormatPath(delpath, context->directories.cbuild));
459458
}
460459
}
461460

tools/projmgr/src/ProjMgrCbuildBase.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ void ProjMgrCbuildBase::SetNodeValue(YAML::Node node, const vector<string>& vec)
2525
}
2626
}
2727

28+
void ProjMgrCbuildBase::SetNodeValueUniquely(YAML::Node node, const string& value) {
29+
if (!value.empty()) {
30+
for (const auto& item : node) {
31+
if (value == item.as<string>()) {
32+
return;
33+
}
34+
}
35+
node.push_back(value);
36+
}
37+
}
38+
2839
const string ProjMgrCbuildBase::FormatPath(const string& original, const string& directory) {
2940
return ProjMgrUtils::FormatPath(original, directory, m_useAbsolutePaths);
3041
}

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 5 additions & 2 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-2025 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -3362,7 +3362,10 @@ bool ProjMgrWorker::ProcessSequenceRelative(ContextItem& context, string& item,
33623362
// adjust relative path according to the given reference
33633363
if (!fs::equivalent(outDir, ref, ec)) {
33643364
const string absPath = RteFsUtils::MakePathCanonical(fs::path(item).is_relative() ? ref + "/" + item : item);
3365-
item = RteFsUtils::RelativePath(absPath, outDir, withHeadingDot);
3365+
const string relPath = RteFsUtils::RelativePath(absPath, outDir, withHeadingDot);
3366+
if (!relPath.empty()) {
3367+
item = relPath;
3368+
}
33663369
}
33673370
}
33683371
return true;

tools/projmgr/src/ProjMgrYamlParser.cpp

Lines changed: 1 addition & 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-2025 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -306,15 +306,13 @@ bool ProjMgrYamlParser::ParseCbuildSet(const string& input, CbuildSetItem& cbuil
306306
}
307307

308308
// EnsurePortability checks the presence of backslash, case inconsistency and absolute path
309-
// It clears the string 'value' when it is an absolute path
310309
void ProjMgrYamlParser::EnsurePortability(const string& file, const YAML::Mark& mark, const string& key, string& value) {
311310
if (value.find('\\') != string::npos) {
312311
ProjMgrLogger::Get().Warn("'" + value + "' contains non-portable backslash, use forward slash instead", "", file, mark.line + 1, mark.column + 1);
313312
}
314313
if (!value.empty()) {
315314
if (fs::path(value).is_absolute()) {
316315
ProjMgrLogger::Get().Warn("absolute path '" + value + "' is not portable, use relative path instead", "", file, mark.line + 1, mark.column + 1);
317-
value.clear();
318316
} else {
319317
const string parentDir = RteFsUtils::ParentPath(file);
320318
const string original = RteFsUtils::LexicallyNormal(fs::path(parentDir).append(value).generic_string());
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
build:
2+
generated-by: csolution version 2.8.0
3+
solution: ../data/TestProjectSetup/setup-test.csolution.yml
4+
project: ../data/TestProjectSetup/setup-test.cproject.yml
5+
context: setup-test.AbsolutePath+TEST_TARGET
6+
compiler: GCC
7+
device: ARM::RteTest_ARMCM0
8+
device-pack: ARM::[email protected]
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+
processor:
13+
fpu: off
14+
trustzone: off
15+
core: Cortex-M0
16+
packs:
17+
- pack: ARM::[email protected]
18+
path: ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0
19+
optimize: size
20+
debug: on
21+
warnings: on
22+
language-C: c11
23+
language-CPP: c++11
24+
misc:
25+
C:
26+
- SETUP_GCC_MISC
27+
- SETUP_COMMON_MISC
28+
define:
29+
- SETUP_GCC
30+
- SETUP_COMMON
31+
- ARMCM0
32+
- _RTE_
33+
define-asm:
34+
- ARMCM0
35+
- _RTE_
36+
add-path:
37+
- ../data/TestProjectSetup/setup/GCC
38+
- ../data/TestProjectSetup/setup/common
39+
- ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Device/ARM/ARMCM0/Include
40+
- C:/Absolute/Path
41+
- ../data/TestProjectSetup/RTE/_AbsolutePath_TEST_TARGET
42+
add-path-asm:
43+
- ../data/TestProjectSetup/RTE/_AbsolutePath_TEST_TARGET
44+
- ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Device/ARM/ARMCM0/Include
45+
output-dirs:
46+
intdir: tmp
47+
outdir: out/setup-test/TEST_TARGET/AbsolutePath
48+
rtedir: ../data/TestProjectSetup/RTE
49+
output:
50+
- type: elf
51+
file: setup-test.elf
52+
components:
53+
- component: ARM::RteTest:[email protected]
54+
condition: Cortex-M Device
55+
from-pack: ARM::[email protected]
56+
selected-by: CORE
57+
implements: RteTest:[email protected]
58+
files:
59+
- file: ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Doc/html/index.html
60+
category: doc
61+
version: 0.1.1
62+
apis:
63+
- api: RteTest:[email protected]
64+
from-pack: ARM::[email protected]
65+
implemented-by: ARM::RteTest:[email protected]
66+
files:
67+
- file: https://arm-software.github.io/CMSIS_5/Pack/html/pdsc_apis_pg.html
68+
category: doc
69+
version: 1.1.2
70+
linker:
71+
script: ../data/TestProjectSetup/RTE/Device/RteTest_ARMCM0/gcc_linker_script.ld.src
72+
regions: ../data/TestProjectSetup/RTE/Device/RteTest_ARMCM0/regions_RteTest_ARMCM0.h
73+
groups:
74+
- group: Generic Group
75+
files:
76+
- file: ../data/TestProjectSetup/gcc.c
77+
category: sourceC
78+
- file: ../data/TestProjectSetup/generic.c
79+
category: sourceC
80+
misc:
81+
C:
82+
- -DMISC-FILE-GCC
83+
constructed-files:
84+
- file: ../data/TestProjectSetup/RTE/_AbsolutePath_TEST_TARGET/RTE_Components.h
85+
category: header
86+
licenses:
87+
- license: <unknown>
88+
license-agreement: ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Doc/license.txt
89+
packs:
90+
- pack: ARM::[email protected]
91+
components:
92+
- component: ARM::RteTest:[email protected]
93+
- component: RteTest:CORE(API)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
build:
2+
generated-by: csolution version 2.8.0
3+
solution: ../data/TestProjectSetup/setup-test.csolution.yml
4+
project: ../data/TestProjectSetup/setup-test.cproject.yml
5+
context: setup-test.Build_AC6+TEST_TARGET
6+
compiler: AC6
7+
device: ARM::RteTest_ARMCM0
8+
device-pack: ARM::[email protected]
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+
processor:
13+
fpu: off
14+
core: Cortex-M0
15+
packs:
16+
- pack: ARM::[email protected]
17+
path: ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0
18+
misc:
19+
C:
20+
- SETUP_AC6_MISC
21+
- SETUP_COMMON_MISC
22+
define:
23+
- SETUP_AC6
24+
- SETUP_COMMON
25+
- ARMCM0
26+
- _RTE_
27+
define-asm:
28+
- ARMCM0
29+
- _RTE_
30+
add-path:
31+
- ../data/TestProjectSetup/setup/AC6
32+
- ../data/TestProjectSetup/setup/common
33+
- ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Device/ARM/ARMCM0/Include
34+
- ../data/TestProjectSetup/RTE/_Build_AC6_TEST_TARGET
35+
add-path-asm:
36+
- ../data/TestProjectSetup/RTE/_Build_AC6_TEST_TARGET
37+
- ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Device/ARM/ARMCM0/Include
38+
output-dirs:
39+
intdir: tmp
40+
outdir: out/setup-test/TEST_TARGET/Build_AC6
41+
rtedir: ../data/TestProjectSetup/RTE
42+
output:
43+
- type: elf
44+
file: setup-test.axf
45+
components:
46+
- component: ARM::RteTest:[email protected]
47+
condition: Cortex-M Device
48+
from-pack: ARM::[email protected]
49+
selected-by: CORE
50+
implements: RteTest:[email protected]
51+
files:
52+
- file: ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Doc/html/index.html
53+
category: doc
54+
version: 0.1.1
55+
apis:
56+
- api: RteTest:[email protected]
57+
from-pack: ARM::[email protected]
58+
implemented-by: ARM::RteTest:[email protected]
59+
files:
60+
- file: https://arm-software.github.io/CMSIS_5/Pack/html/pdsc_apis_pg.html
61+
category: doc
62+
version: 1.1.2
63+
linker:
64+
script: ../data/TestProjectSetup/RTE/Device/RteTest_ARMCM0/ac6_linker_script.sct.src
65+
regions: ../data/TestProjectSetup/RTE/Device/RteTest_ARMCM0/regions_RteTest_ARMCM0.h
66+
groups:
67+
- group: Group for AC6
68+
files:
69+
- file: ../data/TestProjectSetup/ac6.c
70+
category: sourceC
71+
- group: Generic Group
72+
files:
73+
- file: ../data/TestProjectSetup/generic.c
74+
category: sourceC
75+
misc:
76+
C:
77+
- -DMISC-FILE-AC6
78+
constructed-files:
79+
- file: ../data/TestProjectSetup/RTE/_Build_AC6_TEST_TARGET/RTE_Components.h
80+
category: header
81+
licenses:
82+
- license: <unknown>
83+
license-agreement: ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Doc/license.txt
84+
packs:
85+
- pack: ARM::[email protected]
86+
components:
87+
- component: ARM::RteTest:[email protected]
88+
- component: RteTest:CORE(API)

tools/projmgr/test/data/TestProjectSetup/ref/setup-test.Build_AC6+TEST_TARGET.cprj

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)