From: Andrew Tridgell Date: Fri, 10 Sep 2004 05:05:14 +0000 (+0200) Subject: added CCACHE_READONLY and CCACHE_TEMPDIR options, thanks to a X-Git-Tag: v2.4~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0df8530cab4df895060f21560220abc50ad99111;p=thirdparty%2Fccache.git added CCACHE_READONLY and CCACHE_TEMPDIR options, thanks to a suggestion from Jeff Apple --- diff --git a/ccache.1 b/ccache.1 index 8ffb5cc29..daec8ee1e 100644 --- a/ccache.1 +++ b/ccache.1 @@ -101,6 +101,7 @@ To install for the second method do something like this: cp ccache /usr/local/bin/ ln -s /usr/local/bin/ccache /usr/local/bin/gcc + ln -s /usr/local/bin/ccache /usr/local/bin/g++ ln -s /usr/local/bin/ccache /usr/local/bin/cc .fi @@ -118,7 +119,7 @@ cause "interesting" problems\&. When run as a compiler front end ccache usually just takes the same command line options as the compiler you are using\&. The only exception to this is the option \&'--ccache-skip\&'\&. That option can be used to tell -ccache that the next option is definately not a input filename, and +ccache that the next option is definitely not a input filename, and should be passed along to the compiler as-is\&. .PP The reason this can be important is that ccache does need to parse the @@ -142,6 +143,13 @@ the CCACHE_DIR environment variable specifies where ccache will keep its cached compiler output\&. The default is "$HOME/\&.ccache"\&. .IP +.IP "\fBCCACHE_TEMPDIR\fP" +the CCACHE_TEMPDIR environment variable specifies +where ccache will put temporary files\&. The default is the same as +CCACHE_DIR\&. Note that the CCACHE_TEMPDIR path must be on the same +filesystem as the CCACHE_DIR path, so that renames of files between +the two directories can work\&. +.IP .IP "\fBCCACHE_LOGFILE\fP" If you set the CCACHE_LOGFILE environment variable then ccache will write some log information on cache hits @@ -169,6 +177,14 @@ If you set the environment variable CCACHE_DISABLE then ccache will just call the real compiler, bypassing the cache completely\&. .IP +.IP "\fBCCACHE_READONLY\fP" +the CCACHE_READONLY environment variable +tells ccache to attempt to use existing cached object files, but not +to try to add anything new to the cache\&. If you are using this because +your CCACHE_DIR is read-only, then you may find that you also need to +set CCACHE_TEMPDIR as otherwise ccache will fail to create the +temporary files\&. +.IP .IP "\fBCCACHE_CPP2\fP" If you set the environment variable CCACHE_CPP2 then ccache will not use the optimisation of avoiding the 2nd call to @@ -304,11 +320,14 @@ following conditions need to be met: .IP o Use the same \fBCCACHE_DIR\fP environment variable setting .IP o -Make sure that all users have write permission in the entire -cache directory (and that you trust all users of the shared cache)\&. +Set the \fBCCACHE_NOLINK\fP environment variable .IP o Make sure everyone sets the CCACHE_UMASK environment variable -to 002, this ensures that cached files are accessible to everyone\&. +to 002, this ensures that cached files are accessible to everyone in +the group\&. +.IP o +Make sure that all users have write permission in the entire +cache directory (and that you trust all users of the shared cache)\&. .IP o Make sure that the setgid bit is set on all directories in the cache\&. This tells the filesystem to inherit group ownership for new diff --git a/ccache.c b/ccache.c index b0fd9dbbe..ace986d1f 100644 --- a/ccache.c +++ b/ccache.c @@ -26,6 +26,9 @@ /* the base cache directory */ char *cache_dir = NULL; +/* the directory for temporary files */ +static char *temp_dir = NULL; + /* the debug logfile name, if set */ char *cache_logfile = NULL; @@ -155,9 +158,9 @@ static void to_cache(ARGS *args) struct stat st1, st2; int status; - x_asprintf(&tmp_stdout, "%s/tmp.stdout.%s", cache_dir, tmp_string()); - x_asprintf(&tmp_stderr, "%s/tmp.stderr.%s", cache_dir, tmp_string()); - x_asprintf(&tmp_hashname, "%s/tmp.hash.%s.o", cache_dir, tmp_string()); + x_asprintf(&tmp_stdout, "%s/tmp.stdout.%s", temp_dir, tmp_string()); + x_asprintf(&tmp_stderr, "%s/tmp.stderr.%s", temp_dir, tmp_string()); + x_asprintf(&tmp_hashname, "%s/tmp.hash.%s.o", temp_dir, tmp_string()); args_add(args, "-o"); args_add(args, tmp_hashname); @@ -347,10 +350,10 @@ static void find_hash(ARGS *args) } /* now the run */ - x_asprintf(&path_stdout, "%s/%s.tmp.%s.%s", cache_dir, + x_asprintf(&path_stdout, "%s/%s.tmp.%s.%s", temp_dir, input_base, tmp_string(), i_extension); - x_asprintf(&path_stderr, "%s/tmp.cpp_stderr.%s", cache_dir, tmp_string()); + x_asprintf(&path_stderr, "%s/tmp.cpp_stderr.%s", temp_dir, tmp_string()); if (!direct_i_file) { /* run cpp on the input file to obtain the .i */ @@ -845,6 +848,11 @@ static void ccache(int argc, char *argv[]) /* if we can return from cache at this point then do */ from_cache(1); + + if (getenv("CCACHE_READONLY")) { + cc_log("read-only set - doing real compile\n"); + failed(); + } /* run real compiler, sending output to cache */ to_cache(stripped_args); @@ -971,6 +979,11 @@ int main(int argc, char *argv[]) x_asprintf(&cache_dir, "%s/.ccache", get_home_directory()); } + temp_dir = getenv("CCACHE_TEMPDIR"); + if (!temp_dir) { + temp_dir = cache_dir; + } + cache_logfile = getenv("CCACHE_LOGFILE"); setup_uncached_err(); diff --git a/ccache.yo b/ccache.yo index 8c152754d..12e45a6fb 100644 --- a/ccache.yo +++ b/ccache.yo @@ -125,6 +125,12 @@ dit(bf(CCACHE_DIR)) the CCACHE_DIR environment variable specifies where ccache will keep its cached compiler output. The default is "$HOME/.ccache". +dit(bf(CCACHE_TEMPDIR)) the CCACHE_TEMPDIR environment variable specifies +where ccache will put temporary files. The default is the same as +CCACHE_DIR. Note that the CCACHE_TEMPDIR path must be on the same +filesystem as the CCACHE_DIR path, so that renames of files between +the two directories can work. + dit(bf(CCACHE_LOGFILE)) If you set the CCACHE_LOGFILE environment variable then ccache will write some log information on cache hits and misses in that file. This is useful for tracking down problems. @@ -147,6 +153,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_READONLY)) the CCACHE_READONLY environment variable +tells ccache to attempt to use existing cached object files, but not +to try to add anything new to the cache. If you are using this because +your CCACHE_DIR is read-only, then you may find that you also need to +set CCACHE_TEMPDIR as otherwise ccache will fail to create the +temporary files. + dit(bf(CCACHE_CPP2)) If you set the environment variable CCACHE_CPP2 then ccache will not use the optimisation of avoiding the 2nd call to the pre-processor by compiling the pre-processed output that was used