]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Add CCACHE_EXTRAFILES feature
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 28 Apr 2010 20:30:55 +0000 (22:30 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 28 Apr 2010 20:30:55 +0000 (22:30 +0200)
NEWS.txt
ccache.c
ccache.h
manual.txt
stats.c
test.sh

index e5b3f166cb70b684723d55a5471d7c9ded3faaa9..a874424c50fddf6843a396ab6586e21db41d248c 100644 (file)
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -65,6 +65,9 @@ New features and improvements
       hash anything), mtime (hash the compiler's mtime and size) and content
       (hash the content of the compiler binary). The default is mtime.
 
+    - It is now possible to specify extra files whose contents should be
+      included in the hash sum by setting the `CCACHE_EXTRAFILES` option.
+
     - Temporary files are now created in the directory they will end up in.
       This makes ccache more friendly to Linux's directory layout.
 
index 1cd4cec70087df7bc28973f123fd3c150cb69ba8..53fc0b6679a1ef3b31e7c98d9c1a96e8d29017ff 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -761,6 +761,7 @@ static void calculate_common_hash(ARGS *args, struct mdfour *hash)
 {
        struct stat st;
        const char *compilercheck;
+       char *p;
 
        hash_string(hash, HASH_PREFIX);
        hash_delimiter(hash);
@@ -820,6 +821,23 @@ static void calculate_common_hash(ARGS *args, struct mdfour *hash)
                }
        }
        hash_delimiter(hash);
+
+       p = getenv("CCACHE_EXTRAFILES");
+       if (p) {
+               char *path, *q;
+               p = x_strdup(p);
+               q = p;
+               while ((path = strtok(q, " \t\r\n"))) {
+                       cc_log("Hashing extra file %s", path);
+                       if (!hash_file(hash, path)) {
+                               stats_update(STATS_BADEXTRAFILE);
+                               failed();
+                       }
+                       hash_delimiter(hash);
+                       q = NULL;
+               }
+               free(p);
+       }
 }
 
 /*
index 02d874247ac891e6f6051ac6a79271e002cf47fa..2902bd9c75ed00e05b7e2d1050d95ce418963d83 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -49,6 +49,7 @@ enum stats {
        STATS_CACHEHIT_DIR,
        STATS_NOOUTPUT,
        STATS_EMPTYOUTPUT,
+       STATS_BADEXTRAFILE,
 
        STATS_END
 };
index d4386cf0145a7dad7fcf214607317edf561a4bab..98549e84936fdb36763489c8baef873d73c5989d 100644 (file)
@@ -213,6 +213,12 @@ cases you won't need any of these as the defaults will be fine.
     *CCACHE_EXTENSION* option to override the default. On HP-UX set this
     environment variable to *i* if you use the ``aCC'' compiler.
 
+*CCACHE_EXTRAFILES*::
+
+    If you set the environment variable *CCACHE_EXTRAFILES* to a
+    space-separated list of paths then ccache will include the contents of
+    those files when calculating the hash sum.
+
 *CCACHE_HARDLINK*::
 
     If you set the environment variable *CCACHE_HARDLINK* then ccache will
diff --git a/stats.c b/stats.c
index 4d4ebab1bd990ae281b46db7ba4411b6b0bdb4a8..d0953ca01fadae66d72747caeb1706883c7b26ae 100644 (file)
--- a/stats.c
+++ b/stats.c
@@ -72,6 +72,7 @@ static struct {
        { STATS_OUTSTDOUT,    "output to stdout               ", NULL, 0 },
        { STATS_DEVICE,       "output to a non-regular file   ", NULL, 0 },
        { STATS_NOINPUT,      "no input file                  ", NULL, 0 },
+       { STATS_BADEXTRAFILE, "error hashing extra file       ", NULL, 0 },
        { STATS_NUMFILES,     "files in cache                 ", NULL, FLAG_NOZERO|FLAG_ALWAYS },
        { STATS_TOTALSIZE,    "cache size                     ", display_size , FLAG_NOZERO|FLAG_ALWAYS },
        { STATS_MAXFILES,     "max files                      ", NULL, FLAG_NOZERO },
diff --git a/test.sh b/test.sh
index b4ac87914cabe7c2bdb0378f31fb47428a392722..10baa2e6d60bbf700586017b543f9de8942a6f72 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -41,6 +41,7 @@ unset CCACHE_CPP2
 unset CCACHE_DIR
 unset CCACHE_DISABLE
 unset CCACHE_EXTENSION
+unset CCACHE_EXTRAFILES
 unset CCACHE_HARDLINK
 unset CCACHE_HASHDIR
 unset CCACHE_LOGFILE
@@ -1095,6 +1096,56 @@ readonly_suite() {
     ##################################################################
 }
 
+extrafiles_suite() {
+    ##################################################################
+    # Create some code to compile.
+    cat <<EOF >test.c
+int test;
+EOF
+    echo a >a
+    echo b >b
+
+    ##################################################################
+    # Test the CCACHE_EXTRAFILES feature.
+
+    testname="cache hit"
+    $CCACHE $COMPILER -c test.c
+    checkstat 'cache hit (preprocessed)' 0
+    checkstat 'cache miss' 1
+
+    testname="cache miss"
+    $CCACHE $COMPILER -c test.c
+    checkstat 'cache hit (preprocessed)' 1
+    checkstat 'cache miss' 1
+
+    testname="cache miss a b"
+    CCACHE_EXTRAFILES="a b" $CCACHE $COMPILER -c test.c
+    checkstat 'cache hit (preprocessed)' 1
+    checkstat 'cache miss' 2
+
+    testname="cache hit a b"
+    CCACHE_EXTRAFILES="a b" $CCACHE $COMPILER -c test.c
+    checkstat 'cache hit (preprocessed)' 2
+    checkstat 'cache miss' 2
+
+    testname="cache miss a b2"
+    echo b2 >b
+    CCACHE_EXTRAFILES="a b" $CCACHE $COMPILER -c test.c
+    checkstat 'cache hit (preprocessed)' 2
+    checkstat 'cache miss' 3
+
+    testname="cache hit a b2"
+    CCACHE_EXTRAFILES="a b" $CCACHE $COMPILER -c test.c
+    checkstat 'cache hit (preprocessed)' 3
+    checkstat 'cache miss' 3
+
+    testname="cache miss doesntexist"
+    CCACHE_EXTRAFILES="doesntexist" $CCACHE $COMPILER -c test.c
+    checkstat 'cache hit (preprocessed)' 3
+    checkstat 'cache miss' 3
+    checkstat 'error hashing extra file' 1
+}
+
 ######################################################################
 # main program
 
@@ -1123,6 +1174,7 @@ direct
 basedir
 compression
 readonly
+extrafiles
 "
 
 if [ -z "$suites" ]; then