diff mbox series

Add --with-diagnostics-urls configuration option and GCC_URLS env var

Message ID 20191219202419.31099-1-dmalcolm@redhat.com
State New
Headers show
Series Add --with-diagnostics-urls configuration option and GCC_URLS env var | expand

Commit Message

David Malcolm Dec. 19, 2019, 8:24 p.m. UTC
On Mon, 2019-12-16 at 10:39 +0800, 王昊然 wrote:
> > Which revision of gcc is this?
> Using built-in specs.
> COLLECT_GCC=/opt/gcc-10.0-20191208/bin/gcc-10.0-20191208
> COLLECT_LTO_WRAPPER=/opt/gcc-10.0-20191208/bin/../lib/gcc/x86_64-pc-
> linux-gnu/10.0.0/lto-wrapper
> Target: x86_64-pc-linux-gnu
> Configured with: ../gcc-10-20191208/configure --prefix=/usr/local
> --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/local/lib'
> --enable-version-specific-runtime-libs --disable-rpath
> --with-system-zlib --enable-gnu-unique-object
> --enable-languages=c,c++,objc,obj-c++,fortran,lto --enable-plugin
> --enable-initfini-array --enable-gnu-indirect-function
> --program-suffix=-10.0-20191208
> Thread model: posix
> Supported LTO compression algorithms: zlib
> gcc version 10.0.0 20191208 (experimental) (GCC)

Thanks.  That version includes r279073:

2019-12-07  Tobias Burnus  <tobias@codesourcery.com>
           David Malcolm  <dmalcolm@redhat.com>
           Jakub Jelinek  <jakub@redhat.com>

       PR c/87488
       * pretty-print.c (pp_begin_url, pp_end_url, test_urls): Use BEL
       instead of ST sequence to terminate OSC 8 strings.

> > Which terminal are you using, and what version?
> libvte 2.90.
> Also tested on MATE Terminal 1.16.3 and Terminator 1.90, showing
> garbled outputs on warning lines and beeps.
> Tested on xfce4-terminal 0.8.3, it produces no beep but garbled
> outputs; however I think this is due to broken terminal bell support
> of xfce4-terminal in my system.

It seems that we need a configuration option for this.

> 2019-12-15 23:09 GMT+08:00, David Malcolm <dmalcolm@redhat.com>:
> > On Sun, 2019-12-15 at 19:38 +0800, 王昊然 wrote:
> > > This patch has made my terminal beeps on every warning message,
> > > which
> > > is so noisy.
> > 
> > Sorry about this.
> > 
> > > May be this feature should be disabled by default, unless enabled
> > > by
> > > configure time option, runtime option or runtime environment
> > > variables.
> > 
> > Which revision of gcc is this?
> > 
> > Which terminal are you using, and what version?
> > 
> > 
> > Thanks
> > David
> > 
> >

Currently -fdiagnostics-urls defaults to "auto" and this works
(e.g. for recent gnome-terminal, and is gracefully discarded by
konsole5), but there have been reports of incompatibilities of the
feature with various other terminals.

This patch adds a configuration option to change this default, based
on Jakub's analogous change to -fdiagnostics-color (r217540).  One
possible configure-time option is --with-diagnostics-urls=auto-if-env,
which adds support for a GCC_URLS environment variable to control
the default (again by analogy with the --with-diagnostics-color
configure-time support for changing -fdiagnostics-color).

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu; I
tested the --with-diagnostics-urls=auto-if-env and GCC_URLS behavior
manually.

Jakub: does this look sane to you?  (given that this is heavily based
on your 2014 patches for --with-diagnostics-color).

Thanks
Dave

gcc/ChangeLog:
	PR 87488
	* configure.ac (--with-diagnostics-urls): New configuration
	option, based on --with-diagnostics-color.
	(DIAGNOSTICS_URLS_DEFAULT): New define.
	* config.h: Regenerate.
	* configure: Regenerate.
	* diagnostic.c (diagnostic_urls_init): Handle -1 for
	DIAGNOSTICS_URLS_DEFAULT from configure-time
	--with-diagnostics-urls=auto-if-env by querying for a GCC_URLS
	environment variable.
	* doc/install.texi (--with-diagnostics-urls): Document new
	configuration option.
	* doc/invoke.texi (-fdiagnostics-urls): Add GCC_URLS vindex
	reference.  Update description of defaults based on the above.
---
 gcc/configure.ac     | 28 ++++++++++++++++++++++++++++
 gcc/diagnostic.c     | 17 ++++++++++++++++-
 gcc/doc/install.texi |  9 +++++++++
 gcc/doc/invoke.texi  | 10 ++++++++--
 4 files changed, 61 insertions(+), 3 deletions(-)

Comments

Jakub Jelinek Dec. 19, 2019, 8:48 p.m. UTC | #1
On Thu, Dec 19, 2019 at 03:24:19PM -0500, David Malcolm wrote:
> Currently -fdiagnostics-urls defaults to "auto" and this works
> (e.g. for recent gnome-terminal, and is gracefully discarded by
> konsole5), but there have been reports of incompatibilities of the
> feature with various other terminals.
> 
> This patch adds a configuration option to change this default, based
> on Jakub's analogous change to -fdiagnostics-color (r217540).  One
> possible configure-time option is --with-diagnostics-urls=auto-if-env,
> which adds support for a GCC_URLS environment variable to control
> the default (again by analogy with the --with-diagnostics-color
> configure-time support for changing -fdiagnostics-color).

I think it would be better to have GCC_URLS env var to be be more consistent
with GCC_COLORS, so yes, have the never,auto,auto-if-env,always
configure possibilities like for colors and for auto-if-env don't print
URLS if the env var is not present, but on top of that, parse also the value
of the env var like parse_gcc_colors does, and have a way to disable urls
even with -fdiagnostics-urls=always (like GCC_COLORS= disables colors),
and perhaps use the env var to select between the ST and BEL terminator
as apparently some terminals like one or the other more.
So perhaps accept GCC_URLS= and GCC_URLS=no as disabling, GCC_URLS=bel
as the (default) case for BEL termination and GCC_URLS=st for the ST
termination?
E.g. have a way even for a compiler configured that it will work with new
terminals most of them time and thus --with-diagnostics-urls=always that
if somebody sshs to some machine from some old host, GCC_URLS=no (or none?)
can be still used to disable it, without the need to tweak build system to
inject there some flags.

> Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu; I
> tested the --with-diagnostics-urls=auto-if-env and GCC_URLS behavior
> manually.
> 
> Jakub: does this look sane to you?  (given that this is heavily based
> on your 2014 patches for --with-diagnostics-color).

	Jakub
王昊然 Dec. 21, 2019, 4:51 a.m. UTC | #2
I think this is good idea since it is consistent with env var
GCC_COLORS -- the color support will be disabled even with
-fdiagnostics-color=always, if GCC_COLORS is set to empty.
And I has experienced more serious problem when I ssh(1) to the remote
machine from a even older terminal, GNOME Terminal 2.30.2. The
terminal bells made noticeable delays; The whole terminal window would
hang for several seconds when gcc(1) emits too many warnings in at a
time...

2019-12-20 4:48 GMT+08:00, Jakub Jelinek <jakub@redhat.com>:
> On Thu, Dec 19, 2019 at 03:24:19PM -0500, David Malcolm wrote:
>> Currently -fdiagnostics-urls defaults to "auto" and this works
>> (e.g. for recent gnome-terminal, and is gracefully discarded by
>> konsole5), but there have been reports of incompatibilities of the
>> feature with various other terminals.
>>
>> This patch adds a configuration option to change this default, based
>> on Jakub's analogous change to -fdiagnostics-color (r217540).  One
>> possible configure-time option is --with-diagnostics-urls=auto-if-env,
>> which adds support for a GCC_URLS environment variable to control
>> the default (again by analogy with the --with-diagnostics-color
>> configure-time support for changing -fdiagnostics-color).
>
> I think it would be better to have GCC_URLS env var to be be more
> consistent
> with GCC_COLORS, so yes, have the never,auto,auto-if-env,always
> configure possibilities like for colors and for auto-if-env don't print
> URLS if the env var is not present, but on top of that, parse also the
> value
> of the env var like parse_gcc_colors does, and have a way to disable urls
> even with -fdiagnostics-urls=always (like GCC_COLORS= disables colors),
> and perhaps use the env var to select between the ST and BEL terminator
> as apparently some terminals like one or the other more.
> So perhaps accept GCC_URLS= and GCC_URLS=no as disabling, GCC_URLS=bel
> as the (default) case for BEL termination and GCC_URLS=st for the ST
> termination?
> E.g. have a way even for a compiler configured that it will work with new
> terminals most of them time and thus --with-diagnostics-urls=always that
> if somebody sshs to some machine from some old host, GCC_URLS=no (or none?)
> can be still used to disable it, without the need to tweak build system to
> inject there some flags.
>
>> Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu; I
>> tested the --with-diagnostics-urls=auto-if-env and GCC_URLS behavior
>> manually.
>>
>> Jakub: does this look sane to you?  (given that this is heavily based
>> on your 2014 patches for --with-diagnostics-color).
>
> 	Jakub
>
>
diff mbox series

Patch

diff --git a/gcc/configure.ac b/gcc/configure.ac
index 954c1496fb1..8f3cee0917b 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -6706,6 +6706,34 @@  AC_ARG_WITH([diagnostics-color],
 AC_DEFINE_UNQUOTED(DIAGNOSTICS_COLOR_DEFAULT, $DIAGNOSTICS_COLOR_DEFAULT,
 		   [The default for -fdiagnostics-color option])
 
+# Specify what should be the default of -fdiagnostics-urls option.
+AC_ARG_WITH([diagnostics-urls],
+[AC_HELP_STRING([--with-diagnostics-urls={never,auto,auto-if-env,always}],
+                [specify the default of -fdiagnostics-urls option
+                 auto-if-env stands for -fdiagnostics-urls=auto if
+                 GCC_URLS environment variable is present and
+                 -fdiagnostics-urls=never otherwise])],
+[case x"$withval" in
+   xnever)
+     DIAGNOSTICS_URLS_DEFAULT=DIAGNOSTICS_URL_NO
+     ;;
+   xauto)
+     DIAGNOSTICS_URLS_DEFAULT=DIAGNOSTICS_URL_AUTO
+     ;;
+   xauto-if-env)
+     DIAGNOSTICS_URLS_DEFAULT=-1
+     ;;
+   xalways)
+     DIAGNOSTICS_URLS_DEFAULT=DIAGNOSTICS_URL_YES
+     ;;
+   *)
+     AC_MSG_ERROR([$withval is an invalid option to --with-diagnostics-urls])
+     ;;
+ esac],
+[DIAGNOSTICS_URLS_DEFAULT=DIAGNOSTICS_URL_AUTO])
+AC_DEFINE_UNQUOTED(DIAGNOSTICS_URLS_DEFAULT, $DIAGNOSTICS_URLS_DEFAULT,
+		   [The default for -fdiagnostics-urls option])
+
 # Generate gcc-driver-name.h containing GCC_DRIVER_NAME for the benefit
 # of jit/jit-playback.c.
 gcc_driver_version=`eval "${get_gcc_base_ver} $srcdir/BASE-VER"`
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index 95cfb6e76ac..708d4649e90 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -257,8 +257,23 @@  diagnostic_color_init (diagnostic_context *context, int value /*= -1 */)
 void
 diagnostic_urls_init (diagnostic_context *context, int value /*= -1 */)
 {
+  /* value == -1 is the default value.  */
   if (value < 0)
-    value = DIAGNOSTICS_COLOR_DEFAULT;
+    {
+      /* If DIAGNOSTICS_URLS_DEFAULT is -1, default to
+	 -fdiagnostics-urls=auto if GCC_URLS is in the environment,
+	 otherwise default to -fdiagnostics-urls=never, for other
+	 values default to that
+	 -fdiagnostics-urls={never,auto,always}.  */
+      if (DIAGNOSTICS_URLS_DEFAULT == -1)
+	{
+	  if (!getenv ("GCC_URLS"))
+	    return;
+	  value = DIAGNOSTICS_URL_AUTO;
+	}
+      else
+	value = DIAGNOSTICS_URLS_DEFAULT;
+    }
 
   context->printer->show_urls
     = diagnostic_urls_enabled_p ((diagnostic_url_rule_t) value);
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 19d649ccc83..83f35a131fb 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -2098,6 +2098,15 @@  where @samp{auto} is the default.  @samp{auto-if-env} means that
 is present and non-empty in the environment, and
 @option{-fdiagnostics-color=never} otherwise.
 
+@item --with-diagnostics-urls=@var{choice}
+Tells GCC to use @var{choice} as the default for @option{-fdiagnostics-urls=}
+option (if not used explicitly on the command line).  @var{choice}
+can be one of @samp{never}, @samp{auto}, @samp{always}, and @samp{auto-if-env}
+where @samp{auto} is the default.  @samp{auto-if-env} means that
+@option{-fdiagnostics-urls=auto} will be the default if @env{GCC_URLS}
+is present in the environment, and @option{-fdiagnostics-urls=never}
+otherwise.
+
 @item --enable-lto
 @itemx --disable-lto
 Enable support for link-time optimization (LTO).  This is enabled by
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 6942881dbcc..aee4596120d 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -3921,14 +3921,20 @@  arguments in the C++ frontend.
 @item -fdiagnostics-urls[=@var{WHEN}]
 @opindex fdiagnostics-urls
 @cindex urls
+@vindex GCC_URLS @r{environment variable}
 Use escape sequences to embed URLs in diagnostics.  For example, when
 @option{-fdiagnostics-show-option} emits text showing the command-line
 option controlling a diagnostic, embed a URL for documentation of that
 option.
 
 @var{WHEN} is @samp{never}, @samp{always}, or @samp{auto}.
-The default is @samp{auto}, which means to use URL escape sequences only
-when the standard error is a terminal.
+@samp{auto} means to use URL escape sequences only when the standard error
+is a terminal.
+
+The default depends on how the compiler has been configured,
+it can be any of the above @var{WHEN} options or also @samp{never}
+if @env{GCC_URLS} environment variable isn't present in the environment,
+and @samp{auto} otherwise.
 
 @item -fno-diagnostics-show-option
 @opindex fno-diagnostics-show-option