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  <tob...@codesourcery.com>
           David Malcolm  <dmalc...@redhat.com>
           Jakub Jelinek  <ja...@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 <dmalc...@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(-)

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
-- 
2.21.0

Reply via email to