From: Justin Lebar Date: Tue, 25 Dec 2012 04:09:14 +0000 (-0500) Subject: Check that included files' ctimes aren't too new. X-Git-Tag: v3.2~57 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=290a8b44f8ed1c117fd54000d58f05912066c63c;p=thirdparty%2Fccache.git Check that included files' ctimes aren't too new. ccache currently checks that a file's mtime isn't too new, unless CCACHE_SLOPPINESS includes "include_file_mtime". This patch adds a similar check that a file's ctime isn't too new. We skip this check if CCACHE_SLOPPINESS includes "include_file_ctime". --- diff --git a/MANUAL.txt b/MANUAL.txt index 3a4afdeb3..e7411b407 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -428,6 +428,9 @@ WRAPPERS>>. *include_file_mtime*:: By default, ccache will not cache a file if it includes a header whose mtime is too new. This option disables that check. +*include_file_ctime*:: + ccache also will not cache a file if it includes a header whose ctime is + too new. This option disables that check. *time_macros*:: Ignore *\_\_DATE\__* and *\_\_TIME__* being present in the source code. -- diff --git a/ccache.c b/ccache.c index e0bd25cf6..fd1a49959 100644 --- a/ccache.c +++ b/ccache.c @@ -373,6 +373,12 @@ remember_include_file(char *path, struct mdfour *cpp_hash) goto failure; } + if (!(conf->sloppiness & SLOPPY_INCLUDE_FILE_CTIME) + && st.st_ctime >= time_of_compilation) { + cc_log("Include file %s ctime too new", path); + goto failure; + } + hash_start(&fhash); is_pch = is_precompiled_header(path); diff --git a/ccache.h b/ccache.h index 5bcbf711b..f57a901bd 100644 --- a/ccache.h +++ b/ccache.h @@ -54,8 +54,9 @@ enum stats { }; #define SLOPPY_INCLUDE_FILE_MTIME 1 -#define SLOPPY_FILE_MACRO 2 -#define SLOPPY_TIME_MACROS 4 +#define SLOPPY_INCLUDE_FILE_CTIME 2 +#define SLOPPY_FILE_MACRO 4 +#define SLOPPY_TIME_MACROS 8 #define str_eq(s1, s2) (strcmp((s1), (s2)) == 0) #define str_startswith(s, p) (strncmp((s), (p), strlen((p))) == 0) diff --git a/conf.c b/conf.c index 0f62b86bf..a9d261dc6 100644 --- a/conf.c +++ b/conf.c @@ -92,6 +92,8 @@ parse_sloppiness(const char *str, void *result, char **errmsg) *value |= SLOPPY_FILE_MACRO; } else if (str_eq(word, "include_file_mtime")) { *value |= SLOPPY_INCLUDE_FILE_MTIME; + } else if (str_eq(word, "include_file_ctime")) { + *value |= SLOPPY_INCLUDE_FILE_CTIME; } else if (str_eq(word, "time_macros")) { *value |= SLOPPY_TIME_MACROS; } else { @@ -584,6 +586,9 @@ conf_print_items(struct conf *conf, if (conf->sloppiness & SLOPPY_INCLUDE_FILE_MTIME) { reformat(&s, "%sinclude_file_mtime, ", s); } + if (conf->sloppiness & SLOPPY_INCLUDE_FILE_CTIME) { + reformat(&s, "%sinclude_file_ctime, ", s); + } if (conf->sloppiness & SLOPPY_TIME_MACROS) { reformat(&s, "%stime_macros, ", s); } diff --git a/test.sh b/test.sh index 4209edf84..d2af7e4ca 100755 --- a/test.sh +++ b/test.sh @@ -43,6 +43,11 @@ unset CCACHE_TEMPDIR unset CCACHE_UMASK unset CCACHE_UNIFY +# Many tests backdate files, which updates their ctimes. In those tests, we +# must ignore ctimes. Might as well do so everywhere. +default_sloppiness=include_file_ctime +export CCACHE_SLOPPINESS="$default_sloppiness" + test_failed() { echo "SUITE: \"$testsuite\", TEST: \"$testname\" - $1" $CCACHE -s @@ -1102,15 +1107,15 @@ EOF #define file __FILE__ int test; EOF - CCACHE_SLOPPINESS=file_macro $CCACHE $COMPILER -c file.c + CCACHE_SLOPPINESS="$default_sloppiness file_macro" $CCACHE $COMPILER -c file.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_SLOPPINESS=file_macro $CCACHE $COMPILER -c file.c + CCACHE_SLOPPINESS="$default_sloppiness file_macro" $CCACHE $COMPILER -c file.c checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_SLOPPINESS=file_macro $CCACHE $COMPILER -c `pwd`/file.c + CCACHE_SLOPPINESS="$default_sloppiness file_macro" $CCACHE $COMPILER -c `pwd`/file.c checkstat 'cache hit (direct)' 2 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 @@ -1125,16 +1130,16 @@ EOF cat <file_h.c #include "file.h" EOF - CCACHE_SLOPPINESS=file_macro $CCACHE $COMPILER -c file_h.c + CCACHE_SLOPPINESS="$default_sloppiness file_macro" $CCACHE $COMPILER -c file_h.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_SLOPPINESS=file_macro $CCACHE $COMPILER -c file_h.c + CCACHE_SLOPPINESS="$default_sloppiness file_macro" $CCACHE $COMPILER -c file_h.c checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 mv file_h.c file2_h.c - CCACHE_SLOPPINESS=file_macro $CCACHE $COMPILER -c `pwd`/file2_h.c + CCACHE_SLOPPINESS="$default_sloppiness file_macro" $CCACHE $COMPILER -c `pwd`/file2_h.c checkstat 'cache hit (direct)' 2 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 @@ -1183,11 +1188,11 @@ EOF #define time __TIME__ int test; EOF - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c time.c + CCACHE_SLOPPINESS="$default_sloppiness time_macros" $CCACHE $COMPILER -c time.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c time.c + CCACHE_SLOPPINESS="$default_sloppiness time_macros" $CCACHE $COMPILER -c time.c checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 @@ -1202,11 +1207,11 @@ EOF cat <time_h.c #include "time.h" EOF - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c time_h.c + CCACHE_SLOPPINESS="$default_sloppiness time_macros" $CCACHE $COMPILER -c time_h.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER -c time_h.c + CCACHE_SLOPPINESS="$default_sloppiness time_macros" $CCACHE $COMPILER -c time_h.c checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 @@ -1242,11 +1247,11 @@ EOF int test; EOF touch -t 203801010000 new.h - CCACHE_SLOPPINESS=include_file_mtime $CCACHE $COMPILER -c new.c + CCACHE_SLOPPINESS="$default_sloppiness include_file_mtime" $CCACHE $COMPILER -c new.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_SLOPPINESS=include_file_mtime $CCACHE $COMPILER -c new.c + CCACHE_SLOPPINESS="$default_sloppiness include_file_mtime" $CCACHE $COMPILER -c new.c checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 @@ -1297,7 +1302,7 @@ EOF echo "#line 1 \"/dev/$x\"" >> strange.c fi done - CCACHE_SLOPPINESS=include_file_mtime $CCACHE $COMPILER -c strange.c + CCACHE_SLOPPINESS="$default_sloppiness include_file_mtime" $CCACHE $COMPILER -c strange.c manifest=`find $CCACHE_DIR -name '*.manifest'` if [ -n "$manifest" ]; then data="`$CCACHE --dump-manifest $manifest | egrep '/dev/(stdout|tty|sda|hda'`" @@ -1313,7 +1318,7 @@ EOF $CCACHE $COMPILER test.c -c -o test.o manifest=`find $CCACHE_DIR -name '*.manifest'` $CCACHE --dump-manifest $manifest | - perl -ape 's/:.*/: normalized/ if $F[0] =~ "(Hash|Size):" and ++$n > 6' \ + perl -ape 's/:.*/: normalized/ if ($F[0] =~ "Mtime:") or ($F[0] =~ "(Hash|Size):" and ++$n > 6)' \ >manifest.dump if [ $COMPILER_TYPE_CLANG -eq 1 ]; then cat <expected.dump @@ -1989,11 +1994,11 @@ gcc_pch_suite() { testname="no -fpch-preprocess, -include" $CCACHE -Cz >/dev/null - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null + CCACHE_SLOPPINESS="$default_sloppiness time_macros" $CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null + CCACHE_SLOPPINESS="$default_sloppiness time_macros" $CCACHE $COMPILER $SYSROOT -c -include pch.h pch2.c 2>/dev/null checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 @@ -2008,11 +2013,11 @@ gcc_pch_suite() { testname="-fpch-preprocess, #include, sloppy time macros" $CCACHE -Cz >/dev/null - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -fpch-preprocess pch.c + CCACHE_SLOPPINESS="$default_sloppiness time_macros" $CCACHE $COMPILER $SYSROOT -c -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -fpch-preprocess pch.c + CCACHE_SLOPPINESS="$default_sloppiness time_macros" $CCACHE $COMPILER $SYSROOT -c -fpch-preprocess pch.c checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 @@ -2020,18 +2025,18 @@ gcc_pch_suite() { testname="-fpch-preprocess, #include, file changed" echo "updated" >>pch.h.gch # GCC seems to cope with this... backdate pch.h.gch - CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -fpch-preprocess pch.c + CCACHE_SLOPPINESS="$default_sloppiness time_macros" $CCACHE $COMPILER $SYSROOT -c -fpch-preprocess pch.c checkstat 'cache hit (direct)' 1 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 2 testname="preprocessor mode" $CCACHE -Cz >/dev/null - CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -fpch-preprocess pch.c + CCACHE_NODIRECT=1 CCACHE_SLOPPINESS="$default_sloppiness time_macros" $CCACHE $COMPILER $SYSROOT -c -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 0 checkstat 'cache miss' 1 - CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -fpch-preprocess pch.c + CCACHE_NODIRECT=1 CCACHE_SLOPPINESS="$default_sloppiness time_macros" $CCACHE $COMPILER $SYSROOT -c -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 1 checkstat 'cache miss' 1 @@ -2039,11 +2044,11 @@ gcc_pch_suite() { testname="preprocessor mode, file changed" echo "updated" >>pch.h.gch # GCC seems to cope with this... backdate pch.h.gch - CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -fpch-preprocess pch.c + CCACHE_NODIRECT=1 CCACHE_SLOPPINESS="$default_sloppiness time_macros" $CCACHE $COMPILER $SYSROOT -c -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 1 checkstat 'cache miss' 2 - CCACHE_NODIRECT=1 CCACHE_SLOPPINESS=time_macros $CCACHE $COMPILER $SYSROOT -c -fpch-preprocess pch.c + CCACHE_NODIRECT=1 CCACHE_SLOPPINESS="$default_sloppiness time_macros" $CCACHE $COMPILER $SYSROOT -c -fpch-preprocess pch.c checkstat 'cache hit (direct)' 0 checkstat 'cache hit (preprocessed)' 2 checkstat 'cache miss' 2 diff --git a/test/test_conf.c b/test/test_conf.c index 3e933814c..048264fc9 100644 --- a/test/test_conf.c +++ b/test/test_conf.c @@ -143,7 +143,8 @@ TEST(conf_read_valid_config) CHECK(conf->read_only); CHECK(conf->recache); CHECK(conf->run_second_cpp); - CHECK_INT_EQ(SLOPPY_INCLUDE_FILE_MTIME|SLOPPY_FILE_MACRO|SLOPPY_TIME_MACROS, + CHECK_INT_EQ(SLOPPY_INCLUDE_FILE_MTIME|SLOPPY_INCLUDE_FILE_CTIME| + SLOPPY_FILE_MACRO|SLOPPY_TIME_MACROS, conf->sloppiness); CHECK(!conf->stats); CHECK_STR_EQ_FREE1(format("%s_foo", user), conf->temporary_dir); @@ -359,7 +360,8 @@ TEST(conf_print_items) true, true, true, - SLOPPY_FILE_MACRO|SLOPPY_INCLUDE_FILE_MTIME|SLOPPY_TIME_MACROS, + SLOPPY_FILE_MACRO|SLOPPY_INCLUDE_FILE_MTIME| + SLOPPY_INCLUDE_FILE_CTIME|SLOPPY_TIME_MACROS, false, "td", 022,