diff options
author | JinWang An <jinwang.an@samsung.com> | 2021-08-03 16:28:49 +0900 |
---|---|---|
committer | JinWang An <jinwang.an@samsung.com> | 2021-08-03 16:28:49 +0900 |
commit | 4054b9513e8603b7750db35cb4602bf071c7077c (patch) | |
tree | 73451a7e6495f9b0a770c41274229a2e9217a679 /src/ccache.c | |
parent | 39332268d5f0d0365f2083a4fa882fed18c0bb0e (diff) | |
download | ccache-41d8df8028f93d8747f13e5c0c767891d03547f3.tar.gz ccache-41d8df8028f93d8747f13e5c0c767891d03547f3.tar.bz2 ccache-41d8df8028f93d8747f13e5c0c767891d03547f3.zip |
Imported Upstream version 3.7.6upstream/3.7.6
Diffstat (limited to 'src/ccache.c')
-rw-r--r-- | src/ccache.c | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/src/ccache.c b/src/ccache.c index 2ad1ed5..dbfd821 100644 --- a/src/ccache.c +++ b/src/ccache.c @@ -104,6 +104,9 @@ char *current_working_dir = NULL; // The original argument list. static struct args *orig_args; +// Argument list to add to compiler invocation in depend mode. +static struct args *depend_extra_args; + // The source file. static char *input_file; @@ -331,6 +334,18 @@ add_prefix(struct args *args, char *prefix_command) args_free(prefix); } +// Compiler in depend mode is invoked with the original arguments. +// Collect extra arguments that should be added. +static void +add_extra_arg(const char *arg) +{ + if (conf->depend_mode) { + if (depend_extra_args == NULL) { + depend_extra_args = args_init(0, NULL); + } + args_add(depend_extra_args, arg); + } +} static void failed(void) ATTR_NORETURN; @@ -485,7 +500,7 @@ clean_up_internal_tempdir(void) time_t now = time(NULL); struct stat st; if (x_stat(conf->cache_dir, &st) != 0 - || st.st_mtime + k_tempdir_cleanup_interval >= now) { + || st.st_mtime + k_tempdir_cleanup_interval >= now) { // No cleanup needed. return; } @@ -505,7 +520,7 @@ clean_up_internal_tempdir(void) char *path = format("%s/%s", temp_dir(), entry->d_name); if (x_lstat(path, &st) == 0 - && st.st_mtime + k_tempdir_cleanup_interval < now) { + && st.st_mtime + k_tempdir_cleanup_interval < now) { tmp_unlink(path); } free(path); @@ -1459,6 +1474,9 @@ to_cache(struct args *args, struct hash *depend_mode_hash) assert(orig_args); struct args *depend_mode_args = args_copy(orig_args); args_strip(depend_mode_args, "--ccache-"); + if (depend_extra_args) { + args_extend(depend_mode_args, depend_extra_args); + } add_prefix(depend_mode_args, conf->prefix_command); time_of_compilation = time(NULL); @@ -2216,12 +2234,19 @@ calculate_object_hash(struct args *args, struct hash *hash, int direct_mode) } } - if (!(conf->sloppiness & SLOPPY_FILE_MACRO)) { - // The source code file or an include file may contain __FILE__, so make - // sure that the hash is unique for the file name. - hash_delimiter(hash, "inputfile"); - hash_string(hash, input_file); - } + // Make sure that the direct mode hash is unique for the input file path. + // If this would not be the case: + // + // * An false cache hit may be produced. Scenario: + // - a/r.h exists. + // - a/x.c has #include "r.h". + // - b/x.c is identical to a/x.c. + // - Compiling a/x.c records a/r.h in the manifest. + // - Compiling b/x.c results in a false cache hit since a/x.c and b/x.c + // share manifests and a/r.h exists. + // * The expansion of __FILE__ may be incorrect. + hash_delimiter(hash, "inputfile"); + hash_string(hash, input_file); hash_delimiter(hash, "sourcecode"); int result = hash_source_code_file(conf, hash, input_file); @@ -2649,7 +2674,9 @@ cc_process_args(struct args *args, } // These are always too hard. - if (compopt_too_hard(argv[i]) || str_startswith(argv[i], "-fdump-")) { + if (compopt_too_hard(argv[i]) + || str_startswith(argv[i], "-fdump-") + || str_startswith(argv[i], "-MJ")) { cc_log("Compiler option %s is unsupported", argv[i]); stats_update(STATS_UNSUPPORTED_OPTION); result = false; @@ -3100,6 +3127,7 @@ cc_process_args(struct args *args, if (color_output_possible()) { // Output is redirected, so color output must be forced. args_add(common_args, "-fdiagnostics-color=always"); + add_extra_arg("-fdiagnostics-color=always"); cc_log("Automatically forcing colors"); } else { args_add(common_args, argv[i]); @@ -3507,6 +3535,7 @@ cc_process_args(struct args *args, if (guessed_compiler == GUESSED_CLANG) { if (!str_eq(actual_language, "assembler")) { args_add(common_args, "-fcolor-diagnostics"); + add_extra_arg("-fcolor-diagnostics"); cc_log("Automatically enabling colors"); } } else if (guessed_compiler == GUESSED_GCC) { @@ -3516,6 +3545,7 @@ cc_process_args(struct args *args, // colors. if (getenv("GCC_COLORS") && getenv("GCC_COLORS")[0] != '\0') { args_add(common_args, "-fdiagnostics-color"); + add_extra_arg("-fdiagnostics-color"); cc_log("Automatically enabling colors"); } } @@ -3818,6 +3848,7 @@ cc_reset(void) sanitize_blacklists_len = 0; free(included_pch_file); included_pch_file = NULL; args_free(orig_args); orig_args = NULL; + args_free(depend_extra_args); depend_extra_args = NULL; free(input_file); input_file = NULL; free(output_obj); output_obj = NULL; free(output_dep); output_dep = NULL; |