find_compiler(Context& ctx,
const FindExecutableFunction& find_executable_function)
{
- const nonstd::string_view first_param_base_name =
- Util::base_name(ctx.orig_args[0]);
- const bool first_param_is_ccache =
- Util::same_program_name(first_param_base_name, CCACHE_NAME);
+ // gcc --> 0
+ // ccache gcc --> 1
+ // ccache ccache gcc --> 2
+ size_t compiler_pos = 0;
+ while (compiler_pos < ctx.orig_args.size()
+ && Util::same_program_name(
+ Util::base_name(ctx.orig_args[compiler_pos]), CCACHE_NAME)) {
+ compiler_pos++;
+ }
// Support user override of the compiler.
const std::string compiler =
!ctx.config.compiler().empty()
? ctx.config.compiler()
- : (first_param_is_ccache ? ctx.orig_args[1]
- // ccache is masquerading as compiler:
- : std::string(first_param_base_name));
+ // In case ccache is masquerading as compiler,
+ // use only base_name so the real compiler can be determined.
+ : compiler_pos == 0 ? std::string(Util::base_name(ctx.orig_args[0]))
+ : ctx.orig_args[compiler_pos];
const std::string resolved_compiler =
Util::is_full_path(compiler)
CCACHE_NAME);
}
- if (first_param_is_ccache) {
- ctx.orig_args.pop_front();
- }
+ ctx.orig_args.pop_front(compiler_pos);
ctx.orig_args[0] = resolved_compiler;
}
expect_stat 'files in cache' 1
expect_equal_object_files reference_test1.o test1.o
+ # -------------------------------------------------------------------------
+ TEST "ccache ccache gcc"
+ # e.g. due to some suboptimal setup, scripts etc.
+ # Source: https://github.com/ccache/ccache/issues/686
+
+ $REAL_COMPILER -c -o reference_test1.o test1.c
+
+ $CCACHE $COMPILER -c test1.c
+ expect_stat 'cache hit (preprocessed)' 0
+ expect_stat 'cache miss' 1
+ expect_stat 'files in cache' 1
+ expect_equal_object_files reference_test1.o test1.o
+
+ $CCACHE $CCACHE $COMPILER -c test1.c
+ expect_stat 'cache hit (preprocessed)' 1
+ expect_stat 'cache miss' 1
+ expect_stat 'files in cache' 1
+ expect_equal_object_files reference_test1.o test1.o
+
+ $CCACHE $CCACHE $CCACHE $COMPILER -c test1.c
+ expect_stat 'cache hit (preprocessed)' 2
+ expect_stat 'cache miss' 1
+ expect_stat 'files in cache' 1
+ expect_equal_object_files reference_test1.o test1.o
+
# -------------------------------------------------------------------------
TEST "Version output readable"
CHECK(helper("/abs/" CCACHE_NAME " /abs/gcc", "", "") == "/abs/gcc");
}
+ SUBCASE("double ccache")
+ {
+ // e.g. due to some suboptimal setup, scripts etc.
+ // Source: https://github.com/ccache/ccache/issues/686
+ CHECK(helper(CCACHE_NAME " gcc", "") == "resolved_gcc");
+ CHECK(helper(CCACHE_NAME " " CCACHE_NAME " gcc", "") == "resolved_gcc");
+ CHECK(helper(CCACHE_NAME " " CCACHE_NAME " " CCACHE_NAME " gcc", "")
+ == "resolved_gcc");
+ }
+
SUBCASE("config")
{
// In case the first parameter is gcc it must be a link to ccache so use