Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tools/projmgr/include/ProjMgrUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ class ProjMgrUtils {
*/
static const std::string FormatPath(const std::string& original, const std::string& directory, bool useAbsolutePaths = false);

/**
* @brief adjust relative path fragments in a list of values
* @param vec list of strings that may contain relative paths
* @param ref reference path for formatting
* @param outDir output directory for path formatting
*/
static void AdjustRelativePaths(std::vector<std::string>& vec, const std::string& ref, const std::string& outDir);

/**
* @brief check if list contains incompatible version of pack requirement
* @param list of packs
Expand Down
13 changes: 13 additions & 0 deletions tools/projmgr/src/ProjMgrUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,16 @@ const std::string ProjMgrUtils::GetWestBoard(const std::string& board) {
std::replace(westBoard.begin(), westBoard.end(), '-', '_');
return westBoard;
}

void ProjMgrUtils::AdjustRelativePaths(vector<string>& vec, const string& ref, const string& outDir) {
static const regex pattern(R"((\.{1,2}/.*))");
for (string& value : vec) {
if (!value.empty()) {
smatch match;
if (regex_search(value, match, pattern)) {
const auto& replacement = RteFsUtils::RelativePath(ref + "/" + match.str(), outDir, true);
value.replace(match.position(), match.length(), replacement);
}
}
}
}
Comment thread
brondani marked this conversation as resolved.
15 changes: 5 additions & 10 deletions tools/projmgr/src/ProjMgrWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5132,16 +5132,11 @@ bool ProjMgrWorker::ProcessSequencesRelatives(ContextItem& context, BuildType& b
return false;
}
for (auto& misc : build.misc) {
if (!ProcessSequencesRelatives(context, misc.as, "", "", true) ||
!ProcessSequencesRelatives(context, misc.c, "", "", true) ||
!ProcessSequencesRelatives(context, misc.cpp, "", "", true) ||
!ProcessSequencesRelatives(context, misc.c_cpp, "", "", true) ||
!ProcessSequencesRelatives(context, misc.lib, "", "", true) ||
!ProcessSequencesRelatives(context, misc.library, "", "", true) ||
!ProcessSequencesRelatives(context, misc.link, "", "", true) ||
!ProcessSequencesRelatives(context, misc.link_c, "", "", true) ||
!ProcessSequencesRelatives(context, misc.link_cpp, "", "", true)) {
return false;
for (auto* vec : { &misc.as, &misc.c, &misc.cpp, &misc.c_cpp, &misc.lib, &misc.library, &misc.link, &misc.link_c, &misc.link_cpp }) {
ProjMgrUtils::AdjustRelativePaths(*vec, ref, context.directories.cprj);
if (!ProcessSequencesRelatives(context, *vec, "", "", true)) {
return false;
}
}
}
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/clayer.schema.json

layer:
misc:
- C-CPP:
- --misc-layer=./relative/from-layer

groups:
- group: Sources
files:
- file: ../main.c
3 changes: 3 additions & 0 deletions tools/projmgr/test/data/TestMiscRelativePaths/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main(void) {
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json

solution:
target-types:
- type: TEST_TARGET
device: RteTest_ARMCM0
misc:
- C-CPP:
- --misc-sol=./relative/from-solution

build-types:
- type: Debug

projects:
- project: ./project/misc-relative.cproject.yml

packs:
- pack: ARM::RteTest
- pack: ARM::RteTest_DFP
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/cproject.schema.json

project:
compiler: AC6
components:
- component: CORE

misc:
- C-CPP:
- --misc-proj=./relative/from-project

layers:
- layer: ../layers/misc-relative.clayer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
build:
generated-by: csolution version 0.0.0
solution: ../../../../../../data/TestMiscRelativePaths/misc-relative.csolution.yml
project: ../../../../../../data/TestMiscRelativePaths/project/misc-relative.cproject.yml
context: misc-relative.Debug+TEST_TARGET
compiler: AC6
device: ARM::RteTest_ARMCM0
device-pack: ARM::RteTest_DFP@0.2.0
device-books:
- name: http://infocenter.arm.com/help/topic/com.arm.doc.dui0497a/index.html
title: Cortex-M0 Device Generic Users Guide
dbgconf:
- file: ../../../../../../data/TestMiscRelativePaths/.cmsis/misc-relative+TEST_TARGET.dbgconf
version: 0.0.2
processor:
fpu: off
core: Cortex-M0
packs:
- pack: ARM::RteTest_DFP@0.2.0
path: ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0
misc:
C:
- --misc-proj=../../../../../../data/TestMiscRelativePaths/project/relative/from-project
- --misc-sol=../../../../../../data/TestMiscRelativePaths/relative/from-solution
- --misc-layer=../../../../../../data/TestMiscRelativePaths/layers/relative/from-layer
CPP:
- --misc-proj=../../../../../../data/TestMiscRelativePaths/project/relative/from-project
- --misc-sol=../../../../../../data/TestMiscRelativePaths/relative/from-solution
- --misc-layer=../../../../../../data/TestMiscRelativePaths/layers/relative/from-layer
define:
- ARMCM0
- _RTE_
define-asm:
- ARMCM0
- _RTE_
add-path:
- ../../../../../../data/TestMiscRelativePaths/project/RTE/_Debug_TEST_TARGET
- ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Device/ARM/ARMCM0/Include
add-path-asm:
- ../../../../../../data/TestMiscRelativePaths/project/RTE/_Debug_TEST_TARGET
- ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Device/ARM/ARMCM0/Include
output-dirs:
intdir: ../../../../tmp
outdir: .
rtedir: ../../../../../../data/TestMiscRelativePaths/project/RTE
output:
- type: elf
file: misc-relative.axf
- type: comp-db
file: compile_commands.json
- type: comp-db
file: compile_macros.h
components:
- component: ARM::RteTest:CORE@0.1.1
condition: Cortex-M Device
from-pack: ARM::RteTest_DFP@0.2.0
selected-by: CORE
implements: RteTest:CORE@1.1.2
files:
- file: ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Doc/html/index.html
category: doc
version: 0.1.1
apis:
- api: RteTest:CORE@1.1.2
from-pack: ARM::RteTest_DFP@0.2.0
implemented-by: ARM::RteTest:CORE@0.1.1
files:
- file: https://arm-software.github.io/CMSIS_5/Pack/html/pdsc_apis_pg.html
category: doc
version: 1.1.2
linker:
script: ../../../../../../data/TestMiscRelativePaths/project/RTE/Device/RteTest_ARMCM0/ac6_linker_script.sct.src
regions: ../../../../../../data/TestMiscRelativePaths/project/RTE/Device/RteTest_ARMCM0/regions_RteTest_ARMCM0.h
groups:
- group: Sources
files:
- file: ../../../../../../data/TestMiscRelativePaths/main.c
category: sourceC
constructed-files:
- file: ../../../../../../data/TestMiscRelativePaths/project/RTE/_Debug_TEST_TARGET/RTE_Components.h
category: header
licenses:
- license: <unknown>
license-agreement: ${CMSIS_PACK_ROOT}/ARM/RteTest_DFP/0.2.0/Doc/license.txt
packs:
- pack: ARM::RteTest_DFP@0.2.0
components:
- component: ARM::RteTest:CORE@0.1.1
- component: RteTest:CORE(API)
16 changes: 16 additions & 0 deletions tools/projmgr/test/src/ProjMgrUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,22 @@ TEST_F(ProjMgrUnitTests, RunProjMgrLayers) {
EXPECT_TRUE(RteFsUtils::Exists(testinput_folder + "/TestLayers/Layer3/RTE/RteTest/MyDir"));
}

TEST_F(ProjMgrUnitTests, MiscRelativePathsAtAllLevels) {
char* argv[5];

const string csolution = testinput_folder + "/TestMiscRelativePaths/misc-relative.csolution.yml";
const string output = testoutput_folder + "/misc-relative";
argv[1] = (char*)"convert";
argv[2] = (char*)csolution.c_str();
argv[3] = (char*)"-o";
argv[4] = (char*)output.c_str();
EXPECT_EQ(0, RunProjMgr(5, argv, m_envp));

const string cbuildFile = output + "/out/misc-relative/TEST_TARGET/Debug/misc-relative.Debug+TEST_TARGET.cbuild.yml";
ProjMgrTestEnv::CompareFile(cbuildFile,
testinput_folder + "/TestMiscRelativePaths/ref/misc-relative.Debug+TEST_TARGET.cbuild.yml");
}

TEST_F(ProjMgrUnitTests, RunProjMgrSolution_CbuildFailedToCreate) {
char* argv[7];
StdStreamRedirect streamRedirect;
Expand Down
22 changes: 22 additions & 0 deletions tools/projmgr/test/src/ProjMgrUtilsUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,28 @@ TEST_F(ProjMgrUtilsUnitTests, ReplaceDelimiters) {
EXPECT_EQ("path_with_spaces", ProjMgrUtils::ReplaceDelimiters("path/with spaces"));
}

TEST_F(ProjMgrUtilsUnitTests, AdjustRelativePaths) {
const string baseDir = testoutput_folder + "/AdjustRelativePaths";
const string refDir = baseDir + "/ref";
const string outDir = baseDir + "/out/sub";

RteFsUtils::CreateDirectories(refDir + "/assets");
RteFsUtils::CreateDirectories(baseDir + "/shared");
RteFsUtils::CreateDirectories(outDir);

vector<string> paths = {
"prefix ./assets/file.txt suffix",
"copy ../shared/config.yml",
"absolute/path/unchanged",
};

ProjMgrUtils::AdjustRelativePaths(paths, refDir, outDir);

EXPECT_EQ("prefix ../../ref/assets/file.txt suffix", paths[0]);
EXPECT_EQ("copy ../../shared/config.yml", paths[1]);
EXPECT_EQ("absolute/path/unchanged", paths[2]);
}

TEST_F(ProjMgrUtilsUnitTests, FindReferencedContext) {
const vector<string> selectedContexts = {
"Project1.Debug+Target",
Expand Down
Loading