diff options
Diffstat (limited to 'src/ccache.c')
-rw-r--r-- | src/ccache.c | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/src/ccache.c b/src/ccache.c index f56445b..2ad1ed5 100644 --- a/src/ccache.c +++ b/src/ccache.c @@ -280,6 +280,10 @@ struct pending_tmp_file { // Temporary files to remove at program exit. static struct pending_tmp_file *pending_tmp_files = NULL; +// How often (in seconds) to scan $CCACHE_DIR/tmp for left-over temporary +// files. +static const int k_tempdir_cleanup_interval = 2 * 24 * 60 * 60; // 2 days + #ifndef _WIN32 static sigset_t fatal_signal_set; @@ -480,7 +484,8 @@ clean_up_internal_tempdir(void) { time_t now = time(NULL); struct stat st; - if (x_stat(conf->cache_dir, &st) != 0 || st.st_mtime + 3600 >= now) { + if (x_stat(conf->cache_dir, &st) != 0 + || st.st_mtime + k_tempdir_cleanup_interval >= now) { // No cleanup needed. return; } @@ -499,7 +504,8 @@ clean_up_internal_tempdir(void) } char *path = format("%s/%s", temp_dir(), entry->d_name); - if (x_lstat(path, &st) == 0 && st.st_mtime + 3600 < now) { + if (x_lstat(path, &st) == 0 + && st.st_mtime + k_tempdir_cleanup_interval < now) { tmp_unlink(path); } free(path); @@ -1720,7 +1726,10 @@ get_object_name_from_cpp(struct args *args, struct hash *hash) hash_delimiter(hash, "cppstderr"); if (!direct_i_file && !hash_file(hash, path_stderr)) { - fatal("Failed to open %s: %s", path_stderr, strerror(errno)); + // Somebody removed the temporary file? + stats_update(STATS_ERROR); + cc_log("Failed to open %s: %s", path_stderr, strerror(errno)); + failed(); } if (direct_i_file) { @@ -2492,10 +2501,15 @@ detect_pch(const char *option, const char *arg, bool *found_pch) } // Process the compiler options into options suitable for passing to the -// preprocessor and the real compiler. The preprocessor options don't include -// -E; this is added later. Returns true on success, otherwise false. +// preprocessor and the real compiler. preprocessor_args doesn't include -E; +// this is added later. extra_args_to_hash are the arguments that are not +// included in preprocessor_args but that should be included in the hash. +// +// Returns true on success, otherwise false. bool -cc_process_args(struct args *args, struct args **preprocessor_args, +cc_process_args(struct args *args, + struct args **preprocessor_args, + struct args **extra_args_to_hash, struct args **compiler_args) { bool found_c_opt = false; @@ -2825,8 +2839,11 @@ cc_process_args(struct args *args, struct args **preprocessor_args, arg = argv[i + 1]; i++; } else { - // -MFarg + // -MFarg or -MF=arg (EDG-based compilers) arg = &argv[i][3]; + if (arg[0] == '=') { + ++arg; + } } output_dep = make_relative_path(x_strdup(arg)); // Keep the format of the args the same. @@ -3517,7 +3534,7 @@ cc_process_args(struct args *args, struct args **preprocessor_args, if (!dependency_target_specified && !dependency_implicit_target_specified - && !str_eq(get_extension(output_dep), ".o")) { + && !str_eq(get_extension(output_obj), ".o")) { args_add(dep_args, "-MQ"); args_add(dep_args, output_obj); } @@ -3580,6 +3597,10 @@ cc_process_args(struct args *args, struct args **preprocessor_args, *preprocessor_args = args_copy(common_args); args_extend(*preprocessor_args, cpp_args); + if (extra_args_to_hash) { + *extra_args_to_hash = compiler_only_args; + } + out: args_free(expanded_args); args_free(common_args); @@ -3918,10 +3939,14 @@ ccache(int argc, char *argv[]) // Arguments (except -E) to send to the preprocessor. struct args *preprocessor_args; + // Arguments not sent to the preprocessor but that should be part of the + // hash. + struct args *extra_args_to_hash; // Arguments to send to the real compiler. struct args *compiler_args; MTR_BEGIN("main", "process_args"); - if (!cc_process_args(orig_args, &preprocessor_args, &compiler_args)) { + if (!cc_process_args( + orig_args, &preprocessor_args, &extra_args_to_hash, &compiler_args)) { failed(); } MTR_END("main", "process_args"); @@ -3980,13 +4005,16 @@ ccache(int argc, char *argv[]) init_hash_debug( direct_hash, output_obj, 'd', "DIRECT MODE", debug_text_file); + struct args *args_to_hash = args_copy(preprocessor_args); + args_extend(args_to_hash, extra_args_to_hash); + bool put_object_in_manifest = false; struct file_hash *object_hash = NULL; struct file_hash *object_hash_from_manifest = NULL; if (conf->direct_mode) { cc_log("Trying direct lookup"); MTR_BEGIN("hash", "direct_hash"); - object_hash = calculate_object_hash(preprocessor_args, direct_hash, 1); + object_hash = calculate_object_hash(args_to_hash, direct_hash, 1); MTR_END("hash", "direct_hash"); if (object_hash) { update_cached_result_globals(object_hash); @@ -4018,7 +4046,7 @@ ccache(int argc, char *argv[]) cpp_hash, output_obj, 'p', "PREPROCESSOR MODE", debug_text_file); MTR_BEGIN("hash", "cpp_hash"); - object_hash = calculate_object_hash(preprocessor_args, cpp_hash, 0); + object_hash = calculate_object_hash(args_to_hash, cpp_hash, 0); MTR_END("hash", "cpp_hash"); if (!object_hash) { fatal("internal error: object hash from cpp returned NULL"); |