summaryrefslogtreecommitdiff
path: root/Source/cmOutputConverter.cxx
diff options
context:
space:
mode:
authorBruno Manganelli <bruno.manga95@gmail.com>2018-11-23 01:38:29 +0000
committerBruno Manganelli <bruno.manga95@gmail.com>2018-12-07 19:29:30 +0000
commit87e810f223bad6fb889e7ae4ad08be98461bf6e2 (patch)
tree07ad1b190e0bfe2240a2e534195973e44426d913 /Source/cmOutputConverter.cxx
parent99a224e3ee0b6a770c388313a7b32746a95514e8 (diff)
downloadcmake-87e810f223bad6fb889e7ae4ad08be98461bf6e2.tar.gz
cmOutputConverter: Moved ForceToRelativePath to cmSystem
Diffstat (limited to 'Source/cmOutputConverter.cxx')
-rw-r--r--Source/cmOutputConverter.cxx76
1 files changed, 1 insertions, 75 deletions
diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx
index 80e6e9721c..58d31b9d3f 100644
--- a/Source/cmOutputConverter.cxx
+++ b/Source/cmOutputConverter.cxx
@@ -111,81 +111,7 @@ std::string cmOutputConverter::ConvertToRelativePath(
return remote_path;
}
- return cmOutputConverter::ForceToRelativePath(local_path, remote_path);
-}
-
-std::string cmOutputConverter::ForceToRelativePath(
- std::string const& local_path, std::string const& remote_path)
-{
- // The paths should never be quoted.
- assert(local_path.front() != '\"');
- assert(remote_path.front() != '\"');
-
- // The local path should never have a trailing slash.
- assert(local_path.empty() || local_path.back() != '/');
-
- // If the path is already relative then just return the path.
- if (!cmSystemTools::FileIsFullPath(remote_path)) {
- return remote_path;
- }
-
- // Identify the longest shared path component between the remote
- // path and the local path.
- std::vector<std::string> local;
- cmSystemTools::SplitPath(local_path, local);
- std::vector<std::string> remote;
- cmSystemTools::SplitPath(remote_path, remote);
- unsigned int common = 0;
- while (common < remote.size() && common < local.size() &&
- cmSystemTools::ComparePath(remote[common], local[common])) {
- ++common;
- }
-
- // If no part of the path is in common then return the full path.
- if (common == 0) {
- return remote_path;
- }
-
- // If the entire path is in common then just return a ".".
- if (common == remote.size() && common == local.size()) {
- return ".";
- }
-
- // If the entire path is in common except for a trailing slash then
- // just return a "./".
- if (common + 1 == remote.size() && remote[common].empty() &&
- common == local.size()) {
- return "./";
- }
-
- // Construct the relative path.
- std::string relative;
-
- // First add enough ../ to get up to the level of the shared portion
- // of the path. Leave off the trailing slash. Note that the last
- // component of local will never be empty because local should never
- // have a trailing slash.
- for (unsigned int i = common; i < local.size(); ++i) {
- relative += "..";
- if (i < local.size() - 1) {
- relative += "/";
- }
- }
-
- // Now add the portion of the destination path that is not included
- // in the shared portion of the path. Add a slash the first time
- // only if there was already something in the path. If there was a
- // trailing slash in the input then the last iteration of the loop
- // will add a slash followed by an empty string which will preserve
- // the trailing slash in the output.
-
- if (!relative.empty() && !remote.empty()) {
- relative += "/";
- }
- relative += cmJoin(cmMakeRange(remote).advance(common), "/");
-
- // Finally return the path.
- return relative;
+ return cmSystemTools::ForceToRelativePath(local_path, remote_path);
}
static bool cmOutputConverterIsShellOperator(const std::string& str)