From: Joel Rosdahl Date: Fri, 10 Jun 2022 14:12:27 +0000 (+0200) Subject: feat: Set CCACHE_DISABLE when calling compiler X-Git-Tag: v4.7~190 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5b4fd92cdda6a39fb17e35ef25b85e7e156e25ab;p=thirdparty%2Fccache.git feat: Set CCACHE_DISABLE when calling compiler If ccache for some reason executes a compiler that in turn calls ccache then ccache will be run twice (and will potentially store two different result in the cache since the compiler identications differ), which is not very useful. This could for instance happen if the compiler is a wrapper script that in turn calls "ccache $compiler ...". Improve this by setting CCACHE_DISABLE when executing the compiler. Any subsequent ccache invocations will then fall back to running the real compiler. --- diff --git a/src/ccache.cpp b/src/ccache.cpp index f17631355..630513818 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -2165,6 +2165,12 @@ do_cache_compilation(Context& ctx, const char* const* argv) LOG("Compiler type: {}", compiler_type_to_string(ctx.config.compiler_type())); + // Set CCACHE_DISABLE so no process ccache executes from now on will risk + // calling ccache second time. For instance, if the real compiler is a wrapper + // script that calls "ccache $compiler ..." we want that inner ccache call to + // be disabled. + Util::setenv("CCACHE_DISABLE", "1"); + MTR_BEGIN("main", "process_args"); ProcessArgsResult processed = process_args(ctx); MTR_END("main", "process_args"); diff --git a/test/suites/base.bash b/test/suites/base.bash index 89cddf3e8..754649d1c 100644 --- a/test/suites/base.bash +++ b/test/suites/base.bash @@ -788,6 +788,21 @@ b" expect_stat cache_miss 2 fi + # ------------------------------------------------------------------------- + TEST "CCACHE_DISABLE set when executing compiler" + + cat >compiler.sh <>CCACHE_DISABLE.value +exec $COMPILER "\$@" +EOF + chmod +x compiler.sh + backdate compiler.sh + $CCACHE ./compiler.sh -c test1.c + expect_stat preprocessed_cache_hit 0 + expect_stat cache_miss 1 + expect_content CCACHE_DISABLE.value '11' # preprocessor + compiler + # ------------------------------------------------------------------------- TEST "CCACHE_COMPILER" @@ -867,8 +882,6 @@ EOF cat >compiler.sh <compiler.sh <compiler.sh <compiler.sh <compiler.sh <compiler.sh <&2 printf "cc_out|" fi -CCACHE_DISABLE=1 # If $COMPILER happens to be a ccache symlink... -export CCACHE_DISABLE exec $COMPILER "\$@" EOF chmod +x compiler.sh @@ -1450,8 +1451,6 @@ EOF cat >buggy-cpp </dev/null; then $COMPILER "\$@" else