]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Support using -MF /dev/null argument (#398)
authorAnders Björklund <anders.f.bjorklund@gmail.com>
Sun, 28 Apr 2019 20:50:03 +0000 (22:50 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 28 Apr 2019 20:50:03 +0000 (22:50 +0200)
This is sometimes used when detecting capabilities.

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

index cb8b3a721544984fab1d2849ca4b2180ec7c7cdd..4b1aed0e9ca583487c96cbd268d3903a76b96f58 100644 (file)
@@ -1519,7 +1519,10 @@ to_cache(struct args *args, struct hash *depend_mode_hash)
                update_cached_result_globals(object_hash);
        }
 
-       if (generating_dependencies) {
+       bool produce_dep_file = generating_dependencies &&
+                               !str_eq(output_dep, "/dev/null");
+
+       if (produce_dep_file) {
                use_relative_paths_in_depfile(output_dep);
        }
 
@@ -1555,7 +1558,7 @@ to_cache(struct args *args, struct hash *depend_mode_hash)
        MTR_BEGIN("file", "file_put");
 
        copy_file_to_cache(output_obj, cached_obj);
-       if (generating_dependencies) {
+       if (produce_dep_file) {
                copy_file_to_cache(output_dep, cached_dep);
        }
        if (generating_coverage) {
@@ -2220,7 +2223,10 @@ calculate_object_hash(struct args *args, struct hash *hash, int direct_mode)
                        args_pop(args, 1);
                }
                if (generating_dependencies) {
-                       cc_log("Preprocessor created %s", output_dep);
+                       // Nothing is actually created with -MF /dev/null
+                       if (!str_eq(output_dep, "/dev/null")) {
+                               cc_log("Preprocessor created %s", output_dep);
+                       }
                }
        }
 
@@ -2268,7 +2274,8 @@ from_cache(enum fromcache_call_mode mode, bool put_object_in_manifest)
 
        // (If mode != FROMCACHE_DIRECT_MODE, the dependency file is created by gcc.)
        bool produce_dep_file =
-               generating_dependencies && mode == FROMCACHE_DIRECT_MODE;
+               generating_dependencies && mode == FROMCACHE_DIRECT_MODE &&
+               !str_eq(output_dep, "/dev/null");
 
        MTR_BEGIN("file", "file_get");
 
@@ -3837,7 +3844,8 @@ ccache(int argc, char *argv[])
        MTR_END("main", "process_args");
 
        if (conf->depend_mode
-           && (!generating_dependencies || !conf->run_second_cpp || conf->unify)) {
+           && (!generating_dependencies || str_eq(output_dep, "/dev/null") ||
+               !conf->run_second_cpp || conf->unify)) {
                cc_log("Disabling depend mode");
                conf->depend_mode = false;
        }
index 3d2f2adc1ce41b83988a063f8a041311eae875b9..a13f84260d41a10c2ac23380d1a14fedc49a3627 100644 (file)
@@ -108,6 +108,21 @@ SUITE_depend() {
     expect_stat 'cache miss' 1
     expect_stat 'files in cache' 3
 
+    # -------------------------------------------------------------------------
+    TEST "No dependency file"
+
+    CCACHE_DEPEND=1 $CCACHE_COMPILE -MP -MMD -MF /dev/null -c test.c
+    expect_stat 'cache hit (direct)' 0
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
+    expect_stat 'files in cache' 2 # .o + .manifest
+
+    CCACHE_DEPEND=1 $CCACHE_COMPILE -MP -MMD -MF /dev/null -c test.c
+    expect_stat 'cache hit (direct)' 1
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
+    expect_stat 'files in cache' 2
+
     # -------------------------------------------------------------------------
     TEST "No explicit dependency file"
 
index 643471c1885c0724d021628b7f9567891d77c6bb..f721e7589d4c6f908dff876c650b6724c778633b 100644 (file)
@@ -438,6 +438,21 @@ EOF
 
     rm -f third_name.d
 
+    # -------------------------------------------------------------------------
+    TEST "MF /dev/null"
+
+    $CCACHE_COMPILE -c -MD -MF /dev/null test.c
+    expect_stat 'cache hit (direct)' 0
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
+    expect_stat 'files in cache' 2 # .o + .manifest
+
+    $CCACHE_COMPILE -c -MD -MF /dev/null test.c
+    expect_stat 'cache hit (direct)' 1
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
+    expect_stat 'files in cache' 2
+
     # -------------------------------------------------------------------------
     TEST "Missing .d file"