]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Handle properly color diagnostics also in depend mode (#484)
authorLuboš Luňák <l.lunak@centrum.cz>
Thu, 14 Nov 2019 19:23:03 +0000 (20:23 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 14 Nov 2019 19:34:50 +0000 (20:34 +0100)
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)

src/ccache.c

index 00d35a36a94942868550048e5ff0462545d6a5eb..7857be4adb5ce84d6fca3ceacef689d8678ab069 100644 (file)
@@ -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;