]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Hash information to make results with -MF /dev/null unique (#400)
authorAnders F Björklund <anders.f.bjorklund@gmail.com>
Mon, 29 Apr 2019 18:01:38 +0000 (20:01 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 1 May 2019 12:23:39 +0000 (14:23 +0200)
If we first run with -MF /dev/null, then we will get a
"cache file missing" error on the next run - avoid that.

Make sure to cache the special /dev/null value, so that
it differs from the normal (ignored) dep file name...

src/ccache.c
test/suites/direct.bash

index 4b1aed0e9ca583487c96cbd268d3903a76b96f58..6f9d4b496e6ee1747901744cdff43bbe713b06b2 100644 (file)
@@ -2043,10 +2043,15 @@ calculate_object_hash(struct args *args, struct hash *hash, int direct_mode)
                                hash_delimiter(hash, "arg");
                                hash_string_buffer(hash, args->argv[i], 3);
 
-                               bool separate_argument = (strlen(args->argv[i]) == 3);
-                               if (separate_argument) {
-                                       // Next argument is dependency name, so skip it.
-                                       i++;
+                               if (!str_eq(output_dep, "/dev/null")) {
+                                       bool separate_argument = (strlen(args->argv[i]) == 3);
+                                       if (separate_argument) {
+                                               // Next argument is dependency name, so skip it.
+                                               i++;
+                                       }
+                               } else {
+                                       // Hash that we don't have a .d file.
+                                       hash_string(hash, output_dep);
                                }
                                continue;
                        }
index f721e7589d4c6f908dff876c650b6724c778633b..137304433119b1a88ecc1d483a0828b086c3bc21 100644 (file)
@@ -453,6 +453,22 @@ EOF
     expect_stat 'cache miss' 1
     expect_stat 'files in cache' 2
 
+    $CCACHE_COMPILE -c -MD -MF test.d test.c
+    expect_stat 'cache hit (direct)' 1
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 2
+    expect_stat 'files in cache' 5
+    expect_equal_files test.d expected.d
+
+    rm -f test.d
+
+    $CCACHE_COMPILE -c -MD -MF test.d test.c
+    expect_stat 'cache hit (direct)' 2
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 2
+    expect_stat 'files in cache' 5
+    expect_equal_files test.d expected.d
+
     # -------------------------------------------------------------------------
     TEST "Missing .d file"