}
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);
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);
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;
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);
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
}
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