return false;
}
- // - Don't store stderr outputs as raw files since they:
- // 1. Never are large.
- // 2. Will end up in a temporary file anyway.
+ // Only store object files as raw files since there are several problems with
+ // storing other file types:
//
- // - Don't store .d/dependency files since they:
- // 1. Never are large.
- // 2. Compress well.
- // 3. Cause trouble for automake if hard-linked (see ccache issue 378).
+ // 1. The compiler unlinks object files before writing to them but it doesn't
+ // unlink .d files, so just it's possible to corrupt .d files just by
+ // running the compiler (see ccache issue 599).
+ // 2. .d files cause trouble for automake if hard-linked (see ccache issue
+ // 378).
+ // 3. It's unknown how the compiler treats other file types, so better safe
+ // than sorry.
//
- // Note that .d files can't be stored as raw files for the file_clone case
- // since the hard link mode happily will try to use them if they exist. This
- // could be fixed by letting read_raw_file_entry refuse to hard link .d
- // files, but it's easier to simply always store them embedded. This will
- // also save i-nodes in the cache.
- return type != FileType::stderr_output && type != FileType::dependency;
+ // It would be possible to store all files in raw form for the file_clone case
+ // and only hard link object files. However, most likely it's only object
+ // files that become large enough that it's of interest to clone or hard link
+ // them, so we keep things simple for now. This will also save i-nodes in the
+ // cache.
+ return type == FileType::object;
}
static void
CCACHE_HARDLINK=1 CCACHE_DEPEND=1 $CCACHE_COMPILE -c -MMD -MF test1.d.tmp test1.c
expect_stat 'cache hit (direct)' 1
mv test1.d.tmp test1.d || test_failed "second mv failed"
+
+ # -------------------------------------------------------------------------
+ TEST ".d file corrupted by compiler"
+
+ unset CCACHE_NODIRECT
+ export CCACHE_SLOPPINESS=include_file_mtime,include_file_ctime
+ export CCACHE_HARDLINK=1
+
+ echo "int x;" >test1.c
+
+ $CCACHE_COMPILE -c -MMD test1.c
+ expect_stat 'cache hit (direct)' 0
+ expect_stat 'cache miss' 1
+ expect_file_content test1.d "test1.o: test1.c"
+
+ touch test1.h
+ echo '#include "test1.h"' >>test1.c
+
+ $CCACHE_COMPILE -c -MMD test1.c
+ expect_stat 'cache hit (direct)' 0
+ expect_stat 'cache miss' 2
+ expect_file_content test1.d "test1.o: test1.c test1.h"
+
+ echo "int x;" >test1.c
+
+ $CCACHE_COMPILE -c -MMD test1.c
+ expect_stat 'cache hit (direct)' 1
+ expect_stat 'cache miss' 2
+ expect_file_content test1.d "test1.o: test1.c"
}