]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Fix matching of base directory for MSVC
authorJoel Rosdahl <joel.rosdahl@maxar.com>
Wed, 21 Dec 2022 12:16:12 +0000 (13:16 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 23 Dec 2022 09:56:43 +0000 (10:56 +0100)
The base directory will now match case-insensitively with absolute paths
in preprocessed output, or from /showIncludes in the depend mode case,
when compiling with MSVC.

src/Util.cpp
src/ccache.cpp
src/util/path.cpp
unittest/test_argprocessing.cpp
unittest/test_util_path.cpp

index 844e5497a14171391f95e57124e17425215a38f0..8f6b4102c1fe582199bfafe36fd08a0b2fa07e4c 100644 (file)
@@ -910,20 +910,14 @@ matches_dir_prefix_or_file(std::string_view dir_prefix_or_file,
              || is_dir_separator(dir_prefix_or_file.back()));
 }
 
-std::string
-normalize_abstract_absolute_path(std::string_view path)
+static std::string
+do_normalize_abstract_absolute_path(std::string_view path)
 {
   if (!util::is_absolute_path(path)) {
     return std::string(path);
   }
 
 #ifdef _WIN32
-  if (path.find("\\") != std::string_view::npos) {
-    std::string new_path(path);
-    std::replace(new_path.begin(), new_path.end(), '\\', '/');
-    return normalize_abstract_absolute_path(new_path);
-  }
-
   std::string drive(path.substr(0, 2));
   path = path.substr(2);
 #endif
@@ -970,6 +964,18 @@ normalize_abstract_absolute_path(std::string_view path)
 #endif
 }
 
+std::string
+normalize_abstract_absolute_path(std::string_view path)
+{
+#ifdef _WIN32
+  std::string new_path(path);
+  std::replace(new_path.begin(), new_path.end(), '\\', '/');
+  return do_normalize_abstract_absolute_path(new_path);
+#else
+  return do_normalize_abstract_absolute_path(path);
+#endif
+}
+
 std::string
 normalize_concrete_absolute_path(const std::string& path)
 {
index c8a21ac354d96fc9a8904961c55f329cf6dfecb8..8f71e2a29cdb8a9b3a819c7e6af7ecfd0495946f 100644 (file)
@@ -704,9 +704,10 @@ struct DoExecuteResult
 static std::optional<Digest>
 result_key_from_includes(Context& ctx, Hash& hash, std::string_view stdout_data)
 {
-  for (std::string_view token : core::MsvcShowIncludesOutput::get_includes(
+  for (std::string_view include : core::MsvcShowIncludesOutput::get_includes(
          stdout_data, ctx.config.msvc_dep_prefix())) {
-    const std::string path = Util::make_relative_path(ctx, token);
+    const std::string path = Util::make_relative_path(
+      ctx, Util::normalize_abstract_absolute_path(include));
     remember_include_file(ctx, path, hash, false, &hash);
   }
 
index a1e797ded33a0570279beaeae87408e3c718716f..d1e6b7e858537f465dc497d64c35d3c36dd50692 100644 (file)
@@ -73,10 +73,14 @@ path_starts_with(std::string_view path, std::string_view prefix)
     if (path[i] == '\\' && prefix[j] == '/') {
       continue;
     }
-#endif
+    if (std::tolower(path[i]) != std::tolower(prefix[j])) {
+      return false;
+    }
+#else
     if (path[i] != prefix[j]) {
       return false;
     }
+#endif
   }
   return true;
 }
index 1a59f6a207435b2fbf287b842e701dfc187e190b..062d66221beb2bdeb9879e51ffc959bbf8ec6e9f 100644 (file)
@@ -59,7 +59,9 @@ get_posix_path(const std::string& path)
   std::string posix;
 
   // /-escape volume.
-  if (path[0] >= 'A' && path[0] <= 'Z' && path[1] == ':') {
+  if (path[1] == ':'
+      && ((path[0] >= 'A' && path[0] <= 'Z')
+          || (path[0] >= 'a' && path[0] <= 'z'))) {
     posix = "/" + path;
   } else {
     posix = path;
index 43defcada2e37b6a998184234207a1b39c36707d..8bb703dffcfac9078bca3cc5eae1d61e7d4867f2 100644 (file)
@@ -131,6 +131,8 @@ TEST_CASE("util::path_starts_with")
   CHECK(util::path_starts_with("C:/foo/bar", "C:\\\\foo"));
   CHECK(util::path_starts_with("C:\\foo\\bar", "C:/foo"));
   CHECK(util::path_starts_with("C:\\\\foo\\\\bar", "C:/foo"));
+  CHECK(util::path_starts_with("C:/FOO/BAR", "c:\\foo"));
+  CHECK(util::path_starts_with("c:/foo/bar", "C:\\FOO"));
   CHECK(!util::path_starts_with("C:\\foo\\bar", "/foo/baz"));
   CHECK(!util::path_starts_with("C:\\foo\\bar", "C:/foo/baz"));
   CHECK(!util::path_starts_with("C:\\beh\\foo", "/foo"));