]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Normalize paths to fix basedir option on Windows (#1033)
authorvvainola <vilivainola@gmail.com>
Sat, 30 Apr 2022 20:13:58 +0000 (23:13 +0300)
committerGitHub <noreply@github.com>
Sat, 30 Apr 2022 20:13:58 +0000 (22:13 +0200)
Co-authored-by: Joel Rosdahl <joel@rosdahl.net>
src/ArgsInfo.hpp
src/argprocessing.cpp
src/ccache.cpp

index 41b18740b0ac8c99412eb8a02b53cc75171caaf2..343fedc6effe7ca30b9a722bf1a4a030b25d3ea1 100644 (file)
 // This class holds meta-information derived from the compiler arguments.
 struct ArgsInfo
 {
-  // The source file.
+  // The source file path.
   std::string input_file;
 
+  // The source file path run through Util::normalize_concrete_absolute_path.
+  std::string normalized_input_file;
+
   // In normal compiler operation an output file is created if there is no
   // compiler error. However certain flags like -fsyntax-only change this
   // behavior.
index fbd92188d0dc9098cf6ed95a8fadf05437bfe926..518d3e1a0f444520f6d9522abc7daf7ab8b8f775 100644 (file)
@@ -1016,6 +1016,8 @@ process_arg(const Context& ctx,
 
   // Rewrite to relative to increase hit rate.
   args_info.input_file = Util::make_relative_path(ctx, args[i]);
+  args_info.normalized_input_file =
+    Util::normalize_concrete_absolute_path(args_info.input_file);
 
   return nullopt;
 }
index 175160e00b133e4377762dc5dbc549de8efbe570..5316d20e16a263da59c1491f1bc0f47df1d7bbe7 100644 (file)
@@ -284,7 +284,7 @@ do_remember_include_file(Context& ctx,
     return true;
   }
 
-  if (path == ctx.args_info.input_file) {
+  if (path == ctx.args_info.normalized_input_file) {
     // Don't remember the input file.
     return true;
   }
@@ -553,23 +553,10 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path)
       if (!ctx.has_absolute_include_headers) {
         ctx.has_absolute_include_headers = util::is_absolute_path(inc_path);
       }
+      inc_path = Util::normalize_concrete_absolute_path(inc_path);
       inc_path = Util::make_relative_path(ctx, inc_path);
 
-      bool should_hash_inc_path = true;
-      if (!ctx.config.hash_dir()) {
-        if (util::starts_with(inc_path, ctx.apparent_cwd)
-            && util::ends_with(inc_path, "//")) {
-          // When compiling with -g or similar, GCC adds the absolute path to
-          // CWD like this:
-          //
-          //   # 1 "CWD//"
-          //
-          // If the user has opted out of including the CWD in the hash, don't
-          // hash it. See also how debug_prefix_map is handled.
-          should_hash_inc_path = false;
-        }
-      }
-      if (should_hash_inc_path) {
+      if ((inc_path != ctx.apparent_cwd) || ctx.config.hash_dir()) {
         hash.hash(inc_path);
       }
 
@@ -911,17 +898,29 @@ rewrite_stdout_from_compiler(const Context& ctx, std::string&& stdout_data)
   using util::Tokenizer;
   using Mode = Tokenizer::Mode;
   using IncludeDelimiter = Tokenizer::IncludeDelimiter;
-  // distcc-pump outputs lines like this:
-  //
-  //   __________Using # distcc servers in pump mode
-  //
-  // We don't want to cache those.
   if (!stdout_data.empty()) {
     std::string new_stdout_text;
     for (const auto line : Tokenizer(
            stdout_data, "\n", Mode::include_empty, IncludeDelimiter::yes)) {
       if (util::starts_with(line, "__________")) {
         Util::send_to_fd(ctx, std::string(line), STDOUT_FILENO);
+      }
+      // Ninja uses the lines with 'Note: including file: ' to determine the
+      // used headers. Headers within basedir need to be changed into relative
+      // paths because otherwise Ninja will use the abs path to original header
+      // to check if a file needs to be recompiled.
+      else if (ctx.config.compiler_type() == CompilerType::msvc
+               && !ctx.config.base_dir().empty()
+               && util::starts_with(line, "Note: including file:")) {
+        std::string orig_line(line.data(), line.length());
+        std::string abs_inc_path =
+          util::replace_first(orig_line, "Note: including file:", "");
+        abs_inc_path = util::strip_whitespace(abs_inc_path);
+        std::string rel_inc_path = Util::make_relative_path(
+          ctx, Util::normalize_concrete_absolute_path(abs_inc_path));
+        std::string line_with_rel_inc =
+          util::replace_first(orig_line, abs_inc_path, rel_inc_path);
+        new_stdout_text.append(line_with_rel_inc);
       } else {
         new_stdout_text.append(line.data(), line.length());
       }