Fix GN freeze on generating Visual Studio projects There's an infinite loop while searching for parent directory. It happens when drive letter case is mixed in absolute paths on Windows (/C:/foo and /c:/foo). It's easily reproducible on MSYS terminals when system-absolute paths are used for some targets and source root-absolute (//foo/bar) paths are used for other targets. BUG= Review URL: https://codereview.chromium.org/1897213002 Cr-Original-Commit-Position: refs/heads/master@{#388443} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: e4b98e2d9ff4fceae0d515d5795e677ff4518223
diff --git a/tools/gn/visual_studio_writer.cc b/tools/gn/visual_studio_writer.cc index 4f92344..14a02cd 100644 --- a/tools/gn/visual_studio_writer.cc +++ b/tools/gn/visual_studio_writer.cc
@@ -181,7 +181,11 @@ const std::string& _config_platform) : SolutionEntry(_name, _path, _guid), label_dir_path(_label_dir_path), - config_platform(_config_platform) {} + config_platform(_config_platform) { + // Make sure all paths use the same drive letter case. This is especially + // important when searching for the common path prefix. + label_dir_path[0] = base::ToUpperASCII(label_dir_path[0]); +} VisualStudioWriter::SolutionProject::~SolutionProject() = default;
diff --git a/tools/gn/visual_studio_writer_unittest.cc b/tools/gn/visual_studio_writer_unittest.cc index 16e327b..f89c1c1 100644 --- a/tools/gn/visual_studio_writer_unittest.cc +++ b/tools/gn/visual_studio_writer_unittest.cc
@@ -4,6 +4,7 @@ #include "tools/gn/visual_studio_writer.h" +#include "base/strings/string_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "tools/gn/test_with_scope.h" #include "tools/gn/visual_studio_utils.h" @@ -100,11 +101,15 @@ "bar", path, MakeGuid(path, "project"), MakeTestPath("/foo/bar"), "Win32")); + std::string baz_label_dir_path = MakeTestPath("/foo/bar/baz"); +#if defined(OS_WIN) + // Make sure mixed lower and upper-case drive letters are handled properly. + baz_label_dir_path[0] = base::ToLowerASCII(baz_label_dir_path[0]); +#endif path = MakeTestPath( "/foo/chromium/src/out/Debug/obj/ABS_PATH/C/foo/bar/baz/baz.vcxproj"); writer.projects_.emplace_back(new VisualStudioWriter::SolutionProject( - "baz", path, MakeGuid(path, "project"), MakeTestPath("/foo/bar/baz"), - "Win32")); + "baz", path, MakeGuid(path, "project"), baz_label_dir_path, "Win32")); writer.ResolveSolutionFolders();