Add CCACHE_EXTRAFILES feature

This commit is contained in:
Joel Rosdahl 2010-04-28 22:30:55 +02:00
parent 1b322f5fe4
commit 609fb3417f
6 changed files with 81 additions and 0 deletions

View File

@ -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.

View File

@ -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);
}
}
/*

View File

@ -49,6 +49,7 @@ enum stats {
STATS_CACHEHIT_DIR,
STATS_NOOUTPUT,
STATS_EMPTYOUTPUT,
STATS_BADEXTRAFILE,
STATS_END
};

View 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

View File

@ -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 },

52
test.sh
View File

@ -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