]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Handle -frecord-gcc-switches correctly
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 23 Feb 2021 20:11:58 +0000 (21:11 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 23 Feb 2021 20:35:12 +0000 (21:35 +0100)
-frecord-gcc-switches records the full command line in the object file,
so include the original command line in the hash as suggested by
Lawrence Chan.

Fixes #804.

src/argprocessing.cpp
src/compopt.cpp
test/suites/base.bash

index 54cdc073f61554569499d061934f2fb1d35990f7..3dd0358a5ffd861803bd6ebb5130c551ccf1f7d7 100644 (file)
@@ -84,6 +84,9 @@ struct ArgumentProcessingState
   // the compiler, not the preprocessor, and that also should not be part of the
   // hash identifying the result.
   Args compiler_only_args_no_hash;
+
+  // Whether to include the full command line in the hash.
+  bool hash_full_command_line = false;
 };
 
 bool
@@ -762,6 +765,10 @@ process_arg(Context& ctx,
     return nullopt;
   }
 
+  if (args[i] == "-frecord-gcc-switches") {
+    state.hash_full_command_line = true;
+  }
+
   // Options taking an argument that we may want to rewrite to relative paths to
   // get better hit rate. A secondary effect is that paths in the standard error
   // output produced by the compiler will be normalized.
@@ -1228,6 +1235,9 @@ process_args(Context& ctx)
   if (config.run_second_cpp()) {
     extra_args_to_hash.push_back(state.dep_args);
   }
+  if (state.hash_full_command_line) {
+    extra_args_to_hash.push_back(ctx.orig_args);
+  }
 
   if (diagnostics_color_arg) {
     compiler_args.push_back(*diagnostics_color_arg);
index 1931d5f442be66e56b811b1c3c8ea30fbf898b62..1e17699a092446551e99541bee583d00f9df5715 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2010-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
index 2ed268642faff3321a025ef32e4d282195501fc4..e685f29b57999aa58f7fb3d1b1bfb6434cde3b34 100644 (file)
@@ -752,6 +752,27 @@ b"
     expect_stat 'cache hit (preprocessed)' 2
     expect_stat 'cache miss' 2
 
+    # -------------------------------------------------------------------------
+    TEST "-frecord-gcc-switches"
+
+    if $REAL_COMPILER -frecord-gcc-switches -c test1.c >&/dev/null; then
+        $CCACHE_COMPILE -frecord-gcc-switches -c test1.c
+        expect_stat 'cache hit (preprocessed)' 0
+        expect_stat 'cache miss' 1
+
+        $CCACHE_COMPILE -frecord-gcc-switches -c test1.c
+        expect_stat 'cache hit (preprocessed)' 1
+        expect_stat 'cache miss' 1
+
+        $CCACHE_COMPILE -frecord-gcc-switches -Wall -c test1.c
+        expect_stat 'cache hit (preprocessed)' 1
+        expect_stat 'cache miss' 2
+
+        $CCACHE_COMPILE -frecord-gcc-switches -Wall -c test1.c
+        expect_stat 'cache hit (preprocessed)' 2
+        expect_stat 'cache miss' 2
+    fi
+
     # -------------------------------------------------------------------------
     TEST "CCACHE_COMPILER"