]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Always rewrite dependency file if base_dir is used
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 1 Aug 2022 12:53:52 +0000 (14:53 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 1 Aug 2022 13:24:38 +0000 (15:24 +0200)
[1] added the has_absolute_include_headers variable as a performance
optimization for base_dir/CCACHE_BASEDIR so that the dependency file
only has to be parsed/rewritten when necessary. This is based on the
assumption that if no include file has an absolute path then no rewrite
is needed, but apparently Clang can insert other paths into the
dependency file as well, for instance the asan_blacklist.txt file when
using -fsanitize=address.

Fix this by simply always parsing the dependency file when base_dir is
active.

Fixes #1128.

[1]: 60178b7a8eb8d03b364afb2fb8bd6753924cd9b7

src/Context.hpp
src/Depfile.cpp
src/ccache.cpp
unittest/test_Depfile.cpp

index bf85c1ec0237335e201fea7efcd6fc0a4ece64e0..80aa641870f1567959de1c889baa7d0360a37f6e 100644 (file)
@@ -77,9 +77,6 @@ public:
   // Files included by the preprocessor and their hashes.
   std::unordered_map<std::string, Digest> included_files;
 
-  // Uses absolute path for some include files.
-  bool has_absolute_include_headers = false;
-
   // Have we tried and failed to get colored diagnostics?
   bool diagnostics_color_failed = false;
 
index 14ce863087cd5558b4db1d5fdb9c1fd26d56daae..f944bfed81e72e6d42f273916106d366df283d9e 100644 (file)
@@ -63,7 +63,6 @@ std::optional<std::string>
 rewrite_source_paths(const Context& ctx, const std::string& file_content)
 {
   ASSERT(!ctx.config.base_dir().empty());
-  ASSERT(ctx.has_absolute_include_headers);
 
   // Fast path for the common case:
   if (file_content.find(ctx.config.base_dir()) == std::string::npos) {
@@ -126,11 +125,6 @@ make_paths_relative_in_output_dep(const Context& ctx)
     LOG_RAW("Base dir not set, skip using relative paths");
     return; // nothing to do
   }
-  if (!ctx.has_absolute_include_headers) {
-    LOG_RAW(
-      "No absolute path for included files found, skip using relative paths");
-    return; // nothing to do
-  }
 
   const std::string& output_dep = ctx.args_info.output_dep;
   std::string file_content;
index bc5ae309188533dbf4d9ce402fe9dec6b8088209..73bdc583ef10606b92f7a0eb6d88a8410eb01d09 100644 (file)
@@ -567,9 +567,6 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path)
       }
       // p and q span the include file path.
       std::string inc_path(p, q - p);
-      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);
 
@@ -653,9 +650,6 @@ result_key_from_depfile(Context& ctx, Hash& hash)
     if (util::ends_with(token, ":")) {
       continue;
     }
-    if (!ctx.has_absolute_include_headers) {
-      ctx.has_absolute_include_headers = util::is_absolute_path(token);
-    }
     std::string path = Util::make_relative_path(ctx, token);
     remember_include_file(ctx, path, hash, false, &hash);
   }
index 3bbb1415b325801016adb1f3a17cd8e3fb2881e3..692a415395f57203481a0126383c1a669dda5eaf 100644 (file)
@@ -43,7 +43,6 @@ TEST_CASE("Depfile::rewrite_source_paths")
   Context ctx;
 
   const auto cwd = ctx.actual_cwd;
-  ctx.has_absolute_include_headers = true;
 
   const auto content =
     FMT("{0}/foo.o {0}/foo.o: bar.c {0}/bar.h \\\n\n {1}/fie.h {0}/fum.h\n",