/* current working directory taken from $PWD, or getcwd() if $PWD is bad */
char *current_working_dir = NULL;
-/* the base cache directory */
-char *cache_dir = NULL;
-
/* the debug logfile name, if set */
char *cache_logfile = NULL;
/*
* Full path to the statistics file in the subdirectory where the cached result
- * belongs (CCACHE_DIR/X/stats).
+ * belongs (<cache_dir>/<x>/stats).
*/
char *stats_file = NULL;
if (path) return path; /* Memoize */
path = getenv("CCACHE_TEMPDIR");
if (!path) {
- path = format("%s/tmp", cache_dir);
+ path = format("%s/tmp", conf->cache_dir);
}
return path;
}
char *path;
char *result;
- path = x_strdup(cache_dir);
+ path = x_strdup(conf->cache_dir);
for (i = 0; i < nlevels; ++i) {
char *p = format("%s/%c", path, name[i]);
free(path);
* This can be almost anywhere, but might as well do it near the end
* as if we exit early we save the stat call
*/
- if (create_cachedirtag(cache_dir) != 0) {
+ if (create_cachedirtag(conf->cache_dir) != 0) {
cc_log("Failed to create %s/CACHEDIR.TAG (%s)\n",
- cache_dir, strerror(errno));
+ conf->cache_dir, strerror(errno));
stats_update(STATS_ERROR);
failed();
}
cached_obj = get_path_in_cache(object_name, ".o");
cached_stderr = get_path_in_cache(object_name, ".stderr");
cached_dep = get_path_in_cache(object_name, ".d");
- stats_file = format("%s/%c/stats", cache_dir, object_name[0]);
+ stats_file = format("%s/%c/stats", conf->cache_dir, object_name[0]);
free(object_name);
}
}
current_working_dir = get_cwd();
- cache_dir = getenv("CCACHE_DIR");
- if (cache_dir) {
- cache_dir = x_strdup(cache_dir);
- } else {
- const char *home_directory = get_home_directory();
- if (home_directory) {
- cache_dir = format("%s/.ccache", home_directory);
- }
- }
}
/* Reset the global state. Used by the test suite. */
{
conf_free(conf); conf = NULL;
free(current_working_dir); current_working_dir = NULL;
- free(cache_dir); cache_dir = NULL;
cache_logfile = NULL;
args_free(orig_args); orig_args = NULL;
free(input_file); input_file = NULL;
case 'c': /* --cleanup */
initialize();
- cleanup_all(cache_dir);
+ cleanup_all(conf->cache_dir);
printf("Cleaned cache\n");
break;
case 'C': /* --clear */
initialize();
- wipe_all(cache_dir);
+ wipe_all(conf->cache_dir);
printf("Cleared cache\n");
break;
*/
#include "ccache.h"
+#include "conf.h"
#include "hashutil.h"
#include <sys/types.h>
#include <unistd.h>
extern char *stats_file;
-extern char *cache_dir;
+extern struct conf *conf;
extern unsigned lock_staleness_limit;
static struct counters *counter_updates;
* A NULL stats_file means that we didn't get past calculate_object_hash(),
* so we just choose one of stats files in the 16 subdirectories.
*/
- if (!cache_dir) return;
- stats_dir = format("%s/%x", cache_dir, hash_from_int(getpid()) % 16);
+ stats_dir = format("%s/%x", conf->cache_dir, hash_from_int(getpid()) % 16);
stats_file = format("%s/stats", stats_dir);
free(stats_dir);
}
char *fname;
if (dir == -1) {
- fname = format("%s/stats", cache_dir);
+ fname = format("%s/stats", conf->cache_dir);
} else {
- fname = format("%s/%1x/stats", cache_dir, dir);
+ fname = format("%s/%1x/stats", conf->cache_dir, dir);
}
stats_read(fname, counters);
}
}
- printf("cache directory %s\n", cache_dir);
+ printf("cache directory %s\n", conf->cache_dir);
/* and display them */
for (i = 0; stats_info[i].message; i++) {
unsigned i;
char *fname;
- fname = format("%s/stats", cache_dir);
+ fname = format("%s/stats", conf->cache_dir);
x_unlink(fname);
free(fname);
for (dir = 0; dir <= 0xF; dir++) {
struct counters *counters = counters_init(STATS_END);
- fname = format("%s/%1x/stats", cache_dir, dir);
+ fname = format("%s/%1x/stats", conf->cache_dir, dir);
if (lockfile_acquire(fname, lock_staleness_limit)) {
stats_read(fname, counters);
for (i = 0; stats_info[i].message; i++) {
for (dir = 0; dir <= 0xF; dir++) {
char *fname, *cdir;
- cdir = format("%s/%1x", cache_dir, dir);
+ cdir = format("%s/%1x", conf->cache_dir, dir);
fname = format("%s/stats", cdir);
free(cdir);