Lines 1065-1070
Link Here
|
1065 |
} |
1065 |
} |
1066 |
|
1066 |
|
1067 |
/* |
1067 |
/* |
|
|
1068 |
* Note that these compiler checks are unreliable, so nothing should hard-depend on them. |
1069 |
*/ |
1070 |
|
1071 |
static bool compiler_is_clang() |
1072 |
{ |
1073 |
const char* name = strrchr( orig_args->argv[ 0 ], '/' ); |
1074 |
name = name ? name + 1 : orig_args->argv[ 0 ]; |
1075 |
return strstr( name, "clang" ) != NULL; |
1076 |
} |
1077 |
|
1078 |
static bool compiler_is_gcc() |
1079 |
{ |
1080 |
const char* name = strrchr(orig_args->argv[ 0 ], '/' ); |
1081 |
name = name ? name + 1 : orig_args->argv[ 0 ]; |
1082 |
return strstr(name, "gcc") != NULL || strstr(name, "g++") != NULL; |
1083 |
} |
1084 |
|
1085 |
/* |
1068 |
* Update a hash sum with information common for the direct and preprocessor |
1086 |
* Update a hash sum with information common for the direct and preprocessor |
1069 |
* modes. |
1087 |
* modes. |
1070 |
*/ |
1088 |
*/ |
Lines 1128-1133
Link Here
|
1128 |
} |
1146 |
} |
1129 |
free(p); |
1147 |
free(p); |
1130 |
} |
1148 |
} |
|
|
1149 |
|
1150 |
/* Possibly hash GCC_COLORS (for color diagnostics). */ |
1151 |
if (compiler_is_gcc()) { |
1152 |
const char* gcc_colors = getenv("GCC_COLORS"); |
1153 |
if (gcc_colors != NULL) { |
1154 |
hash_delimiter(hash,"gcccolors"); |
1155 |
hash_string(hash, gcc_colors); |
1156 |
} |
1157 |
} |
1131 |
} |
1158 |
} |
1132 |
|
1159 |
|
1133 |
/* |
1160 |
/* |
Lines 1626-1631
Link Here
|
1626 |
|| str_eq(get_extension(path), ".pth"); |
1653 |
|| str_eq(get_extension(path), ".pth"); |
1627 |
} |
1654 |
} |
1628 |
|
1655 |
|
|
|
1656 |
static bool color_output_possible() |
1657 |
{ |
1658 |
const char* term_env = getenv("TERM"); |
1659 |
|
1660 |
return term_env && strcasecmp(term_env, "DUMB") != 0; |
1661 |
} |
1662 |
|
1629 |
/* |
1663 |
/* |
1630 |
* Process the compiler options into options suitable for passing to the |
1664 |
* Process the compiler options into options suitable for passing to the |
1631 |
* preprocessor and the real compiler. The preprocessor options don't include |
1665 |
* preprocessor and the real compiler. The preprocessor options don't include |
Lines 1654-1659
Link Here
|
1654 |
int argc; |
1688 |
int argc; |
1655 |
char **argv; |
1689 |
char **argv; |
1656 |
bool result = true; |
1690 |
bool result = true; |
|
|
1691 |
bool found_color_diagnostics = false; |
1657 |
|
1692 |
|
1658 |
expanded_args = args_copy(args); |
1693 |
expanded_args = args_copy(args); |
1659 |
stripped_args = args_init(0, NULL); |
1694 |
stripped_args = args_init(0, NULL); |
Lines 2010-2015
Link Here
|
2010 |
free(arg); |
2045 |
free(arg); |
2011 |
} |
2046 |
} |
2012 |
|
2047 |
|
|
|
2048 |
if (str_eq(argv[i], "-fcolor-diagnostics") |
2049 |
|| str_eq(argv[i], "-fno-color-diagnostics") |
2050 |
|| str_eq(argv[i], "-fdiagnostics-color") |
2051 |
|| str_eq(argv[i], "-fdiagnostics-color=always") |
2052 |
|| str_eq(argv[i], "-fno-diagnostics-color") |
2053 |
|| str_eq(argv[i], "-fdiagnostics-color=never")) { |
2054 |
args_add(stripped_args, argv[i]); |
2055 |
found_color_diagnostics = true; |
2056 |
continue; |
2057 |
} |
2058 |
if (str_eq(argv[i], "-fdiagnostics-color=auto")) { |
2059 |
|
2060 |
/* auto means to use colours only when standard error is a terminal */ |
2061 |
if (color_output_possible()) { |
2062 |
/* Since the condition is verified, we force the colour output */ |
2063 |
args_add(stripped_args, "-fdiagnostics-color"); |
2064 |
found_color_diagnostics = true; |
2065 |
} |
2066 |
continue; |
2067 |
} |
2068 |
|
2013 |
/* |
2069 |
/* |
2014 |
* Options taking an argument that we may want to rewrite to relative paths |
2070 |
* Options taking an argument that we may want to rewrite to relative paths |
2015 |
* to get better hit rate. A secondary effect is that paths in the standard |
2071 |
* to get better hit rate. A secondary effect is that paths in the standard |
Lines 2298-2303
Link Here
|
2298 |
args_add(cpp_args, explicit_language); |
2354 |
args_add(cpp_args, explicit_language); |
2299 |
} |
2355 |
} |
2300 |
|
2356 |
|
|
|
2357 |
/* |
2358 |
* Since output is redirected, compilers will not color their output by default, |
2359 |
* so force it explicitly if it would be otherwise done. |
2360 |
*/ |
2361 |
if (!found_color_diagnostics && color_output_possible()) { |
2362 |
if (compiler_is_clang()) { |
2363 |
args_add(stripped_args, "-fcolor-diagnostics"); |
2364 |
cc_log("Automatically enabling colors"); |
2365 |
} else if (compiler_is_gcc()) { |
2366 |
/* |
2367 |
* GCC has colour support since 4.9. Adding the option to an |
2368 |
* earlier version of GCC will make the compiler fail. |
2369 |
* This test enables colours if GCC_COLORS is present in the |
2370 |
* environment, but does not check if diagnostics-color is available. |
2371 |
*/ |
2372 |
if (getenv("GCC_COLORS") != NULL && getenv("GCC_COLORS")[ 0 ] != '\0') { |
2373 |
args_add(stripped_args, "-fdiagnostics-color"); |
2374 |
cc_log("Automatically enabling colors"); |
2375 |
} |
2376 |
} |
2377 |
} |
2378 |
|
2301 |
/* |
2379 |
/* |
2302 |
* Add flags for dependency generation only to the preprocessor command line. |
2380 |
* Add flags for dependency generation only to the preprocessor command line. |
2303 |
*/ |
2381 |
*/ |