From: Joel Rosdahl Date: Mon, 17 Apr 2023 18:51:38 +0000 (+0200) Subject: fix: Don't add additional depend mode options after Clang -- option X-Git-Tag: v4.8.1~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e58da98645dded3b87b4ffa9b206f9d1fdce53d7;p=thirdparty%2Fccache.git fix: Don't add additional depend mode options after Clang -- option With the depend mode enabled, ccache executes the original command line verbatim, potentially with the addition of a few extra options. However, for clang or clang-cl it is not possible to simply append the additional options to the end of the original command line since there may be a "--" option to indicate the end of options. Fix this by inserting the additional options directly after the compiler instead of at the end. Fixes #1273. --- diff --git a/src/ccache.cpp b/src/ccache.cpp index 9547f538c..71ea532e0 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -1103,7 +1103,9 @@ to_cache(Context& ctx, // mode. Args depend_mode_args = ctx.orig_args; depend_mode_args.erase_with_prefix("--ccache-"); - depend_mode_args.push_back(depend_extra_args); + // Add depend_mode_args directly after the compiler. We can't add them last + // since options then may be placed after a "--" option. + depend_mode_args.insert(1, depend_extra_args); add_prefix(ctx, depend_mode_args, ctx.config.prefix_command()); ctx.time_of_compilation = util::TimePoint::now(); diff --git a/test/suites/depend.bash b/test/suites/depend.bash index 03a14af68..37cff1309 100644 --- a/test/suites/depend.bash +++ b/test/suites/depend.bash @@ -357,4 +357,17 @@ EOF expect_stat preprocessed_cache_hit 0 expect_stat cache_miss 1 expect_equal_content 'file with$special#characters.d' reference.d + + # ------------------------------------------------------------------------- + if touch empty.c && $COMPILER -c -- empty.c 2>/dev/null; then + TEST "--" + + $CCACHE_COMPILE -c -- test.c + expect_stat direct_cache_hit 0 + expect_stat cache_miss 1 + + $CCACHE_COMPILE -c -- test.c + expect_stat direct_cache_hit 1 + expect_stat cache_miss 1 + fi }