summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvvainola <vilivainola@gmail.com>2022-04-30 23:13:58 +0300
committerGitHub <noreply@github.com>2022-04-30 22:13:58 +0200
commit236a297a7d642c95aa802a1b4f08fc701a44b91b (patch)
tree1a2f11df52bdb8c0d8c1dbbb7bd5edde3eaf03de
parent9a05332915d2808f4713437006b3f7c812d9fd74 (diff)
downloadccache-236a297a7d642c95aa802a1b4f08fc701a44b91b.tar.gz
fix: Normalize paths to fix basedir option on Windows (#1033)
Co-authored-by: Joel Rosdahl <joel@rosdahl.net>
-rw-r--r--src/ArgsInfo.hpp5
-rw-r--r--src/argprocessing.cpp2
-rw-r--r--src/ccache.cpp41
3 files changed, 26 insertions, 22 deletions
diff --git a/src/ArgsInfo.hpp b/src/ArgsInfo.hpp
index 41b18740..343fedc6 100644
--- a/src/ArgsInfo.hpp
+++ b/src/ArgsInfo.hpp
@@ -26,9 +26,12 @@
// 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.
diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp
index fbd92188..518d3e1a 100644
--- a/src/argprocessing.cpp
+++ b/src/argprocessing.cpp
@@ -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;
}
diff --git a/src/ccache.cpp b/src/ccache.cpp
index 175160e0..5316d20e 100644
--- a/src/ccache.cpp
+++ b/src/ccache.cpp
@@ -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());
}