in the `.gcno` file. The *gcno_cwd* sloppiness makes ccache not hash the
current working directory so that you can get cache hits when compiling in
different directories, with the tradeoff of potentially getting an incorrect
- directory in the `.gcno` file.
+ directory in the `.gcno` file. *gcno_cwd* also disables hashing of the
+ current working directory if `-fprofile-abs-path` is used.
*include_file_ctime*::
By default, ccache will not cache a file if it includes a header whose ctime
is too new. This sloppiness disables that check. See also
// Whether to include the full command line in the hash.
bool hash_full_command_line = false;
+
+ // Whether to include the actual CWD in the hash.
+ bool hash_actual_cwd = false;
};
bool
return Statistic::none;
}
+ if (args[i] == "-fprofile-abs-path") {
+ if (!config.sloppiness().is_enabled(core::Sloppy::gcno_cwd)) {
+ // -fprofile-abs-path makes the compiler include absolute paths based on
+ // the actual CWD in the .gcno file.
+ state.hash_actual_cwd = true;
+ }
+ return Statistic::none;
+ }
+
if (util::starts_with(args[i], "-fprofile-")
|| util::starts_with(args[i], "-fauto-profile")
|| args[i] == "-fbranch-probabilities") {
}
}
- return {preprocessor_args, extra_args_to_hash, compiler_args};
+ return {
+ preprocessor_args,
+ extra_args_to_hash,
+ compiler_args,
+ state.hash_actual_cwd,
+ };
}
ProcessArgsResult(core::Statistic error_);
ProcessArgsResult(const Args& preprocessor_args_,
const Args& extra_args_to_hash_,
- const Args& compiler_args_);
+ const Args& compiler_args_,
+ bool hash_actual_cwd_);
// nullopt on success, otherwise the statistics counter that should be
// incremented.
// Arguments to send to the real compiler.
Args compiler_args;
+
+ // Whether to include the actual CWD in the hash.
+ bool hash_actual_cwd;
};
inline ProcessArgsResult::ProcessArgsResult(core::Statistic error_)
inline ProcessArgsResult::ProcessArgsResult(const Args& preprocessor_args_,
const Args& extra_args_to_hash_,
- const Args& compiler_args_)
+ const Args& compiler_args_,
+ bool hash_actual_cwd_)
: preprocessor_args(preprocessor_args_),
extra_args_to_hash(extra_args_to_hash_),
- compiler_args(compiler_args_)
+ compiler_args(compiler_args_),
+ hash_actual_cwd(hash_actual_cwd_)
{
}
ctx, processed.preprocessor_args, common_hash, ctx.args_info));
}
+ if (processed.hash_actual_cwd) {
+ common_hash.hash_delimiter("actual_cwd");
+ common_hash.hash(ctx.actual_cwd);
+ }
+
// Try to find the hash using the manifest.
Hash direct_hash = common_hash;
init_hash_debug(ctx, direct_hash, 'd', "DIRECT MODE", debug_text_file);
$CCACHE_COMPILE -fprofile-dir=data2 -fprofile-use=data -c test.c
expect_stat direct_cache_hit 1
expect_stat cache_miss 3
+
+ # -------------------------------------------------------------------------
+ TEST "-fprofile-abs-path"
+
+ if $COMPILER -fprofile-abs-path -c test.c 2>/dev/null; then
+ mkdir a b
+
+ cd a
+
+ $CCACHE_COMPILE -fprofile-abs-path -ftest-coverage -c ../test.c
+ expect_stat direct_cache_hit 0
+ expect_stat cache_miss 1
+
+ $CCACHE_COMPILE -fprofile-abs-path -ftest-coverage -c ../test.c
+ expect_stat direct_cache_hit 1
+ expect_stat cache_miss 1
+
+ cd ../b
+
+ $CCACHE_COMPILE -fprofile-abs-path -ftest-coverage -c ../test.c
+ expect_stat direct_cache_hit 1
+ expect_stat cache_miss 2
+
+ $CCACHE_COMPILE -fprofile-abs-path -ftest-coverage -c ../test.c
+ expect_stat direct_cache_hit 2
+ expect_stat cache_miss 2
+
+ export CCACHE_SLOPPINESS="$CCACHE_SLOPPINESS gcno_cwd"
+
+ cd ../a
+
+ $CCACHE_COMPILE -fprofile-abs-path -ftest-coverage -c ../test.c
+ expect_stat direct_cache_hit 2
+ expect_stat cache_miss 3
+
+ $CCACHE_COMPILE -fprofile-abs-path -ftest-coverage -c ../test.c
+ expect_stat direct_cache_hit 3
+ expect_stat cache_miss 3
+
+ cd ../b
+
+ $CCACHE_COMPILE -fprofile-abs-path -ftest-coverage -c ../test.c
+ expect_stat direct_cache_hit 4
+ expect_stat cache_miss 3
+ fi
}