guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: add command line option to quiet compiler messages


From: Tobin Harding
Subject: Re: add command line option to quiet compiler messages
Date: Wed, 27 Jul 2016 10:36:17 +1000
User-agent: Mutt/1.6.2 (2016-07-01)

Patch Version 3

On Sat, Jul 23, 2016 at 12:29:41PM +0200, Andy Wingo wrote:
> On Wed 20 Jul 2016 08:41, Tobin Harding <address@hidden> writes:
> 
> > On Thu, Jul 14, 2016 at 12:01:10PM +0200, Andy Wingo wrote:
> >> On Wed 13 Jul 2016 06:08, Tobin Harding <address@hidden> writes:

...

> >> Please resend without tabs, please.  Thanks :)

> But we are missing an (indent-tabs-mode . nil) in the c-mode part I
> think.  That is the proper fix ;)  In my emacs I customized the default
> indent-tabs-mode to nil globally; but that's a personal preference.

All changes were re-indented with '(setq-default indent-tabs-mode nil)'. Please
advise if there is still a problem with the indentation. Being my first patch to
the project I am more than happy to back and forth untill it is perfect so I
know for next time :)

> >> > +           ((string=? arg "--quiet")
> >> > +            (set! %quiet #t)
> >> > +            (parse args out))
> >> > +
> >> 
> >> Probably %quiet should be a parameter, and unless we plan on using it
> >> for other purposes it should have a more specific name
> >> (%verbose-auto-compilation-messages or so; no idea).
> >
> > Could you clarify please, a parameter to what?
> 
> See "Parameters" in the manual.  They are dynamically scoped
> thread-local variables.

I read up on parameters, since this variable is declared in the C file
(load.c) I'm not sure how you mean to use a parameter. Am I missing
something? So, I have kept it as is but renamed it as suggested.

> 
> As far as documentation goes, the right place is the doc/ref/ directory,
> specifically doc/ref/guile-invoke.texi.

This version adds documentation. This is my first time editing Texinfo
format. Entry did not seem to need a @cindex line, if required please
say so, again I am happy to add it and re-submit.

> I will apply your patch as-is once we have docs, unless we can figure
> out some more general "chattiness" or verbosity knob that makes sense
> for other messages that Guile issues.  I suspect that the "real"
> solution for user code is to use a logging module that suits the user's
> needs, but for Guile we also have some needs that we should solve in a
> simple way.  Could be that this patch is the one :)
> 
> Thanks for your patience in contributing!

Thanks for taking the time to look over my patch.

thanks,
Tobin.


---
 doc/ref/guile-invoke.texi     |  7 +++++++
 libguile/load.c               | 33 ++++++++++++++++++++++-----------
 module/ice-9/boot-9.scm       | 22 +++++++++++++++++-----
 module/ice-9/command-line.scm |  6 ++++++
 4 files changed, 52 insertions(+), 16 deletions(-)

diff --git a/doc/ref/guile-invoke.texi b/doc/ref/guile-invoke.texi
index bc33ce0..add96da 100644
--- a/doc/ref/guile-invoke.texi
+++ b/doc/ref/guile-invoke.texi
@@ -172,6 +172,13 @@ Do not load the initialization file, @file{.guile}.  This 
option only
 has an effect when running interactively; running scripts does not load
 the @file{.guile} file.  @xref{Init File}.
 
address@hidden --quiet
+Inhibit the output of compiler informational messages. Default behaviour
+is for the compiler to output the file name (fully qualified path name)
+of each file before it is loaded if it is newer than an available
+compiled version, also once compiled, the compiled file name is
+output. The @option{--quiet} flag inhibits these messages.
+
 @item address@hidden
 While this program runs, listen on a local port or a path for REPL
 clients.  If @var{p} starts with a number, it is assumed to be a local
diff --git a/libguile/load.c b/libguile/load.c
index 7ad9a75..b5d80c5 100644
--- a/libguile/load.c
+++ b/libguile/load.c
@@ -226,6 +226,9 @@ static SCM *scm_loc_fresh_auto_compile;
 /* The fallback path for auto-compilation */
 static SCM *scm_loc_compile_fallback_path;
 
+/* Whether we should output compiler informational messages */
+static SCM *scm_loc_verbose_compiler_messages;
+
 /* Ellipsis: "..." */
 static SCM scm_ellipsis;
 
@@ -561,11 +564,13 @@ compiled_is_fresh (SCM full_filename, SCM 
compiled_filename,
   else
     {
       compiled_is_newer = 0;
-      scm_puts (";;; note: source file ", scm_current_warning_port ());
-      scm_display (full_filename, scm_current_warning_port ());
-      scm_puts ("\n;;;       newer than compiled ", scm_current_warning_port 
());
-      scm_display (compiled_filename, scm_current_warning_port ());
-      scm_puts ("\n", scm_current_warning_port ());
+      if (scm_is_true (*scm_loc_verbose_compiler_messages)) {
+        scm_puts (";;; note: source file ", scm_current_warning_port ());
+        scm_display (full_filename, scm_current_warning_port ());
+        scm_puts ("\n;;;       newer than compiled ", scm_current_warning_port 
());
+        scm_display (compiled_filename, scm_current_warning_port ());
+        scm_puts ("\n", scm_current_warning_port ());
+      }
     }
 
   return compiled_is_newer;
@@ -1007,9 +1012,11 @@ do_try_auto_compile (void *data)
   SCM source = SCM_PACK_POINTER (data);
   SCM comp_mod, compile_file;
 
-  scm_puts (";;; compiling ", scm_current_warning_port ());
-  scm_display (source, scm_current_warning_port ());
-  scm_newline (scm_current_warning_port ());
+  if (scm_is_true (*scm_loc_verbose_compiler_messages)) {
+    scm_puts (";;; compiling ", scm_current_warning_port ());
+    scm_display (source, scm_current_warning_port ());
+    scm_newline (scm_current_warning_port ());
+  }
 
   comp_mod = scm_c_resolve_module ("system base compile");
   compile_file = scm_module_variable (comp_mod, sym_compile_file);
@@ -1036,9 +1043,11 @@ do_try_auto_compile (void *data)
       /* Assume `*current-warning-prefix*' has an appropriate value.  */
       res = scm_call_n (scm_variable_ref (compile_file), args, 5);
 
-      scm_puts (";;; compiled ", scm_current_warning_port ());
-      scm_display (res, scm_current_warning_port ());
-      scm_newline (scm_current_warning_port ());
+      if (scm_is_true (*scm_loc_verbose_compiler_messages)) {
+       scm_puts (";;; compiled ", scm_current_warning_port ());
+       scm_display (res, scm_current_warning_port ());
+       scm_newline (scm_current_warning_port ());
+      }
       return res;
     }
   else
@@ -1349,6 +1358,8 @@ scm_init_load ()
     = SCM_VARIABLE_LOC (scm_c_define ("%load-should-auto-compile", 
SCM_BOOL_F));
   scm_loc_fresh_auto_compile
     = SCM_VARIABLE_LOC (scm_c_define ("%fresh-auto-compile", SCM_BOOL_F));
+  scm_loc_verbose_compiler_messages
+    = SCM_VARIABLE_LOC (scm_c_define ("%verbose-compiler-messages", 
SCM_BOOL_T));
 
   scm_ellipsis = scm_from_latin1_string ("...");
 
diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index 99543e7..a0e463c 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -3762,6 +3762,20 @@ when none is available, reading FILE-NAME with READER."
     ;; Return GO-FILE-NAME after making sure that it contains a freshly
     ;; compiled version of source file NAME with stat SCMSTAT; return #f
     ;; on failure.
+    (define (cond-warn-compiling file)
+      (if %verbose-compiler-messages
+          (format (current-warning-port) ";;; compiling ~a\n" file)))
+
+    (define (cond-warn-compiled file)
+      (if %verbose-compiler-messages
+          (format (current-warning-port) ";;; compiled ~a\n" file)))
+
+    (define (cond-warn-newer new old)
+      (if %verbose-compiler-messages
+          (format (current-warning-port)
+                  ";;; note: source file ~a\n;;;       newer than compiled 
~a\n"
+                  name go-file-name)))
+
     (false-if-exception
      (let ((gostat (and (not %fresh-auto-compile)
                         (stat go-file-name #f))))
@@ -3769,15 +3783,13 @@ when none is available, reading FILE-NAME with READER."
            (load-thunk-from-file go-file-name)
            (begin
              (when gostat
-               (format (current-warning-port)
-                       ";;; note: source file ~a\n;;;       newer than 
compiled ~a\n"
-                       name go-file-name))
+               (cond-warn-newer name go-file-name))
              (cond
               (%load-should-auto-compile
                (%warn-auto-compilation-enabled)
-               (format (current-warning-port) ";;; compiling ~a\n" name)
+               (cond-warn-compiling name)
                (let ((cfn (compile name)))
-                 (format (current-warning-port) ";;; compiled ~a\n" cfn)
+                 (cond-warn-compiled cfn)
                  (load-thunk-from-file cfn)))
               (else #f)))))
      #:warning "WARNING: compilation of ~a failed:\n" name))
diff --git a/module/ice-9/command-line.scm b/module/ice-9/command-line.scm
index 98d3855..fe639bb 100644
--- a/module/ice-9/command-line.scm
+++ b/module/ice-9/command-line.scm
@@ -136,6 +136,8 @@ If FILE begins with `-' the -s switch is mandatory.
   --listen[=P]   listen on a local port or a path for REPL clients;
                  if P is not given, the default is local port 37146
   -q             inhibit loading of user init file
+  --quiet        inhibit informational compiler output, e.g name of
+                 files being compiled
   --use-srfi=LS  load SRFI modules for the SRFIs in LS,
                  which is a list of numbers like \"2,13,14\"
   -h, --help     display this help and exit
@@ -358,6 +360,10 @@ If FILE begins with `-' the -s switch is mandatory.
             (set! inhibit-user-init? #t)
             (parse args out))
 
+           ((string=? arg "--quiet")
+            (set! %verbose-compiler-messages #f)
+            (parse args out))
+
            ((string-prefix? "--use-srfi=" arg)
             (let ((srfis (map (lambda (x)
                                 (let ((n (string->number x)))
-- 
2.9.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]