]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Don't add additional depend mode options after Clang -- option
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 17 Apr 2023 18:51:38 +0000 (20:51 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 17 Apr 2023 19:27:01 +0000 (21:27 +0200)
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.

src/ccache.cpp
test/suites/depend.bash

index 9547f538c49377c000d928459f2bc403a1f9eede..71ea532e090fa0f59558db63a8d16b84614083d1 100644 (file)
@@ -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();
index 03a14af68d68a6423167009d9fde1b4d935078c8..37cff1309cf119b05183e1a41927326ea4206dd5 100644 (file)
@@ -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
 }