summaryrefslogtreecommitdiffstats
path: root/tools/gn
diff options
context:
space:
mode:
authortmoniuszko <tmoniuszko@opera.com>2016-03-22 01:30:14 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-22 08:33:10 +0000
commit01a402cd6fb6873e61d2faa269b6b991d307635e (patch)
tree859dbb80d137316093042bf7898cdfa288f320a5 /tools/gn
parent152896e16e1ad357d086ac983ba2d31f50f4a501 (diff)
downloadchromium_src-01a402cd6fb6873e61d2faa269b6b991d307635e.zip
chromium_src-01a402cd6fb6873e61d2faa269b6b991d307635e.tar.gz
chromium_src-01a402cd6fb6873e61d2faa269b6b991d307635e.tar.bz2
Make rebase_path() aware of Windows drive letter capitalization
Make sure rebase_path() supports both capital and non-capital Windows path drive letters. It's unable to find common path prefix otherwise. BUG=596072 Review URL: https://codereview.chromium.org/1817533002 Cr-Commit-Position: refs/heads/master@{#382532}
Diffstat (limited to 'tools/gn')
-rw-r--r--tools/gn/filesystem_utils.cc13
-rw-r--r--tools/gn/filesystem_utils_unittest.cc18
2 files changed, 31 insertions, 0 deletions
diff --git a/tools/gn/filesystem_utils.cc b/tools/gn/filesystem_utils.cc
index 2ceca81..facf442 100644
--- a/tools/gn/filesystem_utils.cc
+++ b/tools/gn/filesystem_utils.cc
@@ -529,6 +529,19 @@ std::string MakeRelativePath(const std::string& input,
corrected_dest.append(dest);
return MakeRelativePath(input, corrected_dest);
}
+
+ // Make sure that both absolute paths use the same drive letter case.
+ if (IsPathAbsolute(input) && IsPathAbsolute(dest) && input.size() > 1 &&
+ dest.size() > 1) {
+ int letter_pos = base::IsAsciiAlpha(input[0]) ? 0 : 1;
+ if (input[letter_pos] != dest[letter_pos] &&
+ base::ToUpperASCII(input[letter_pos]) ==
+ base::ToUpperASCII(dest[letter_pos])) {
+ std::string corrected_input = input;
+ corrected_input[letter_pos] = dest[letter_pos];
+ return MakeRelativePath(corrected_input, dest);
+ }
+ }
#endif
std::string ret;
diff --git a/tools/gn/filesystem_utils_unittest.cc b/tools/gn/filesystem_utils_unittest.cc
index d5638900..894b3da 100644
--- a/tools/gn/filesystem_utils_unittest.cc
+++ b/tools/gn/filesystem_utils_unittest.cc
@@ -488,6 +488,24 @@ TEST(FilesystemUtils, RebasePath) {
RebasePath("/path/to/foo", SourceDir("/source/root/a/b"),
base::StringPiece("/x/y/z")));
+#if defined(OS_WIN)
+ // Test corrections while rebasing Windows-style absolute paths.
+ EXPECT_EQ("../../../../path/to/foo",
+ RebasePath("C:/path/to/foo", SourceDir("//a/b"),
+ base::StringPiece("/C:/source/root")));
+ EXPECT_EQ("../../../../path/to/foo",
+ RebasePath("/C:/path/to/foo", SourceDir("//a/b"),
+ base::StringPiece("C:/source/root")));
+ EXPECT_EQ("../../../../path/to/foo",
+ RebasePath("/C:/path/to/foo", SourceDir("//a/b"),
+ base::StringPiece("/c:/source/root")));
+ EXPECT_EQ("../../../../path/to/foo",
+ RebasePath("/c:/path/to/foo", SourceDir("//a/b"),
+ base::StringPiece("c:/source/root")));
+ EXPECT_EQ("../../../../path/to/foo",
+ RebasePath("/c:/path/to/foo", SourceDir("//a/b"),
+ base::StringPiece("C:/source/root")));
+#endif
}
TEST(FilesystemUtils, DirectoryWithNoLastSlash) {