diff options
-rw-r--r-- | tools/gn/filesystem_utils.cc | 13 | ||||
-rw-r--r-- | tools/gn/filesystem_utils_unittest.cc | 18 |
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) { |