From: Andrew Tridgell Date: Mon, 1 Apr 2002 00:23:31 +0000 (+0200) Subject: added CCACHE_NOUNIFY option X-Git-Tag: v1.3~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4867d787f27e19931ad95b8185dfd3dff22664bc;p=thirdparty%2Fccache.git added CCACHE_NOUNIFY option --- diff --git a/Makefile.in b/Makefile.in index a26b4c737..1e911e0cf 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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: diff --git a/ccache.1 b/ccache.1 index d4a78360f..4a404870c 100644 --- a/ccache.1 +++ b/ccache.1 @@ -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 diff --git a/ccache.c b/ccache.c index e7dc5e8c5..cdc5e8d26 100644 --- a/ccache.c +++ b/ccache.c @@ -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); diff --git a/ccache.h b/ccache.h index 9166f95d2..582756dd8 100644 --- a/ccache.h +++ b/ccache.h @@ -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); diff --git a/ccache.yo b/ccache.yo index d26a0f090..38a80db6c 100644 --- a/ccache.yo +++ b/ccache.yo @@ -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) diff --git a/unify.c b/unify.c index 6e19bc899..884237286 100644 --- a/unify.c +++ b/unify.c @@ -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; +} +