]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Check that included files' ctimes aren't too new.
authorJustin Lebar <justin.lebar@gmail.com>
Tue, 25 Dec 2012 04:09:14 +0000 (23:09 -0500)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 2 Mar 2013 19:45:32 +0000 (20:45 +0100)
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".

MANUAL.txt
ccache.c
ccache.h
conf.c
test.sh
test/test_conf.c

index 3a4afdeb3dbacebe213b45421c0bd9d86b74a355..e7411b407d9024dfeed92811244d8a5388fd9670 100644 (file)
@@ -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.
 --
index e0bd25cf641703d5d737b8bc64e0e05196d978c2..fd1a4995929a71feffb6f003024786564b656c4f 100644 (file)
--- 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);
index 5bcbf711b29d5934838c156b8d369ab661bd36b5..f57a901bd9b611cf640fd5eff8d7896d260185c6 100644 (file)
--- 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 0f62b86bf2b15c1c0474c325ee78da9d75c55860..a9d261dc670860d7d0d06d9395640cf674e954f2 100644 (file)
--- 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 4209edf846206afc54d6f819663da093f45da36c..d2af7e4ca448705414385f96bc538ec4b23dafc0 100755 (executable)
--- 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 <<EOF >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 <<EOF >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 <<EOF >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
index 3e933814c8c3a8eebc9d3f77dc3d8987ff7a4988..048264fc91dd2ca1eb83c8e429e4771e36b52d4f 100644 (file)
@@ -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,