]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Also store preprocessor standard error output in .stderr file
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 12 Dec 2009 20:43:46 +0000 (21:43 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 5 Jan 2010 17:53:03 +0000 (18:53 +0100)
This is needed because we don't run the preprocessor at all in direct mode.

ccache.c
test.sh

index 9558ea2c50db9eb6ebc2a9942228f81b24404b6e..7a94571aedb7b92d8e982ba369d1789766668652 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -450,6 +450,39 @@ static void to_cache(ARGS *args)
        }
        unlink(tmp_stdout);
 
+       /*
+        * Merge stderr from the preprocessor (if any) and stderr from the real
+        * compiler into tmp_stderr.
+        */
+       if (cpp_stderr) {
+               int fd_cpp_stderr;
+               int fd_real_stderr;
+               int fd_result;
+
+               fd_cpp_stderr = open(cpp_stderr, O_RDONLY | O_BINARY);
+               if (fd_cpp_stderr == -1) {
+                       failed();
+               }
+               fd_real_stderr = open(tmp_stderr, O_RDONLY | O_BINARY);
+               if (fd_real_stderr == -1) {
+                       failed();
+               }
+               unlink(tmp_stderr);
+               fd_result = open(tmp_stderr,
+                                O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
+                                0666);
+               if (fd_result == -1) {
+                       failed();
+               }
+               copy_fd(fd_cpp_stderr, fd_result);
+               copy_fd(fd_real_stderr, fd_result);
+               close(fd_cpp_stderr);
+               close(fd_real_stderr);
+               close(fd_result);
+               unlink(cpp_stderr);
+               free(cpp_stderr);
+       }
+
        if (status != 0) {
                int fd;
                cc_log("Compile of %s gave status = %d\n", output_file, status);
@@ -460,17 +493,6 @@ static void to_cache(ARGS *args)
                        if (strcmp(output_file, "/dev/null") == 0
                            || move_file(tmp_hashname, output_file, 0) == 0
                            || errno == ENOENT) {
-                               if (cpp_stderr) {
-                                       /* we might have some stderr from cpp */
-                                       int fd2 = open(cpp_stderr, O_RDONLY | O_BINARY);
-                                       if (fd2 != -1) {
-                                               copy_fd(fd2, 2);
-                                               close(fd2);
-                                               unlink(cpp_stderr);
-                                               cpp_stderr = NULL;
-                                       }
-                               }
-
                                /* we can use a quick method of
                                   getting the failed output */
                                copy_fd(fd, 2);
@@ -789,7 +811,7 @@ static int find_hash(ARGS *args, enum findhash_call_mode mode)
    otherwise it returns */
 static void from_cache(enum fromcache_call_mode mode, int put_object_in_manifest)
 {
-       int fd_stderr, fd_cpp_stderr;
+       int fd_stderr;
        char *stderr_file;
        char *dep_file;
        int ret;
@@ -934,18 +956,7 @@ static void from_cache(enum fromcache_call_mode mode, int put_object_in_manifest
                i_tmpfile = NULL;
        }
 
-       /* send the cpp stderr, if applicable */
-       if (cpp_stderr) {
-               fd_cpp_stderr = open(cpp_stderr, O_RDONLY | O_BINARY);
-               if (fd_cpp_stderr != -1) {
-                       copy_fd(fd_cpp_stderr, 2);
-                       close(fd_cpp_stderr);
-                       unlink(cpp_stderr);
-               }
-               free(cpp_stderr);
-       }
-
-       /* send the stderr */
+       /* Send the stderr, if any. */
        fd_stderr = open(stderr_file, O_RDONLY | O_BINARY);
        if (fd_stderr != -1) {
                copy_fd(fd_stderr, 2);
diff --git a/test.sh b/test.sh
index c18526e590d1c023c7671578a6eecd36921fb7b4..ce48caf0e9b73630e8cd63a6942ee1c7610dc2c2 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -56,7 +56,7 @@ checkfile() {
         test_failed "$1 not found"
     fi
     if [ "`cat $1`" != "$2" ]; then
-        test_failed "Bad content of $2.\nExpected: $2\nActual: `cat $1`"
+        test_failed "Bad content of $1.\nExpected: $2\nActual: `cat $1`"
     fi
 }
 
@@ -572,6 +572,38 @@ EOF
     checkstat 'cache miss' 1
     checkfile other.d "test.o: test.c test1.h test3.h test2.h"
 
+    ##################################################################
+    # Check that stderr from both the preprocessor and the compiler is emitted
+    # in direct mode too.
+    testname="cpp stderr"
+    $CCACHE -z >/dev/null
+    $CCACHE -C >/dev/null
+cat <<EOF >cpp-warning.c
+#if FOO
+/* Trigger preprocessor warning about extra token after #endif. */
+#endif FOO
+int stderr(void)
+{
+       /* Trigger compiler warning by having no return statement. */
+}
+EOF
+    $CCACHE $COMPILER -Wall -W -c cpp-warning.c 2>stderr-orig.txt
+    checkstat 'cache hit (direct)' 0
+    checkstat 'cache hit (preprocessed)' 0
+    checkstat 'cache miss' 1
+
+    CCACHE_NODIRECT=1 $CCACHE $COMPILER -Wall -W -c cpp-warning.c 2>stderr-cpp.txt
+    checkstat 'cache hit (direct)' 0
+    checkstat 'cache hit (preprocessed)' 1
+    checkstat 'cache miss' 1
+    checkfile stderr-cpp.txt "`cat stderr-orig.txt`"
+
+    $CCACHE $COMPILER -Wall -W -c cpp-warning.c 2>stderr-mf.txt
+    checkstat 'cache hit (direct)' 1
+    checkstat 'cache hit (preprocessed)' 1
+    checkstat 'cache miss' 1
+    checkfile stderr-mf.txt "`cat stderr-orig.txt`"
+
     ##################################################################
     # Reset things.
     CCACHE_NODIRECT=1