From 41ef962f6ff865969fd6f7fb0c97dc6f54f8175a Mon Sep 17 00:00:00 2001 From: Daniel Brondani Date: Wed, 12 Jul 2023 11:03:13 +0200 Subject: [PATCH] [projmgr] Ignore references to absolute paths --- tools/projmgr/include/ProjMgrYamlParser.h | 2 +- tools/projmgr/src/ProjMgrYamlParser.cpp | 11 +++++++---- tools/projmgr/test/src/ProjMgrUnitTests.cpp | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/projmgr/include/ProjMgrYamlParser.h b/tools/projmgr/include/ProjMgrYamlParser.h index 40f3a8d32..1b0f7ed9a 100644 --- a/tools/projmgr/include/ProjMgrYamlParser.h +++ b/tools/projmgr/include/ProjMgrYamlParser.h @@ -210,7 +210,7 @@ class ProjMgrYamlParser { bool ValidateMapping(const std::string& input, const YAML::Node& parent, const std::string& seqKey); void ParsePortablePath(const YAML::Node& parent, const std::string& file, const std::string& key, std::string& value, bool checkExist = true); void ParsePortablePaths(const YAML::Node& parent, const std::string& file, const std::string& key, std::vector& value); - void CheckPortability(const std::string& file, const YAML::Mark& mark, const std::string& key, const std::string& value, bool checkExist); + void EnsurePortability(const std::string& file, const YAML::Mark& mark, const std::string& key, std::string& value, bool checkExist); }; diff --git a/tools/projmgr/src/ProjMgrYamlParser.cpp b/tools/projmgr/src/ProjMgrYamlParser.cpp index b0ab7fdfd..f61b43a0d 100644 --- a/tools/projmgr/src/ProjMgrYamlParser.cpp +++ b/tools/projmgr/src/ProjMgrYamlParser.cpp @@ -224,13 +224,16 @@ bool ProjMgrYamlParser::ParseClayer(const string& input, return true; } -void ProjMgrYamlParser::CheckPortability(const string& file, const YAML::Mark& mark, const string& key, const string& value, bool checkExist) { +// EnsurePortability checks the presence of backslash, case inconsistency and absolute path +// It clears the string 'value' when it is an absolute path +void ProjMgrYamlParser::EnsurePortability(const string& file, const YAML::Mark& mark, const string& key, string& value, bool checkExist) { if (value.find('\\') != string::npos) { ProjMgrLogger::Warn(file, mark.line + 1, mark.column + 1, "'" + value + "' contains non-portable backslash, use forward slash instead"); } if (!value.empty()) { if (fs::path(value).is_absolute()) { ProjMgrLogger::Warn(file, mark.line + 1, mark.column + 1, "absolute path '" + value + "' is not portable, use relative path instead"); + value.clear(); } else { const string parentDir = RteFsUtils::ParentPath(file); const string original = fs::path(parentDir).append(value).lexically_normal().generic_string(); @@ -250,15 +253,15 @@ void ProjMgrYamlParser::CheckPortability(const string& file, const YAML::Mark& m void ProjMgrYamlParser::ParsePortablePath(const YAML::Node& parent, const string& file, const string& key, string& value, bool checkExist) { ParseString(parent, key, value); YAML::Mark mark = parent[key].IsDefined() ? parent[key].Mark() : YAML::Mark(); - CheckPortability(file, mark, key, value, checkExist); + EnsurePortability(file, mark, key, value, checkExist); } void ProjMgrYamlParser::ParsePortablePaths(const YAML::Node& parent, const string& file, const string& key, vector& value) { ParseVector(parent, key, value); auto node = parent[key].begin(); - for (const auto& item : value) { + for (auto& item : value) { YAML::Mark mark = (*node++).Mark(); - CheckPortability(file, mark, key, item, true); + EnsurePortability(file, mark, key, item, true); } } diff --git a/tools/projmgr/test/src/ProjMgrUnitTests.cpp b/tools/projmgr/test/src/ProjMgrUnitTests.cpp index 88824d0c9..72e8963f6 100644 --- a/tools/projmgr/test/src/ProjMgrUnitTests.cpp +++ b/tools/projmgr/test/src/ProjMgrUnitTests.cpp @@ -3500,7 +3500,7 @@ TEST_F(ProjMgrUnitTests, FileLanguageAndScope) { testinput_folder + "/TestSolution/LanguageAndScope/ref/lang-scope.Debug_AC6+RteTest_ARMCM3.cbuild.yml"); } -TEST_F(ProjMgrUnitTests, CheckPortability) { +TEST_F(ProjMgrUnitTests, EnsurePortability) { const string host = CrossPlatformUtils::GetHostType(); const string cproject1 = testinput_folder + "/TestSolution/Portability/case/case.cproject.yml"; const string cproject2 = testinput_folder + "/TestSolution/Portability/CASE/CASE.cproject.yml";