diff options
author | Luboš Luňák <l.lunak@centrum.cz> | 2019-11-14 20:23:03 +0100 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2019-11-14 20:34:50 +0100 |
commit | 95e2df8d14d36714cea2105673709166514cffd7 (patch) | |
tree | 5925b3ee61219f1aab14cf3ed94b10300c99ba23 | |
parent | fc3c84ce9bce8444b239246eb8f8f03030f62bba (diff) | |
download | ccache-95e2df8d14d36714cea2105673709166514cffd7.tar.gz |
Handle properly color diagnostics also in depend mode (#484)
Compiler invocation in the depend mode uses the original arguments,
which means the added -fcolor-diagnostics (or -fdiagnostics-color)
was dropped.
(cherry picked from commit 061e57ced8abfd31d7eb41924d64e0765e806d89)
-rw-r--r-- | src/ccache.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/ccache.c b/src/ccache.c index 00d35a36..7857be4a 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; @@ -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); @@ -3102,6 +3120,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]); @@ -3509,6 +3528,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) { @@ -3518,6 +3538,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"); } } @@ -3820,6 +3841,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; |