guile-devel
[Top][All Lists]
Advanced

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

add command line option to quiet compiler messages


From: Tobin Harding
Subject: add command line option to quiet compiler messages
Date: Wed, 13 Jul 2016 14:08:06 +1000
User-agent: Mutt/1.6.1 (2016-04-27)

Patch adds command line option '--quiet' to inhibit compile and load messages.

---

This is version 2. Submitting this patch on a new email thread.

While working on this I discovered that compile messages are output from two
separate places (load.c and boot-9.scm). Each file contains identical strings
for the messages. This goes against the rule of SPOT.

This patch adds scheme procedures for outputting the messages. However load.c
does not call these.

I do not know how to call custom scheme procedures from the C file.

If someone could please point me in the right direction I would like to add this
before the patch is applied.

thanks,
Tobin.

 libguile/load.c               | 33 ++++++++++++++++++++++-----------
 module/ice-9/boot-9.scm       | 24 +++++++++++++++++++-----
 module/ice-9/command-line.scm |  5 +++++
 3 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/libguile/load.c b/libguile/load.c
index 7ad9a75..6b13090 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 load [and compile] quietly */
+static SCM *scm_loc_quiet;
+
 /* 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_false (*scm_loc_quiet)) {
+       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_false (*scm_loc_quiet)) {
+    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_false (*scm_loc_quiet)) {
+       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_quiet
+    = SCM_VARIABLE_LOC (scm_c_define ("%quiet", SCM_BOOL_F));
 
   scm_ellipsis = scm_from_latin1_string ("...");
 
diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index 99543e7..98a9a4e 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -32,6 +32,22 @@
 
 
 
+;;; Don't know where to put these:
+(define (cond_warn_compiling file)
+  (unless %quiet
+    (format (current-warning-port) ";;; compiling ~a\n" file)))
+
+(define (cond_warn_compiled file)
+  (unless %quiet
+    (format (current-warning-port) ";;; compiled ~a\n" file)))
+
+(define (cond_warn_newer new old)
+  (unless %quiet
+    (format (current-warning-port)
+            ";;; note: source file ~a\n;;;       newer than compiled ~a\n"
+            name go-file-name)))
+
+
 ;; Before compiling, make sure any symbols are resolved in the (guile)
 ;; module, the primary location of those symbols, rather than in
 ;; (guile-user), the default module that we compile in.
@@ -3769,15 +3785,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..9a3f7e1 100644
--- a/module/ice-9/command-line.scm
+++ b/module/ice-9/command-line.scm
@@ -136,6 +136,7 @@ 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 compile and load messages
   --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 +359,10 @@ If FILE begins with `-' the -s switch is mandatory.
             (set! inhibit-user-init? #t)
             (parse args out))
 
+           ((string=? arg "--quiet")
+            (set! %quiet #t)
+            (parse args out))
+
            ((string-prefix? "--use-srfi=" arg)
             (let ((srfis (map (lambda (x)
                                 (let ((n (string->number x)))
-- 
2.8.3





reply via email to

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