diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2023-04-17 20:51:38 +0200 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2023-04-17 21:27:01 +0200 |
commit | e58da98645dded3b87b4ffa9b206f9d1fdce53d7 (patch) | |
tree | 9faca2b98e8e511f0d41b51c1606c4763bab5e90 | |
parent | cfc9b99c8070df1aabad167ac7bae4e0a0ce92bc (diff) | |
download | ccache-e58da98645dded3b87b4ffa9b206f9d1fdce53d7.tar.gz |
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.
-rw-r--r-- | src/ccache.cpp | 4 | ||||
-rw-r--r-- | test/suites/depend.bash | 13 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/ccache.cpp b/src/ccache.cpp index 9547f538..71ea532e 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 03a14af6..37cff130 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 } |