diff options
author | Brad King <brad.king@kitware.com> | 2019-07-24 13:53:53 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-07-24 15:37:31 (GMT) |
commit | d46bac5d38320907cc1f11a223fddd9a11c9b184 (patch) | |
tree | e38aa928a8ea7b7f8194740d813d1c074d04e36e /Source/kwsys | |
parent | 79bcf4e1655ffa38e8f4740b19ec3a14ac567eec (diff) | |
download | CMake-d46bac5d38320907cc1f11a223fddd9a11c9b184.zip CMake-d46bac5d38320907cc1f11a223fddd9a11c9b184.tar.gz CMake-d46bac5d38320907cc1f11a223fddd9a11c9b184.tar.bz2 |
Makefile: Fix regression in dependencies on relative includes
Since commit a13a5c948e (Replace use of CollapseCombinedPath with
CollapseFullPath, 2019-03-19, v3.15.0-rc1~361^2~1), one code path now
calls `CollapseFullPath` with a base path that may be relative.
Backport KWSys commit c6f8e24a3 (SystemTools: Fix CollapseFullPath with
relative base path, 2019-07-24) to handle such base paths.
This case occurs when a build tree is placed in a directory inside a
source tree such that CMake is willing to generate a relative path from
the build tree to the source tree. Add a test covering this case.
Fixes: #19507
Diffstat (limited to 'Source/kwsys')
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 7 | ||||
-rw-r--r-- | Source/kwsys/testSystemTools.cxx | 8 |
2 files changed, 12 insertions, 3 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 2135913..ae7a18a 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -3394,8 +3394,13 @@ static void SystemToolsAppendComponents( static const std::string cur = "."; for (std::vector<std::string>::const_iterator i = first; i != last; ++i) { if (*i == up) { - if (out_components.size() > 1) { + // Remove the previous component if possible. Ignore ../ components + // that try to go above the root. Keep ../ components if they are + // at the beginning of a relative path (base path is relative). + if (out_components.size() > 1 && out_components.back() != up) { out_components.resize(out_components.size() - 1); + } else if (!out_components.empty() && out_components[0].empty()) { + out_components.emplace_back(std::move(*i)); } } else if (!i->empty() && *i != cur) { #if __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L) diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx index 9a40b53..ffa6a29 100644 --- a/Source/kwsys/testSystemTools.cxx +++ b/Source/kwsys/testSystemTools.cxx @@ -684,9 +684,10 @@ static bool CheckRelativePaths() } static bool CheckCollapsePath(const std::string& path, - const std::string& expected) + const std::string& expected, + const char* base = nullptr) { - std::string result = kwsys::SystemTools::CollapseFullPath(path); + std::string result = kwsys::SystemTools::CollapseFullPath(path, base); if (!kwsys::SystemTools::ComparePath(expected, result)) { std::cerr << "CollapseFullPath(" << path << ") yielded " << result << " instead of " << expected << std::endl; @@ -710,6 +711,9 @@ static bool CheckCollapsePath() res &= CheckCollapsePath("C:/", "C:/"); res &= CheckCollapsePath("C:/../", "C:/"); res &= CheckCollapsePath("C:/../../", "C:/"); + res &= CheckCollapsePath("../b", "../../b", "../"); + res &= CheckCollapsePath("../a/../b", "../b", "../rel"); + res &= CheckCollapsePath("a/../b", "../rel/b", "../rel"); return res; } |