From 8bebcec47848b5129e0ce41fd4c3ee8a79ba7600 Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Wed, 1 Feb 2017 16:32:08 +0000 Subject: Rollback of commit 855fbe9ee447b7b37fd8c73dbc047d69b7ceffcf. *** Reason for rollback *** Causing bazel server restart every time on Windows See https://github.com/bazelbuild/bazel/issues/2466 *** Original change description *** Bazel client: platform-specific JoinPath This allows joining paths on "\" instead of "/" when building for Windows. See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 146246700 MOS_MIGRATED_REVID=146246700 --- src/main/cpp/util/file.cc | 25 +++++++++++++++++++++++++ src/main/cpp/util/file.h | 3 ++- src/main/cpp/util/file_platform.h | 2 -- src/main/cpp/util/file_posix.cc | 29 ----------------------------- src/main/cpp/util/file_windows.cc | 38 -------------------------------------- 5 files changed, 27 insertions(+), 70 deletions(-) (limited to 'src/main/cpp/util') diff --git a/src/main/cpp/util/file.cc b/src/main/cpp/util/file.cc index cae87198a7..392af372af 100644 --- a/src/main/cpp/util/file.cc +++ b/src/main/cpp/util/file.cc @@ -77,6 +77,31 @@ string Basename(const string &path) { return SplitPath(path).second; } +string JoinPath(const string &path1, const string &path2) { + if (path1.empty()) { + // "" + "/bar" + return path2; + } + + if (path1[path1.size() - 1] == '/') { + if (path2.find('/') == 0) { + // foo/ + /bar + return path1 + path2.substr(1); + } else { + // foo/ + bar + return path1 + path2; + } + } else { + if (path2.find('/') == 0) { + // foo + /bar + return path1 + path2; + } else { + // foo + bar + return path1 + "/" + path2; + } + } +} + class DirectoryTreeWalker : public DirectoryEntryConsumer { public: DirectoryTreeWalker(vector *files, diff --git a/src/main/cpp/util/file.h b/src/main/cpp/util/file.h index e3a744f652..efe963c6d7 100644 --- a/src/main/cpp/util/file.h +++ b/src/main/cpp/util/file.h @@ -17,7 +17,6 @@ #include #include #include -#include "src/main/cpp/util/file_platform.h" namespace blaze_util { @@ -60,6 +59,8 @@ std::string Dirname(const std::string &path); // "/" in the path, the result is the same as the input. std::string Basename(const std::string &path); +std::string JoinPath(const std::string &path1, const std::string &path2); + // Lists all files in `path` and all of its subdirectories. // // Does not follow symlinks / junctions. diff --git a/src/main/cpp/util/file_platform.h b/src/main/cpp/util/file_platform.h index 99cf99044b..600820ba0c 100644 --- a/src/main/cpp/util/file_platform.h +++ b/src/main/cpp/util/file_platform.h @@ -50,8 +50,6 @@ class IFileMtime { // Creates a platform-specific implementation of `IFileMtime`. IFileMtime *CreateFileMtime(); -std::string JoinPath(const std::string &path1, const std::string &path2); - // Split a path to dirname and basename parts. std::pair SplitPath(const std::string &path); diff --git a/src/main/cpp/util/file_posix.cc b/src/main/cpp/util/file_posix.cc index 57c994a3ff..a1d806a9d9 100644 --- a/src/main/cpp/util/file_posix.cc +++ b/src/main/cpp/util/file_posix.cc @@ -168,35 +168,6 @@ IPipe* CreatePipe() { return new PosixPipe(fd[0], fd[1]); } -string JoinPath(const string &path1, const string &path2) { - if (path1.empty()) { - // "" + "/bar" - return path2; - } - if (path2.empty()) { - // "foo/" + "" - return path1; - } - - if (path1.back() == '/') { - if (path2.front() == '/') { - // foo/ + /bar - return path1 + path2.substr(1); - } else { - // foo/ + bar - return path1 + path2; - } - } else { - if (path2.front() == '/') { - // foo + /bar - return path1 + path2; - } else { - // foo + bar - return path1 + "/" + path2; - } - } -} - pair SplitPath(const string &path) { size_t pos = path.rfind('/'); diff --git a/src/main/cpp/util/file_windows.cc b/src/main/cpp/util/file_windows.cc index 2577a41aa1..4b7570d188 100644 --- a/src/main/cpp/util/file_windows.cc +++ b/src/main/cpp/util/file_windows.cc @@ -323,44 +323,6 @@ static bool IsRootOrAbsolute(const basic_string& path, HasDriveSpecifierPrefix(path.c_str() + 4) && IsPathSeparator(path[6])); } -string JoinPath(const string& path1, const string& path2) { - if (path1.empty()) { - // "" + "/bar" - return path2; - } - if (path2.empty()) { - // "foo/" + "" - return path1; - } - - string p1 = path1; - if (path1.back() == '/') { - p1.pop_back(); - } - string p2 = path2; - if (path2.front() == '/') { - p2[0] = '\\'; - } - - if (IsPathSeparator(p1.back())) { - if (!p2.empty() && IsPathSeparator(p2.front())) { - // foo/ + /bar - return p1 + p2.substr(1); - } else { - // foo/ + bar - return p1 + p2; - } - } else { - if (!p2.empty() && IsPathSeparator(p2.front())) { - // foo + /bar - return p1 + p2; - } else { - // foo + bar - return p1 + "\\" + p2; - } - } -} - pair SplitPath(const string& path) { if (path.empty()) { return std::make_pair("", ""); -- cgit v1.2.3