]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
config: Use cache_dir_levels from conf struct
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 14 Jul 2011 19:35:28 +0000 (21:35 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 17 Jul 2011 09:57:51 +0000 (11:57 +0200)
ccache.c
conf.c
test/test_conf.c

index 212155c6abcd0ffce44fc5fa5af8f397fb453d18..9b44fcac9b16d4dfab7c0796b8b0696a1c732d69 100644 (file)
--- 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 ded2f18e6a4fb97a5c006ba5f4297640a72b5616..6bc8a85ed8d81b9d3c1a376b19ea8215a3ec3f5a 100644 (file)
--- 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),
index 60393f9999acb864302a5f812874313663717781..6ca5629b27aed8eeae74486b48d55413a392c170 100644 (file)
@@ -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