added CCACHE_NOUNIFY option

This commit is contained in:
Andrew Tridgell 2002-04-01 02:23:31 +02:00
parent 5d11689fb7
commit 4867d787f2
6 changed files with 63 additions and 40 deletions

View File

@ -1,4 +1,3 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
@ -12,13 +11,18 @@ OBJS= ccache.o mdfour.o hash.o execute.o util.o args.o stats.o \
cleanup.o snprintf.o unify.o
HEADERS = ccache.h mdfour.h
all: ccache ccache.1
all: ccache
docs: ccache.1 web/ccache-man.html
ccache: $(OBJS) $(HEADERS)
$(CC) $(CFLAGS) -o $@ $(OBJS)
ccache.1: ccache.yo
yodl2man -o ccache.1 ccache.yo
web/ccache-man.html: ccache.yo
mkdir -p man
yodl2html -o web/ccache-man.html ccache.yo
install:

View File

@ -134,6 +134,14 @@ If you set the environment variable
CCACHE_DISABLE then ccache will just call the real compiler,
bypassing the cache completely\&.
.IP
.IP "\fBCCACHE_NOUNIFY\fP"
If you set the environment variable
CCACHE_NOUNIFY then ccache will not use the C/C++ unifier when hashing
the pre-processor output\&. The unifier is slower than a normal hash, so
setting this environment variable gains a little bit of speed, but it
means that ccache can\&'t take advantage of not recompiling when the
changes to the source code consist of reformatting only\&.
.IP
.PP
.SH "CACHE SIZE MANAGEMENT"
.PP

View File

@ -108,40 +108,6 @@ static void to_cache(ARGS *args)
free(path_stderr);
}
/* hash a file that consists of preprocessor output, but remove any line
number information from the hash
*/
static void stabs_hash(const char *fname)
{
int fd;
struct stat st;
char *map;
fd = open(fname, O_RDONLY);
if (fd == -1 || fstat(fd, &st) != 0) {
cc_log("Failed to open preprocessor output %s\n", fname);
stats_update(STATS_PREPROCESSOR);
failed();
}
/* we use mmap() to make it easy to handle arbitrarily long
lines in preprocessor output. I have seen lines of over
100k in length, so this is well worth it */
map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (map == (char *)-1) {
cc_log("Failed to mmap %s\n", fname);
failed();
}
close(fd);
/* pass it through the unifier */
unify(map, st.st_size);
munmap(map, st.st_size);
}
/* find the hash for a command. The hash includes all argument lists,
plus the output from running the compiler with -E */
static void find_hash(ARGS *args)
@ -212,10 +178,12 @@ static void find_hash(ARGS *args)
information. Otherwise we can discard line number info, which makes
us less sensitive to reformatting changes
*/
if (found_debug) {
if (found_debug || getenv("CCACHE_NOUNIFY")) {
hash_file(path_stdout);
} else {
stabs_hash(path_stdout);
if (unify_hash(path_stdout) != 0) {
failed();
}
}
hash_file(path_stderr);

View File

@ -88,7 +88,8 @@ void stats_set_limits(long maxfiles, long maxsize);
size_t value_units(const char *s);
void stats_set_sizes(const char *dir, size_t num_files, size_t total_size);
void unify(unsigned char *p, size_t size);
int unify_hash(const char *fname);
void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize);

View File

@ -114,6 +114,13 @@ dit(bf(CCACHE_DISABLE)) If you set the environment variable
CCACHE_DISABLE then ccache will just call the real compiler,
bypassing the cache completely.
dit(bf(CCACHE_NOUNIFY)) If you set the environment variable
CCACHE_NOUNIFY then ccache will not use the C/C++ unifier when hashing
the pre-processor output. The unifier is slower than a normal hash, so
setting this environment variable gains a little bit of speed, but it
means that ccache can't take advantage of not recompiling when the
changes to the source code consist of reformatting only.
enddit()
manpagesection(CACHE SIZE MANAGEMENT)

37
unify.c
View File

@ -106,7 +106,7 @@ static void pushchar(unsigned char c)
}
/* hash some C/C++ code after unifying */
void unify(unsigned char *p, size_t size)
static void unify(unsigned char *p, size_t size)
{
size_t ofs;
unsigned char q;
@ -220,3 +220,38 @@ void unify(unsigned char *p, size_t size)
pushchar(0);
}
/* hash a file that consists of preprocessor output, but remove any line
number information from the hash
*/
int unify_hash(const char *fname)
{
int fd;
struct stat st;
char *map;
fd = open(fname, O_RDONLY);
if (fd == -1 || fstat(fd, &st) != 0) {
cc_log("Failed to open preprocessor output %s\n", fname);
stats_update(STATS_PREPROCESSOR);
return -1;
}
/* we use mmap() to make it easy to handle arbitrarily long
lines in preprocessor output. I have seen lines of over
100k in length, so this is well worth it */
map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (map == (char *)-1) {
cc_log("Failed to mmap %s\n", fname);
return -1;
}
close(fd);
/* pass it through the unifier */
unify(map, st.st_size);
munmap(map, st.st_size);
return 0;
}