]> 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>
Sat, 20 Aug 2022 12:13:12 +0000 (14:13 +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

(cherry picked from commit 1ee5365507ff3dd3d071f9ccd9380ad5c661ee12)

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

index 241ad455d7a7749b466df2f04becc4d2b0ddcc51..d701b9736de6e68b126150876b8d9fff7e9ad20c 100644 (file)
@@ -71,9 +71,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 3fcc0bcd73df7c1050eaaef8578fa9f4672c4458..49c7c063a9b3e5390e1e8fcd2ef2f71004122ab6 100644 (file)
@@ -61,7 +61,6 @@ nonstd::optional<std::string>
 rewrite_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) {
@@ -116,11 +115,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 ec33db832bd47f9a5a3944b139ff663d7e750f16..0bee98d8d892d7af9cac4e1e025b74feacdfe62c 100644 (file)
@@ -553,9 +553,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);
 
@@ -639,9 +636,6 @@ result_key_from_depfile(Context& ctx, Hash& hash)
     if (token.ends_with(":")) {
       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 c4f7e3530291151699a4d2b56010cd09925a3380..d00e3b1ae8a47d064f8758527fc7174a2623046a 100644 (file)
@@ -43,7 +43,6 @@ TEST_CASE("Depfile::rewrite_paths")
   Context ctx;
 
   const auto cwd = ctx.actual_cwd;
-  ctx.has_absolute_include_headers = true;
 
   const auto content =
     FMT("foo.o: bar.c {0}/bar.h \\\n\n {1}/fie.h {0}/fum.h\n",