From: Joel Rosdahl Date: Mon, 1 Aug 2022 12:53:52 +0000 (+0200) Subject: fix: Always rewrite dependency file if base_dir is used X-Git-Tag: v4.6.2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c089aa81533f01fcca2b421b44800479ec297729;p=thirdparty%2Fccache.git fix: Always rewrite dependency file if base_dir is used [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) --- diff --git a/src/Context.hpp b/src/Context.hpp index 241ad455d..d701b9736 100644 --- a/src/Context.hpp +++ b/src/Context.hpp @@ -71,9 +71,6 @@ public: // Files included by the preprocessor and their hashes. std::unordered_map 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; diff --git a/src/Depfile.cpp b/src/Depfile.cpp index 3fcc0bcd7..49c7c063a 100644 --- a/src/Depfile.cpp +++ b/src/Depfile.cpp @@ -61,7 +61,6 @@ nonstd::optional 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; diff --git a/src/ccache.cpp b/src/ccache.cpp index ec33db832..0bee98d8d 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -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); } diff --git a/unittest/test_Depfile.cpp b/unittest/test_Depfile.cpp index c4f7e3530..d00e3b1ae 100644 --- a/unittest/test_Depfile.cpp +++ b/unittest/test_Depfile.cpp @@ -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",