diff options
author | Hongli Lai (Phusion) <hongli@phusion.nl> | 2012-02-20 00:28:36 +0100 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2012-02-20 22:46:18 +0100 |
commit | 62d3eed8dee76a4b271f3c607ef5801b99b31717 (patch) | |
tree | f6ce72c3cbacc3b4c888d7b12edfc80fc95b588b | |
parent | 0593625c3308e6bf2f30030684dd68b820c87551 (diff) | |
download | ccache-62d3eed8dee76a4b271f3c607ef5801b99b31717.tar.gz |
Support adjusting the compression level through CCACHE_COMPRESS_LEVEL
-rw-r--r-- | MANUAL.txt | 7 | ||||
-rw-r--r-- | ccache.c | 12 | ||||
-rw-r--r-- | ccache.h | 6 | ||||
-rw-r--r-- | util.c | 29 |
4 files changed, 33 insertions, 21 deletions
@@ -244,6 +244,13 @@ WRAPPERS>>. cache; compressed and uncompressed results will still be usable regardless of this setting. +*CCACHE_COMPRESS_LEVEL*:: + + This environment variable determines the level at which ccache will + compress object files. It only has effect if *CCACHE_COMPRESS* is also + set. The value defaults to 6, and must be no lower than 1 (fastest, worst + compression) and no higher than 9 (slowest, best compression). + *CCACHE_CPP2*:: If you set the environment variable *CCACHE_CPP2* then ccache will not use @@ -163,10 +163,10 @@ static bool enable_unify; static bool enable_direct = true; /* - * Whether to enable compression of files stored in the cache. (Manifest files - * are always compressed.) + * If non-zero, enables compression of files stored in the cache, compressed + * at the given level. (Manifest files are always compressed.) */ -static bool enable_compression = false; +static int enable_compression = 0; /* number of levels (1 <= nlevels <= 8) */ static int nlevels = 2; @@ -2097,7 +2097,11 @@ ccache(int argc, char *argv[]) if (getenv("CCACHE_COMPRESS")) { cc_log("Compression enabled"); - enable_compression = true; + if (getenv("CCACHE_COMPRESS_LEVEL")) { + enable_compression = atoi(getenv("CCACHE_COMPRESS_LEVEL")); + } else { + enable_compression = 6; + } } if ((env = getenv("CCACHE_NLEVELS"))) { @@ -102,10 +102,10 @@ void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2); void cc_log_argv(const char *prefix, char **argv); void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2); void copy_fd(int fd_in, int fd_out); -int copy_file(const char *src, const char *dest, int compress_dest); -int move_file(const char *src, const char *dest, int compress_dest); +int copy_file(const char *src, const char *dest, int compress_level); +int move_file(const char *src, const char *dest, int compress_level); int move_uncompressed_file(const char *src, const char *dest, - int compress_dest); + int compress_level); bool file_is_compressed(const char *filename); int create_dir(const char *dir); int create_parent_dirs(const char *path); @@ -191,11 +191,11 @@ mkstemp(char *template) #endif /* - * Copy src to dest, decompressing src if needed. compress_dest decides whether - * dest will be compressed. + * Copy src to dest, decompressing src if needed. compress_level > 0 decides whether + * dest will be compressed, and with which compression level. */ int -copy_file(const char *src, const char *dest, int compress_dest) +copy_file(const char *src, const char *dest, int compress_level) { int fd_in = -1, fd_out = -1; gzFile gz_in = NULL, gz_out = NULL; @@ -210,7 +210,7 @@ copy_file(const char *src, const char *dest, int compress_dest) tmp_name = format("%s.%s.XXXXXX", dest, tmp_string()); cc_log("Copying %s to %s via %s (%s)", - src, dest, tmp_name, compress_dest ? "compressed": "uncompressed"); + src, dest, tmp_name, compress_level ? "compressed": "uncompressed"); /* open source file */ fd_in = open(src, O_RDONLY | O_BINARY); @@ -233,7 +233,7 @@ copy_file(const char *src, const char *dest, int compress_dest) goto error; } - if (compress_dest) { + if (compress_level) { /* * A gzip file occupies at least 20 bytes, so it will always * occupy an entire filesystem block, even for empty files. @@ -244,20 +244,21 @@ copy_file(const char *src, const char *dest, int compress_dest) goto error; } if (file_size(&st) == 0) { - compress_dest = 0; + compress_level = 0; } } - if (compress_dest) { + if (compress_level) { gz_out = gzdopen(dup(fd_out), "wb"); if (!gz_out) { cc_log("gzdopen(dest) error: %s", strerror(errno)); goto error; } + gzsetparams(gz_out, compress_level, Z_DEFAULT_STRATEGY); } while ((n = gzread(gz_in, buf, sizeof(buf))) > 0) { - if (compress_dest) { + if (compress_level) { written = gzwrite(gz_out, buf, n); } else { ssize_t count; @@ -271,7 +272,7 @@ copy_file(const char *src, const char *dest, int compress_dest) } while (written < n); } if (written != n) { - if (compress_dest) { + if (compress_level) { cc_log("gzwrite error: %s (errno: %s)", gzerror(gz_in, &errnum), strerror(errno)); @@ -346,11 +347,11 @@ error: /* Run copy_file() and, if successful, delete the source file. */ int -move_file(const char *src, const char *dest, int compress_dest) +move_file(const char *src, const char *dest, int compress_level) { int ret; - ret = copy_file(src, dest, compress_dest); + ret = copy_file(src, dest, compress_level); if (ret != -1) { x_unlink(src); } @@ -362,10 +363,10 @@ move_file(const char *src, const char *dest, int compress_dest) * are on the same file system. */ int -move_uncompressed_file(const char *src, const char *dest, int compress_dest) +move_uncompressed_file(const char *src, const char *dest, int compress_level) { - if (compress_dest) { - return move_file(src, dest, compress_dest); + if (compress_level) { + return move_file(src, dest, compress_level); } else { return x_rename(src, dest); } |