void set_max_size(uint64_t value);
void set_run_second_cpp(bool value);
+ const std::string& primary_config_path() const;
+ const std::string& secondary_config_path() const;
+ void set_primary_config_path(std::string path);
+ void set_secondary_config_path(std::string path);
+
typedef std::function<void(const std::string& key,
const std::string& value,
const std::string& origin)>
const std::string& value);
private:
+ std::string m_primary_config_path;
+ std::string m_secondary_config_path;
+
std::string m_base_dir = "";
std::string m_cache_dir = fmt::format("{}/.ccache", get_home_directory());
uint32_t m_cache_dir_levels = 2;
using nonstd::string_view;
// Global variables used by other compilation units.
-extern char* primary_config_path;
-extern char* secondary_config_path;
extern char* current_working_dir;
extern char* stats_file;
extern unsigned lock_staleness_limit;
"\n"
"See also <https://ccache.dev>.\n";
-// Where to write configuration changes.
-char* primary_config_path = NULL;
-
-// Secondary, read-only configuration file (if any).
-char* secondary_config_path = NULL;
-
// Current working directory taken from $PWD, or getcwd() if $PWD is bad.
char* current_working_dir = NULL;
}
static void
-create_initial_config_file(const char* path)
+create_initial_config_file(const std::string& path)
{
if (!Util::create_dir(Util::dir_name(path))) {
return;
}
free(stats_dir);
- FILE* f = fopen(path, "w");
+ FILE* f = fopen(path.c_str(), "w");
if (!f) {
return;
}
char* p = getenv("CCACHE_CONFIGPATH");
if (p) {
- primary_config_path = x_strdup(p);
+ g_config.set_primary_config_path(p);
} else {
- secondary_config_path = format("%s/ccache.conf", TO_STRING(SYSCONFDIR));
+ g_config.set_secondary_config_path(
+ fmt::format("{}/ccache.conf", TO_STRING(SYSCONFDIR)));
MTR_BEGIN("config", "conf_read_secondary");
// A missing config file in SYSCONFDIR is OK so don't check return value.
- g_config.update_from_file(secondary_config_path);
+ g_config.update_from_file(g_config.secondary_config_path());
MTR_END("config", "conf_read_secondary");
if (g_config.cache_dir().empty()) {
fatal("CCACHE_DIR must not be the empty string");
}
- primary_config_path =
- format("%s/ccache.conf", g_config.cache_dir().c_str());
+ g_config.set_primary_config_path(
+ fmt::format("{}/ccache.conf", g_config.cache_dir()));
}
bool should_create_initial_config = false;
MTR_BEGIN("config", "conf_read_primary");
- if (!g_config.update_from_file(primary_config_path) && !g_config.disable()) {
+ if (!g_config.update_from_file(g_config.primary_config_path())
+ && !g_config.disable()) {
should_create_initial_config = true;
}
MTR_END("config", "conf_read_primary");
MTR_END("config", "conf_update_from_environment");
if (should_create_initial_config) {
- create_initial_config_file(primary_config_path);
+ create_initial_config_file(g_config.primary_config_path());
}
exitfn_init();
{
g_config = Config();
- free_and_nullify(primary_config_path);
- free_and_nullify(secondary_config_path);
free_and_nullify(current_working_dir);
for (size_t i = 0; i < debug_prefix_maps_len; i++) {
free_and_nullify(debug_prefix_maps[i]);
case 'F': { // --max-files
initialize();
- g_config.set_value_in_file(primary_config_path, "max_files", optarg);
+ g_config.set_value_in_file(
+ g_config.primary_config_path(), "max_files", optarg);
unsigned files = atoi(optarg);
if (files == 0) {
printf("Unset cache file limit\n");
if (!parse_size_with_suffix(optarg, &size)) {
fatal("invalid size: %s", optarg);
}
- g_config.set_value_in_file(primary_config_path, "max_size", optarg);
+ g_config.set_value_in_file(
+ g_config.primary_config_path(), "max_size", optarg);
if (size == 0) {
printf("Unset cache size limit\n");
} else {
}
char* key = x_strndup(optarg, p - optarg);
char* value = p + 1;
- g_config.set_value_in_file(primary_config_path, key, value);
+ g_config.set_value_in_file(g_config.primary_config_path(), key, value);
free(key);
break;
}
extern char* stats_file;
extern unsigned lock_staleness_limit;
-extern char* primary_config_path;
-extern char* secondary_config_path;
static struct counters* counter_updates;
time_t last_updated;
stats_collect(counters, &last_updated);
- printf("cache directory %s\n",
- g_config.cache_dir().c_str());
- printf("primary config %s\n",
- primary_config_path ? primary_config_path : "");
- printf("secondary config (readonly) %s\n",
- secondary_config_path ? secondary_config_path : "");
+ fmt::print("cache directory {}\n", g_config.cache_dir());
+ fmt::print("primary config {}\n",
+ g_config.primary_config_path());
+ fmt::print("secondary config (readonly) {}\n",
+ g_config.secondary_config_path());
if (last_updated > 0) {
struct tm tm;
localtime_r(&last_updated, &tm);