summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2012-02-20 23:16:25 +0100
committerJoel Rosdahl <joel@rosdahl.net>2012-02-20 23:16:25 +0100
commit4870af9422e00b272ad129df72166d4f3ba4268b (patch)
treed1354fc1a281b01539c3944465fe92ced424b2bb
parent534e723f0d90a0b0a64ad268d398a91561520b78 (diff)
parent5efb007aeaee8974802cc99b8f8a6bf88f5f7a81 (diff)
downloadccache-4870af9422e00b272ad129df72166d4f3ba4268b.tar.gz
Merge branch 'master' into config
* master: Minor code style changes Support adjusting the compression level through CCACHE_COMPRESS_LEVEL Conflicts: MANUAL.txt ccache.c
-rw-r--r--MANUAL.txt10
-rw-r--r--ccache.c9
-rw-r--r--ccache.h6
-rw-r--r--conf.c5
-rw-r--r--conf.h1
-rw-r--r--confitems.gperf39
-rw-r--r--confitems_lookup.c76
-rw-r--r--envtoconfitems.gperf1
-rw-r--r--envtoconfitems_lookup.c99
-rw-r--r--test/test_conf.c11
-rw-r--r--util.c31
11 files changed, 165 insertions, 123 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index b4679766..6717fdeb 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -314,6 +314,13 @@ WRAPPERS>>.
retrieved from the cache; compressed and uncompressed results will still be
usable regardless of this setting. The default is false.
+*compression_level* (*CCACHE_COMPRESSLEVEL*)::
+
+ This setting determines the level at which ccache will compress object
+ files. It only has effect if *compression* is enabled. The value defaults
+ to 6, and must be no lower than 1 (fastest, worst compression) and no
+ higher than 9 (slowest, best compression).
+
*cpp_extension* (*CCACHE_EXTENSION*)::
This setting can be used to force a certain extension for the intermediate
@@ -471,7 +478,8 @@ Cache compression
ccache can optionally compress all files it puts into the cache using the
compression library zlib. While this may involve a tiny performance slowdown,
it increases the number of files that fit in the cache. You can turn on
-compression with the *compress* configuration setting.
+compression with the *compression* configuration setting and you can also tweak
+the compression level with *compression_level*.
How ccache works
diff --git a/ccache.c b/ccache.c
index 5a55e08f..44046efc 100644
--- a/ccache.c
+++ b/ccache.c
@@ -675,8 +675,9 @@ to_cache(struct args *args)
failed();
}
if (st.st_size > 0) {
- if (move_uncompressed_file(tmp_stderr, cached_stderr,
- conf->compression) != 0) {
+ if (move_uncompressed_file(
+ tmp_stderr, cached_stderr,
+ conf->compression ? conf->compression_level : 0) != 0) {
cc_log("Failed to move %s to %s: %s", tmp_stderr, cached_stderr,
strerror(errno));
stats_update(STATS_ERROR);
@@ -704,7 +705,9 @@ to_cache(struct args *args)
stats_update(STATS_ERROR);
failed();
}
- } else if (move_uncompressed_file(tmp_obj, cached_obj, conf->compression) != 0) {
+ } else if (move_uncompressed_file(
+ tmp_obj, cached_obj,
+ conf->compression ? conf->compression_level : 0) != 0) {
cc_log("Failed to move %s to %s: %s", tmp_obj, cached_obj, strerror(errno));
stats_update(STATS_ERROR);
failed();
diff --git a/ccache.h b/ccache.h
index 2ef65c5f..6e9b8106 100644
--- a/ccache.h
+++ b/ccache.h
@@ -105,10 +105,10 @@ void cc_bulklog(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);
diff --git a/conf.c b/conf.c
index de549e15..ea052db5 100644
--- a/conf.c
+++ b/conf.c
@@ -295,6 +295,7 @@ conf_create(void)
conf->compiler = x_strdup("");
conf->compiler_check = x_strdup("mtime");
conf->compression = false;
+ conf->compression_level = 6;
conf->cpp_extension = x_strdup("");
conf->direct_mode = true;
conf->disable = false;
@@ -528,6 +529,10 @@ conf_print_items(struct conf *conf,
reformat(&s, "compression = %s", conf->compression ? "true" : "false");
printer(s, conf->item_origins[find_conf("compression")->number], context);
+ reformat(&s, "compression_level = %u", conf->compression_level);
+ printer(s, conf->item_origins[find_conf("compression_level")->number],
+ context);
+
reformat(&s, "cpp_extension = %s", conf->cpp_extension);
printer(s, conf->item_origins[find_conf("cpp_extension")->number], context);
diff --git a/conf.h b/conf.h
index e95a2686..9963bced 100644
--- a/conf.h
+++ b/conf.h
@@ -10,6 +10,7 @@ struct conf {
char *compiler;
char *compiler_check;
bool compression;
+ unsigned compression_level;
char *cpp_extension;
bool direct_mode;
bool disable;
diff --git a/confitems.gperf b/confitems.gperf
index 75c6765a..ae48d2b4 100644
--- a/confitems.gperf
+++ b/confitems.gperf
@@ -13,22 +13,23 @@ cache_dir_levels, 2, ITEM_V(cache_dir_levels, unsigned, dir_levels)
compiler, 3, ITEM(compiler, string)
compiler_check, 4, ITEM(compiler_check, string)
compression, 5, ITEM(compression, bool)
-cpp_extension, 6, ITEM(cpp_extension, string)
-direct_mode, 7, ITEM(direct_mode, bool)
-disable, 8, ITEM(disable, bool)
-extra_files_to_hash, 9, ITEM(extra_files_to_hash, env_string)
-hard_link, 10, ITEM(hard_link, bool)
-hash_dir, 11, ITEM(hash_dir, bool)
-log_file, 12, ITEM(log_file, env_string)
-max_files, 13, ITEM(max_files, unsigned)
-max_size, 14, ITEM(max_size, size)
-path, 15, ITEM(path, env_string)
-prefix_command, 16, ITEM(prefix_command, env_string)
-read_only, 17, ITEM(read_only, bool)
-recache, 18, ITEM(recache, bool)
-run_second_cpp, 19, ITEM(run_second_cpp, bool)
-sloppiness, 20, ITEM(sloppiness, sloppiness)
-stats, 21, ITEM(stats, bool)
-temporary_dir, 22, ITEM(temporary_dir, env_string)
-umask, 23, ITEM(umask, umask)
-unify, 24, ITEM(unify, bool)
+compression_level, 6, ITEM(compression_level, unsigned)
+cpp_extension, 7, ITEM(cpp_extension, string)
+direct_mode, 8, ITEM(direct_mode, bool)
+disable, 9, ITEM(disable, bool)
+extra_files_to_hash, 10, ITEM(extra_files_to_hash, env_string)
+hard_link, 11, ITEM(hard_link, bool)
+hash_dir, 12, ITEM(hash_dir, bool)
+log_file, 13, ITEM(log_file, env_string)
+max_files, 14, ITEM(max_files, unsigned)
+max_size, 15, ITEM(max_size, size)
+path, 16, ITEM(path, env_string)
+prefix_command, 17, ITEM(prefix_command, env_string)
+read_only, 18, ITEM(read_only, bool)
+recache, 19, ITEM(recache, bool)
+run_second_cpp, 20, ITEM(run_second_cpp, bool)
+sloppiness, 21, ITEM(sloppiness, sloppiness)
+stats, 22, ITEM(stats, bool)
+temporary_dir, 23, ITEM(temporary_dir, env_string)
+umask, 24, ITEM(umask, umask)
+unify, 25, ITEM(unify, bool)
diff --git a/confitems_lookup.c b/confitems_lookup.c
index 877a7e30..e00ff9be 100644
--- a/confitems_lookup.c
+++ b/confitems_lookup.c
@@ -55,7 +55,7 @@ confitems_hash (register const char *str, register unsigned int len)
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
45, 45, 45, 45, 45, 45, 45, 0, 25, 0,
- 5, 15, 45, 45, 30, 5, 45, 45, 15, 10,
+ 10, 15, 45, 45, 30, 5, 45, 45, 15, 10,
0, 0, 0, 45, 10, 0, 0, 5, 45, 45,
10, 45, 45, 45, 45, 45, 45, 45, 45, 45,
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
@@ -86,7 +86,7 @@ confitems_get (register const char *str, register unsigned int len)
{
enum
{
- TOTAL_KEYWORDS = 25,
+ TOTAL_KEYWORDS = 26,
MIN_WORD_LENGTH = 4,
MAX_WORD_LENGTH = 19,
MIN_HASH_VALUE = 4,
@@ -97,66 +97,68 @@ confitems_get (register const char *str, register unsigned int len)
{
{"",0,NULL,0,NULL}, {"",0,NULL,0,NULL},
{"",0,NULL,0,NULL}, {"",0,NULL,0,NULL},
-#line 25 "confitems.gperf"
- {"path", 15, ITEM(path, env_string)},
-#line 31 "confitems.gperf"
- {"stats", 21, ITEM(stats, bool)},
+#line 26 "confitems.gperf"
+ {"path", 16, ITEM(path, env_string)},
+#line 32 "confitems.gperf"
+ {"stats", 22, ITEM(stats, bool)},
{"",0,NULL,0,NULL}, {"",0,NULL,0,NULL},
#line 13 "confitems.gperf"
{"compiler", 3, ITEM(compiler, string)},
#line 11 "confitems.gperf"
{"cache_dir", 1, ITEM(cache_dir, env_string)},
-#line 34 "confitems.gperf"
- {"unify", 24, ITEM(unify, bool)},
+#line 35 "confitems.gperf"
+ {"unify", 25, ITEM(unify, bool)},
#line 15 "confitems.gperf"
{"compression", 5, ITEM(compression, bool)},
{"",0,NULL,0,NULL},
-#line 16 "confitems.gperf"
- {"cpp_extension", 6, ITEM(cpp_extension, string)},
+#line 17 "confitems.gperf"
+ {"cpp_extension", 7, ITEM(cpp_extension, string)},
#line 14 "confitems.gperf"
{"compiler_check", 4, ITEM(compiler_check, string)},
{"",0,NULL,0,NULL},
#line 12 "confitems.gperf"
{"cache_dir_levels", 2, ITEM_V(cache_dir_levels, unsigned, dir_levels)},
-#line 18 "confitems.gperf"
- {"disable", 8, ITEM(disable, bool)},
+#line 16 "confitems.gperf"
+ {"compression_level", 6, ITEM(compression_level, unsigned)},
+#line 25 "confitems.gperf"
+ {"max_size", 15, ITEM(max_size, size)},
#line 24 "confitems.gperf"
- {"max_size", 14, ITEM(max_size, size)},
+ {"max_files", 14, ITEM(max_files, unsigned)},
+#line 34 "confitems.gperf"
+ {"umask", 24, ITEM(umask, umask)},
+ {"",0,NULL,0,NULL},
+#line 19 "confitems.gperf"
+ {"disable", 9, ITEM(disable, bool)},
#line 23 "confitems.gperf"
- {"max_files", 13, ITEM(max_files, unsigned)},
-#line 33 "confitems.gperf"
- {"umask", 23, ITEM(umask, umask)},
-#line 17 "confitems.gperf"
- {"direct_mode", 7, ITEM(direct_mode, bool)},
+ {"log_file", 13, ITEM(log_file, env_string)},
+#line 27 "confitems.gperf"
+ {"prefix_command", 17, ITEM(prefix_command, env_string)},
+#line 31 "confitems.gperf"
+ {"sloppiness", 21, ITEM(sloppiness, sloppiness)},
+#line 18 "confitems.gperf"
+ {"direct_mode", 8, ITEM(direct_mode, bool)},
{"",0,NULL,0,NULL},
-#line 22 "confitems.gperf"
- {"log_file", 12, ITEM(log_file, env_string)},
-#line 26 "confitems.gperf"
- {"prefix_command", 16, ITEM(prefix_command, env_string)},
+#line 33 "confitems.gperf"
+ {"temporary_dir", 23, ITEM(temporary_dir, env_string)},
#line 30 "confitems.gperf"
- {"sloppiness", 20, ITEM(sloppiness, sloppiness)},
+ {"run_second_cpp", 20, ITEM(run_second_cpp, bool)},
{"",0,NULL,0,NULL}, {"",0,NULL,0,NULL},
-#line 32 "confitems.gperf"
- {"temporary_dir", 22, ITEM(temporary_dir, env_string)},
#line 29 "confitems.gperf"
- {"run_second_cpp", 19, ITEM(run_second_cpp, bool)},
- {"",0,NULL,0,NULL}, {"",0,NULL,0,NULL},
-#line 28 "confitems.gperf"
- {"recache", 18, ITEM(recache, bool)},
+ {"recache", 19, ITEM(recache, bool)},
#line 10 "confitems.gperf"
{"base_dir", 0, ITEM_V(base_dir, env_string, absolute_path)},
-#line 27 "confitems.gperf"
- {"read_only", 17, ITEM(read_only, bool)},
+#line 28 "confitems.gperf"
+ {"read_only", 18, ITEM(read_only, bool)},
{"",0,NULL,0,NULL}, {"",0,NULL,0,NULL},
{"",0,NULL,0,NULL},
+#line 22 "confitems.gperf"
+ {"hash_dir", 12, ITEM(hash_dir, bool)},
#line 21 "confitems.gperf"
- {"hash_dir", 11, ITEM(hash_dir, bool)},
-#line 20 "confitems.gperf"
- {"hard_link", 10, ITEM(hard_link, bool)},
+ {"hard_link", 11, ITEM(hard_link, bool)},
{"",0,NULL,0,NULL}, {"",0,NULL,0,NULL},
{"",0,NULL,0,NULL}, {"",0,NULL,0,NULL},
-#line 19 "confitems.gperf"
- {"extra_files_to_hash", 9, ITEM(extra_files_to_hash, env_string)}
+#line 20 "confitems.gperf"
+ {"extra_files_to_hash", 10, ITEM(extra_files_to_hash, env_string)}
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
@@ -173,4 +175,4 @@ confitems_get (register const char *str, register unsigned int len)
}
return 0;
}
-static const size_t CONFITEMS_TOTAL_KEYWORDS = 25;
+static const size_t CONFITEMS_TOTAL_KEYWORDS = 26;
diff --git a/envtoconfitems.gperf b/envtoconfitems.gperf
index a528af5b..635bc562 100644
--- a/envtoconfitems.gperf
+++ b/envtoconfitems.gperf
@@ -12,6 +12,7 @@ BASEDIR, "base_dir"
CC, "compiler"
COMPILERCHECK, "compiler_check"
COMPRESS, "compression"
+COMPRESSLEVEL, "compression_level"
CPP2, "run_second_cpp"
DIR, "cache_dir"
DIRECT, "direct_mode"
diff --git a/envtoconfitems_lookup.c b/envtoconfitems_lookup.c
index c21f2a26..8c99738e 100644
--- a/envtoconfitems_lookup.c
+++ b/envtoconfitems_lookup.c
@@ -1,6 +1,6 @@
/* ANSI-C code produced by gperf version 3.0.3 */
/* Command-line: gperf envtoconfitems.gperf */
-/* Computed positions: -k'1-2' */
+/* Computed positions: -k'1,5' */
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
&& ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
@@ -51,9 +51,10 @@ envtoconfitems_hash (register const char *str, register unsigned int len)
43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
- 43, 43, 43, 43, 43, 10, 5, 0, 0, 0,
- 43, 43, 20, 0, 43, 43, 15, 10, 20, 10,
- 0, 43, 5, 0, 10, 5, 43, 43, 0, 43,
+ 43, 43, 43, 43, 43, 43, 5, 0, 0, 10,
+ 20, 43, 15, 43, 10, 43, 20, 10, 15, 0,
+ 5, 5, 5, 0, 0, 5, 43, 43, 43, 43,
+ 0, 43, 43, 43, 43, 43, 43, 43, 43, 43,
43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
@@ -69,10 +70,23 @@ envtoconfitems_hash (register const char *str, register unsigned int len)
43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
- 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
- 43, 43, 43, 43, 43, 43
+ 43, 43, 43, 43, 43, 43, 43
};
- return len + asso_values[(unsigned char)str[1]] + asso_values[(unsigned char)str[0]];
+ register int hval = len;
+
+ switch (hval)
+ {
+ default:
+ hval += asso_values[(unsigned char)str[4]+1];
+ /*FALLTHROUGH*/
+ case 4:
+ case 3:
+ case 2:
+ case 1:
+ hval += asso_values[(unsigned char)str[0]];
+ break;
+ }
+ return hval;
}
#ifdef __GNUC__
@@ -86,7 +100,7 @@ envtoconfitems_get (register const char *str, register unsigned int len)
{
enum
{
- TOTAL_KEYWORDS = 25,
+ TOTAL_KEYWORDS = 26,
MIN_WORD_LENGTH = 2,
MAX_WORD_LENGTH = 13,
MIN_HASH_VALUE = 2,
@@ -98,64 +112,65 @@ envtoconfitems_get (register const char *str, register unsigned int len)
{"",""}, {"",""},
#line 12 "envtoconfitems.gperf"
{"CC", "compiler"},
-#line 16 "envtoconfitems.gperf"
+#line 17 "envtoconfitems.gperf"
{"DIR", "cache_dir"},
-#line 15 "envtoconfitems.gperf"
+#line 16 "envtoconfitems.gperf"
{"CPP2", "run_second_cpp"},
- {"",""},
-#line 17 "envtoconfitems.gperf"
- {"DIRECT", "direct_mode"},
+#line 33 "envtoconfitems.gperf"
+ {"STATS", "stats"},
#line 18 "envtoconfitems.gperf"
- {"DISABLE", "disable"},
- {"",""},
+ {"DIRECT", "direct_mode"},
#line 19 "envtoconfitems.gperf"
- {"EXTENSION", "cpp_extension"},
-#line 20 "envtoconfitems.gperf"
- {"EXTRAFILES", "extra_files_to_hash"},
+ {"DISABLE", "disable"},
+#line 14 "envtoconfitems.gperf"
+ {"COMPRESS", "compression"},
#line 28 "envtoconfitems.gperf"
- {"PREFIX", "prefix_command"},
-#line 30 "envtoconfitems.gperf"
- {"RECACHE", "recache"},
-#line 29 "envtoconfitems.gperf"
- {"READONLY", "read_only"},
-#line 27 "envtoconfitems.gperf"
{"PATH", "path"},
-#line 32 "envtoconfitems.gperf"
- {"STATS", "stats"},
+#line 36 "envtoconfitems.gperf"
+ {"UNIFY", "unify"},
{"",""},
-#line 33 "envtoconfitems.gperf"
- {"TEMPDIR", "temporary_dir"},
-#line 14 "envtoconfitems.gperf"
- {"COMPRESS", "compression"},
+#line 31 "envtoconfitems.gperf"
+ {"RECACHE", "recache"},
+#line 15 "envtoconfitems.gperf"
+ {"COMPRESSLEVEL", "compression_level"},
+ {"",""},
+#line 32 "envtoconfitems.gperf"
+ {"SLOPPINESS", "sloppiness"},
{"",""},
#line 34 "envtoconfitems.gperf"
- {"UMASK", "umask"},
+ {"TEMPDIR", "temporary_dir"},
+#line 30 "envtoconfitems.gperf"
+ {"READONLY", "read_only"},
+#line 20 "envtoconfitems.gperf"
+ {"EXTENSION", "cpp_extension"},
{"",""},
+#line 29 "envtoconfitems.gperf"
+ {"PREFIX", "prefix_command"},
#line 11 "envtoconfitems.gperf"
{"BASEDIR", "base_dir"},
#line 13 "envtoconfitems.gperf"
{"COMPILERCHECK", "compiler_check"},
{"",""},
-#line 31 "envtoconfitems.gperf"
- {"SLOPPINESS", "sloppiness"},
+#line 21 "envtoconfitems.gperf"
+ {"EXTRAFILES", "extra_files_to_hash"},
{"",""},
-#line 25 "envtoconfitems.gperf"
+#line 26 "envtoconfitems.gperf"
{"MAXSIZE", "max_size"},
-#line 24 "envtoconfitems.gperf"
+#line 25 "envtoconfitems.gperf"
{"MAXFILES", "max_files"},
{"",""},
#line 35 "envtoconfitems.gperf"
- {"UNIFY", "unify"},
+ {"UMASK", "umask"},
{"",""},
#line 23 "envtoconfitems.gperf"
- {"LOGFILE", "log_file"},
- {"",""}, {"",""}, {"",""}, {"",""},
-#line 22 "envtoconfitems.gperf"
{"HASHDIR", "hash_dir"},
-#line 21 "envtoconfitems.gperf"
+#line 22 "envtoconfitems.gperf"
{"HARDLINK", "hard_link"},
{"",""}, {"",""}, {"",""},
-#line 26 "envtoconfitems.gperf"
+#line 24 "envtoconfitems.gperf"
+ {"LOGFILE", "log_file"},
+ {"",""}, {"",""}, {"",""}, {"",""},
+#line 27 "envtoconfitems.gperf"
{"NLEVELS", "cache_dir_levels"}
};
@@ -173,4 +188,4 @@ envtoconfitems_get (register const char *str, register unsigned int len)
}
return 0;
}
-static const size_t ENVTOCONFITEMS_TOTAL_KEYWORDS = 25;
+static const size_t ENVTOCONFITEMS_TOTAL_KEYWORDS = 26;
diff --git a/test/test_conf.c b/test/test_conf.c
index cfb00a54..27ab4416 100644
--- a/test/test_conf.c
+++ b/test/test_conf.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 Joel Rosdahl
+ * Copyright (C) 2011-2012 Joel Rosdahl
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
@@ -20,7 +20,7 @@
#include "test/framework.h"
#include "test/util.h"
-#define N_CONFIG_ITEMS 25
+#define N_CONFIG_ITEMS 26
static struct {
char *descr;
const char *origin;
@@ -57,6 +57,7 @@ TEST(conf_create)
CHECK_STR_EQ("", conf->compiler);
CHECK_STR_EQ("mtime", conf->compiler_check);
CHECK(!conf->compression);
+ CHECK_INT_EQ(6, conf->compression_level);
CHECK_STR_EQ("", conf->cpp_extension);
CHECK(conf->direct_mode);
CHECK(!conf->disable);
@@ -97,6 +98,7 @@ TEST(conf_read_valid_config)
"\t compiler = foo\n"
"compiler_check = none\n"
"compression=true\n"
+ "compression_level= 2\n"
"cpp_extension = .foo\n"
"direct_mode = false\n"
"disable = true\n"
@@ -125,6 +127,7 @@ TEST(conf_read_valid_config)
CHECK_STR_EQ("foo", conf->compiler);
CHECK_STR_EQ("none", conf->compiler_check);
CHECK(conf->compression);
+ CHECK_INT_EQ(2, conf->compression_level);
CHECK_STR_EQ(".foo", conf->cpp_extension);
CHECK(!conf->direct_mode);
CHECK(conf->disable);
@@ -345,6 +348,7 @@ TEST(conf_print_items)
"c",
"cc",
true,
+ 8,
"ce",
false,
true,
@@ -374,13 +378,14 @@ TEST(conf_print_items)
}
conf_print_items(&conf, conf_item_receiver, NULL);
- CHECK_INT_EQ(25, n_received_conf_items);
+ CHECK_INT_EQ(N_CONFIG_ITEMS, n_received_conf_items);
CHECK_STR_EQ("base_dir = bd", received_conf_items[n++].descr);
CHECK_STR_EQ("cache_dir = cd", received_conf_items[n++].descr);
CHECK_STR_EQ("cache_dir_levels = 7", received_conf_items[n++].descr);
CHECK_STR_EQ("compiler = c", received_conf_items[n++].descr);
CHECK_STR_EQ("compiler_check = cc", received_conf_items[n++].descr);
CHECK_STR_EQ("compression = true", received_conf_items[n++].descr);
+ CHECK_STR_EQ("compression_level = 8", received_conf_items[n++].descr);
CHECK_STR_EQ("cpp_extension = ce", received_conf_items[n++].descr);
CHECK_STR_EQ("direct_mode = false", received_conf_items[n++].descr);
CHECK_STR_EQ("disable = true", received_conf_items[n++].descr);
diff --git a/util.c b/util.c
index ef2dbec0..db39a120 100644
--- a/util.c
+++ b/util.c
@@ -225,11 +225,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;
@@ -243,8 +243,8 @@ copy_file(const char *src, const char *dest, int compress_dest)
int errnum;
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");
+ cc_log("Copying %s to %s via %s (%scompressed)",
+ src, dest, tmp_name, compress_level > 0 ? "" : "un");
/* open source file */
fd_in = open(src, O_RDONLY | O_BINARY);
@@ -267,7 +267,7 @@ copy_file(const char *src, const char *dest, int compress_dest)
goto error;
}
- if (compress_dest) {
+ if (compress_level > 0) {
/*
* A gzip file occupies at least 20 bytes, so it will always
* occupy an entire filesystem block, even for empty files.
@@ -278,20 +278,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 > 0) {
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 > 0) {
written = gzwrite(gz_out, buf, n);
} else {
ssize_t count;
@@ -305,7 +306,7 @@ copy_file(const char *src, const char *dest, int compress_dest)
} while (written < n);
}
if (written != n) {
- if (compress_dest) {
+ if (compress_level > 0) {
cc_log("gzwrite error: %s (errno: %s)",
gzerror(gz_in, &errnum),
strerror(errno));
@@ -380,11 +381,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);
}
@@ -396,10 +397,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 > 0) {
+ return move_file(src, dest, compress_level);
} else {
return x_rename(src, dest);
}