*/
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.
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;
}
enable_unify = false;
enable_direct = true;
enable_compression = false;
- nlevels = 2;
compile_preprocessed_source_code = false;
output_is_precompiled_header = false;
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;
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();
}
}
}
+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) \
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),
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