Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[projmgr] Ignore references to absolute paths #1060

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
2 changes: 1 addition & 1 deletion tools/projmgr/include/ProjMgrYamlParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>& 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);

};

Expand Down
11 changes: 7 additions & 4 deletions tools/projmgr/src/ProjMgrYamlParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<string>& 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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tools/projmgr/test/src/ProjMgrUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Loading