This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] color diagnostics markers


On Mon, Apr 15, 2013 at 04:14:58AM -0500, Gabriel Dos Reis wrote:
> > Defining a variable in my environment counts as a clear intention.
> 
> If you invoke GCC on command line with explicit option requesting
> colors, I don't think there is any doubt that.  However, I dispute the
> intent to be so universally clear for most GCC users who happen to have
> GCC_COLORS set -- most users inherit whatever their sysadmin or
> distros set for them.
> 
> That said, I am fine with the idea to GCC_COLORS => detect.

Here is a patch that implements it.
If GCC_COLORS isn't in the environment, the default is still
-fdiagnostics-color=never, otherwise it is -fdiagnostics-color=auto
(but, as before, if GCC_COLORS is in the environment, but empty,
colors aren't shown at all).

Bootstrapped/regtested on x86_64-linux and i686-linux, additionally tested
on a few testcases with make check when GCC_COLORS was in the environment,
and additionally tested with RUNTESTFLAGS='--target_board=unix/-fdiagnostics-color=always dg.exp=pr56*.c'
where only the last one showed some (expected) regressions, because that
forces over colors even for the tests.  Ok for trunk?

2013-04-15  Jakub Jelinek  <jakub@redhat.com>

	* Makefile.in (toplev.o): Depend on diagnostic-color.h.
	* diagnostic-color.c (should_colorize): Remove _WIN32 version.
	(colorize_init): Add argument to _WIN32 version.
	* toplev.c: Include diagnostic-color.h.
	(process_options): Default to -fdiagnostics-color=auto if
	GCC_COLORS env var is in the environment.
	* common.opt (fdiagnostics-color=): Add Var and Init.
	* doc/invoke.texi (-fdiagnostics-color=): Document that if
	GCC_COLORS env var is in the environment, the default is auto
	rather than never.

	* lib/prune.exp: Add -fdiagnostics-color=never to TEST_ALWAYS_FLAGS.
	* lib/c-compat.exp (compat-use-alt-compiler, compat_setup_dfp): Handle
	-fdiagnostics-color=never option similarly to
	-fno-diagnostics-show-caret option.

--- gcc/Makefile.in.jj	2013-04-12 08:13:22.000000000 +0200
+++ gcc/Makefile.in	2013-04-12 08:13:22.000000000 +0200
@@ -2710,7 +2710,7 @@ toplev.o : toplev.c $(CONFIG_H) $(SYSTEM
    $(OPTS_H) params.def tree-mudflap.h $(TREE_PASS_H) $(GIMPLE_H) \
    tree-ssa-alias.h $(PLUGIN_H) realmpfr.h tree-diagnostic.h \
    $(TREE_PRETTY_PRINT_H) opts-diagnostic.h $(COMMON_TARGET_H) \
-   tsan.h
+   tsan.h diagnostic-color.h
 
 hwint.o : hwint.c $(CONFIG_H) $(SYSTEM_H) $(DIAGNOSTIC_CORE_H)
 
--- gcc/diagnostic-color.c.jj	2013-04-12 08:13:22.000000000 +0200
+++ gcc/diagnostic-color.c	2013-04-15 13:00:41.978114658 +0200
@@ -264,14 +264,8 @@ parse_gcc_colors (void)
 }
 
 #if defined(_WIN32)
-static bool
-should_colorize (void)
-{
-  return false;
-}
-
 bool
-colorize_init (void)
+colorize_init (diagnostic_color_rule_t)
 {
   return false;
 }
--- gcc/doc/invoke.texi.jj	2013-04-12 08:13:22.000000000 +0200
+++ gcc/doc/invoke.texi	2013-04-15 13:41:42.869556167 +0200
@@ -2963,9 +2963,10 @@ a message which is too long to fit on a
 @cindex highlight, color, colour
 @vindex GCC_COLORS @r{environment variable}
 Use color in diagnostics.  @var{WHEN} is @samp{never}, @samp{always},
-or @samp{auto}.  The default is @samp{never}, @samp{auto} means to use color
-only when the standard error is a terminal. The forms
-@option{-fdiagnostics-color} and @option{-fno-diagnostics-color} are
+or @samp{auto}.  The default is @samp{never} if @env{GCC_COLORS} environment
+variable isn't present in the environment, and @samp{auto} otherwise.
+@samp{auto} means to use color only when the standard error is a terminal.
+The forms @option{-fdiagnostics-color} and @option{-fno-diagnostics-color} are
 aliases for @option{-fdiagnostics-color=always} and
 @option{-fdiagnostics-color=never}, respectively.
 
--- gcc/testsuite/lib/prune.exp.jj	2013-01-11 09:02:39.000000000 +0100
+++ gcc/testsuite/lib/prune.exp	2013-04-15 13:36:49.275191326 +0200
@@ -19,7 +19,7 @@
 if ![info exists TEST_ALWAYS_FLAGS] {
     set TEST_ALWAYS_FLAGS ""
 }
-set TEST_ALWAYS_FLAGS "-fno-diagnostics-show-caret $TEST_ALWAYS_FLAGS"
+set TEST_ALWAYS_FLAGS "-fno-diagnostics-show-caret -fdiagnostics-color=never $TEST_ALWAYS_FLAGS"
 
 proc prune_gcc_output { text } {
     #send_user "Before:$text\n"
--- gcc/testsuite/lib/c-compat.exp.jj	2013-01-11 09:02:39.000000000 +0100
+++ gcc/testsuite/lib/c-compat.exp	2013-04-15 13:38:36.361596471 +0200
@@ -34,7 +34,7 @@ load_lib target-supports.exp
 # 
 proc compat-use-alt-compiler { } {
     global GCC_UNDER_TEST ALT_CC_UNDER_TEST
-    global compat_same_alt compat_alt_caret
+    global compat_same_alt compat_alt_caret compat_alt_color
     global TEST_ALWAYS_FLAGS
 
     # We don't need to do this if the alternate compiler is actually
@@ -44,6 +44,9 @@ proc compat-use-alt-compiler { } {
 	if { $compat_alt_caret == 0 } then {
 	    regsub -- "-fno-diagnostics-show-caret" $TEST_ALWAYS_FLAGS "" TEST_ALWAYS_FLAGS
 	}
+	if { $compat_alt_color == 0 } then {
+	    regsub -- "-fdiagnostics-color=never" $TEST_ALWAYS_FLAGS "" TEST_ALWAYS_FLAGS
+	}
     }
 }
 
@@ -70,9 +73,11 @@ proc compat_setup_dfp { } {
     global compat_same_alt
     global compat_have_dfp
     global compat_alt_caret
+    global compat_alt_color
     global TEST_ALWAYS_FLAGS compat_save_TEST_ALWAYS_FLAGS
 
     set compat_alt_caret 0
+    set compat_alt_color 0
     set compat_save_TEST_ALWAYS_FLAGS $TEST_ALWAYS_FLAGS
 
     verbose "compat_setup_dfp: $compat_use_alt $compat_same_alt" 2
@@ -88,6 +93,10 @@ proc compat_setup_dfp { } {
 		int dummy; } "-fno-diagnostics-show-caret"] != 0 } {
 	    set compat_alt_caret 1
 	}
+	if { [check_no_compiler_messages_nocache compat_alt_has_color object {
+		int dummy; } "-fdiagnostics-color=never"] != 0 } {
+	    set compat_alt_color 1
+	}
 	compat-use-tst-compiler
     }
 
--- gcc/toplev.c.jj	2013-04-08 15:38:20.000000000 +0200
+++ gcc/toplev.c	2013-04-15 13:12:53.757005505 +0200
@@ -74,6 +74,7 @@ along with GCC; see the file COPYING3.
 #include "gimple.h"
 #include "tree-ssa-alias.h"
 #include "plugin.h"
+#include "diagnostic-color.h"
 
 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
 #include "dbxout.h"
@@ -1209,6 +1210,13 @@ process_options (void)
 
   maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT;
 
+  /* Default to -fdiagnostics-color=auto if GCC_COLORS is in the environment,
+     otherwise default to -fdiagnostics-color=never.  */
+  if (!global_options_set.x_flag_diagnostics_show_color
+      && getenv ("GCC_COLORS"))
+    pp_show_color (global_dc->printer)
+      = colorize_init (DIAGNOSTICS_COLOR_AUTO);
+
   /* Allow the front end to perform consistency checks and do further
      initialization based on the command line options.  This hook also
      sets the original filename if appropriate (e.g. foo.i -> foo.c)
--- gcc/common.opt.jj	2013-04-12 08:13:22.000000000 +0200
+++ gcc/common.opt	2013-04-15 13:07:59.112638039 +0200
@@ -1033,7 +1033,7 @@ Common Alias(fdiagnostics-color=,always,
 ;
 
 fdiagnostics-color=
-Common Joined RejectNegative Enum(diagnostic_color_rule)
+Common Joined RejectNegative Var(flag_diagnostics_show_color) Enum(diagnostic_color_rule) Init(DIAGNOSTICS_COLOR_NO)
 -fdiagnostics-color=[never|always|auto]	Colorize diagnostics
 
 ; Required for these enum values.


	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]