From: Joel Rosdahl Date: Thu, 14 Jul 2011 19:35:28 +0000 (+0200) Subject: config: Use cache_dir_levels from conf struct X-Git-Tag: v3.2~239 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ebae5f7182b30d358eeb915f4edface74fb945ce;p=thirdparty%2Fccache.git config: Use cache_dir_levels from conf struct --- diff --git a/ccache.c b/ccache.c index 212155c6a..9b44fcac9 100644 --- a/ccache.c +++ b/ccache.c @@ -169,9 +169,6 @@ static bool enable_direct = true; */ static bool enable_compression = false; -/* number of levels (1 <= nlevels <= 8) */ -static int nlevels = 2; - /* * Whether we should use the optimization of passing the already existing * preprocessed source code to the compiler. @@ -296,18 +293,18 @@ temp_dir() static char * get_path_in_cache(const char *name, const char *suffix) { - int i; + unsigned i; char *path; char *result; path = x_strdup(conf->cache_dir); - for (i = 0; i < nlevels; ++i) { + for (i = 0; i < conf->cache_dir_levels; ++i) { char *p = format("%s/%c", path, name[i]); free(path); path = p; } - result = format("%s/%s%s", path, name + nlevels, suffix); + result = format("%s/%s%s", path, name + conf->cache_dir_levels, suffix); free(path); return result; } @@ -1896,7 +1893,6 @@ cc_reset(void) enable_unify = false; enable_direct = true; enable_compression = false; - nlevels = 2; compile_preprocessed_source_code = false; output_is_precompiled_header = false; @@ -1963,7 +1959,6 @@ ccache(int argc, char *argv[]) bool put_object_in_manifest = false; struct file_hash *object_hash; struct file_hash *object_hash_from_manifest = NULL; - char *env; struct mdfour common_hash; struct mdfour direct_hash; struct mdfour cpp_hash; @@ -2012,12 +2007,6 @@ ccache(int argc, char *argv[]) enable_compression = true; } - if ((env = getenv("CCACHE_NLEVELS"))) { - nlevels = atoi(env); - if (nlevels < 1) nlevels = 1; - if (nlevels > 8) nlevels = 8; - } - if (!cc_process_args(orig_args, &preprocessor_args, &compiler_args)) { failed(); } diff --git a/conf.c b/conf.c index ded2f18e6..6bc8a85ed 100644 --- a/conf.c +++ b/conf.c @@ -160,6 +160,19 @@ verify_absolute_path(void *value, char **errmsg) } } +static bool +verify_dir_levels(void *value, char **errmsg) +{ + unsigned *levels = (unsigned *)value; + assert(levels); + if (*levels >= 1 && *levels <= 8) { + return true; + } else { + *errmsg = format("cache directory levels must be between 1 and 8"); + return false; + } +} + #define ITEM(name, type) \ {#name, parse_##type, offsetof(struct conf, name), NULL} #define ITEM_V(name, type, verification) \ @@ -168,7 +181,7 @@ verify_absolute_path(void *value, char **errmsg) static const struct conf_item conf_items[] = { ITEM_V(base_dir, env_string, absolute_path), ITEM(cache_dir, env_string), - ITEM(cache_dir_levels, unsigned), + ITEM_V(cache_dir_levels, unsigned, dir_levels), ITEM(compiler, string), ITEM(compiler_check, string), ITEM(compression, bool), diff --git a/test/test_conf.c b/test/test_conf.c index 60393f999..6ca5629b2 100644 --- a/test/test_conf.c +++ b/test/test_conf.c @@ -265,4 +265,21 @@ TEST(verify_absolute_base_dir) conf_free(conf); } +TEST(verify_dir_levels) +{ + struct conf *conf = conf_create(); + char *errmsg; + + create_file("ccache.conf", "cache_dir_levels = 0"); + CHECK(!conf_read(conf, "ccache.conf", &errmsg)); + CHECK_STR_EQ_FREE2("ccache.conf:1: cache directory levels must be between 1 and 8", + errmsg); + create_file("ccache.conf", "cache_dir_levels = 9"); + CHECK(!conf_read(conf, "ccache.conf", &errmsg)); + CHECK_STR_EQ_FREE2("ccache.conf:1: cache directory levels must be between 1 and 8", + errmsg); + + conf_free(conf); +} + TEST_SUITE_END