]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Don't delete the clang diagnostics file after compiler failures
authorryb <ryb@ableton.com>
Sat, 7 Feb 2015 14:01:34 +0000 (15:01 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 9 Feb 2015 20:32:04 +0000 (21:32 +0100)
move_file() returns an error when called with the same source and destination,
causing the diagnostics file to be removed.

As of 18a645451 ("Create destination file and then copy into cache instead of
the opposite") it is no longer necessary to move the diagnostics file at all
after a compiler failure.

ccache.c
test.sh

index 913e65640f770f0e1c31a07987bc71210f474555..581d59c410c0cd57cee4d40f04863c94f65d45d3 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -841,29 +841,6 @@ to_cache(struct args *args)
                        close(fd);
                        tmp_unlink(tmp_stderr);
 
-                       if (output_dia) {
-                               int ret;
-                               x_unlink(output_dia);
-                               /* only make a hardlink if the cache file is uncompressed */
-                               ret = move_file(output_dia, output_dia, 0);
-
-                               if (ret == -1) {
-                                       if (errno == ENOENT) {
-                                               /* Someone removed the file just before we began copying? */
-                                               cc_log("Diagnostic file %s just disappeared", output_dia);
-                                               stats_update(STATS_MISSING);
-                                       } else {
-                                               cc_log("Failed to move %s to %s: %s",
-                                                      output_dia, output_dia, strerror(errno));
-                                               stats_update(STATS_ERROR);
-                                               failed();
-                                       }
-                                       x_unlink(output_dia);
-                               } else {
-                                       cc_log("Created %s from %s", output_dia, output_dia);
-                               }
-                       }
-
                        exit(status);
                }
 
diff --git a/test.sh b/test.sh
index 0fde54526fd313d3167bbc04c6f68d194b4a81f3..cfeb97aba3c976ae0dda505af1c510c5a7a153a0 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -632,16 +632,45 @@ EOF
     ##################################################################
 
     if [ $COMPILER_TYPE_CLANG -eq 1 ]; then
-        $CCACHE -Cz > /dev/null
         testname="serialize-diagnostics"
-        $CCACHE_COMPILE -c --serialize-diagnostics test.dia test1.c 2> /dev/null
+        $CCACHE -Cz > /dev/null
+        $COMPILER -c --serialize-diagnostics expected.dia test1.c 2> /dev/null
+        # Run with CCACHE_CPP2 to ensure the same diagnostics output as above
+        CCACHE_CPP2=1 $CCACHE_COMPILE -c --serialize-diagnostics test.dia test1.c 2> /dev/null
         checkstat 'cache hit (preprocessed)' 0
         checkstat 'cache miss' 1
         checkstat 'files in cache' 2
-        $CCACHE_COMPILE -c --serialize-diagnostics test.dia test1.c 2> /dev/null
+        compare_file expected.dia test.dia
+        rm -f test.dia
+        CCACHE_CPP2=1 $CCACHE_COMPILE -c --serialize-diagnostics test.dia test1.c 2> /dev/null
         checkstat 'cache hit (preprocessed)' 1
         checkstat 'cache miss' 1
         checkstat 'files in cache' 2
+        compare_file expected.dia test.dia
+
+        rm -f test.dia
+        rm -f expected.dia
+
+        testname="serialize-diagnostics-compile-failed"
+        $CCACHE -Cz > /dev/null
+        echo "bad source" >error.c
+        $COMPILER -c --serialize-diagnostics expected.dia error.c 2> /dev/null
+        if [ $? -eq 0 ]; then
+            test_failed "expected an error compiling error.c"
+        fi
+        CCACHE_CPP2=1 $CCACHE_COMPILE -c --serialize-diagnostics test.dia error.c 2> /dev/null
+        checkstat 'compile failed' 1
+        checkstat 'cache hit (preprocessed)' 0
+        checkstat 'cache miss' 0
+        checkstat 'files in cache' 0
+        compare_file expected.dia test.dia
+        rm -f test.dia
+        CCACHE_CPP2=1 $CCACHE_COMPILE -c --serialize-diagnostics test.dia error.c 2> /dev/null
+        checkstat 'compile failed' 2
+        checkstat 'cache hit (preprocessed)' 0
+        checkstat 'cache miss' 0
+        checkstat 'files in cache' 0
+        compare_file expected.dia test.dia
     fi
 
     ##################################################################