1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-29 19:30:36 +02:00

Redirect diagnostice output messages (e.g., auto-compiling code) to a newly defined current-info-port, and add a command line argument -I' to set the current-info-port to a void-port. * libguile/ports.c: add cur_infoport_fluid, scm_current_info_port, scm_set_current_info_port; define default current-info-port to stderr * libguile/load.c(compiled_is_fresh,load_thunk_from_path, do_try_auto_compile,scm_sys_warn_auto_compilation_enabled, scm_primitive_load_path): direct output messages to current_info_port; was current_warning_port * libguile/init.c(scm_init_standard_ports): set default current_info_port * module/ice-9/ports.scm: define current-info-port and set-current-info-port * module/ice-9/command-line.scm(*usage*,compile-shell-switches): add argument -I' to silence diagnostics (or current-info-port to void-port) * doc/ref/guile-invoke.texi: add description for `-I' command argument

This commit is contained in:
Matthew Wette 2024-10-07 17:12:43 -07:00 committed by Arne Babenhauserheide
parent 3d2fd7a262
commit 78e9e51065
8 changed files with 88 additions and 27 deletions

View file

@ -171,6 +171,10 @@ detailed backtrace upon error. The only difference with
@option{--debug} is lack of support for VM hooks and the facilities that
build upon it (see above).
@item -I
Do not report diagnostic messages (e.g., from compiling source files).
This sets @code{current-info-port} to a void-port.
@item -q
@cindex init file, not loading
@cindex @file{.guile} file, not loading

View file

@ -200,6 +200,7 @@ scm_init_standard_ports ()
scm_set_current_error_port
(scm_standard_stream_to_port (2, isatty (2) ? "w0" : "w"));
scm_set_current_warning_port (scm_current_error_port ());
scm_set_current_info_port (scm_current_error_port ());
}

View file

@ -571,11 +571,11 @@ 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 ());
scm_puts (";;; note: source file ", scm_current_info_port ());
scm_display (full_filename, scm_current_info_port ());
scm_puts ("\n;;; newer than compiled ", scm_current_info_port ());
scm_display (compiled_filename, scm_current_info_port ());
scm_puts ("\n", scm_current_info_port ());
}
return compiled_is_newer;
@ -770,9 +770,9 @@ load_thunk_from_path (SCM filename, SCM source_file_name,
if (found_stale_file && *found_stale_file)
{
scm_puts (";;; found fresh compiled file at ",
scm_current_warning_port ());
scm_display (found, scm_current_warning_port ());
scm_newline (scm_current_warning_port ());
scm_current_info_port ());
scm_display (found, scm_current_info_port ());
scm_newline (scm_current_info_port ());
}
goto end;
@ -1017,9 +1017,9 @@ 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 ());
scm_puts (";;; compiling ", scm_current_info_port ());
scm_display (source, scm_current_info_port ());
scm_newline (scm_current_info_port ());
comp_mod = scm_c_resolve_module ("system base compile");
compile_file = scm_module_variable (comp_mod, sym_compile_file);
@ -1046,17 +1046,17 @@ 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 ());
scm_puts (";;; compiled ", scm_current_info_port ());
scm_display (res, scm_current_info_port ());
scm_newline (scm_current_info_port ());
return res;
}
else
{
scm_puts (";;; it seems ", scm_current_warning_port ());
scm_display (source, scm_current_warning_port ());
scm_puts (";;; it seems ", scm_current_info_port ());
scm_display (source, scm_current_info_port ());
scm_puts ("\n;;; is part of the compiler; skipping auto-compilation\n",
scm_current_warning_port ());
scm_current_info_port ());
return SCM_BOOL_F;
}
}
@ -1099,7 +1099,7 @@ SCM_DEFINE (scm_sys_warn_auto_compilation_enabled, "%warn-auto-compilation-enabl
{
scm_puts (";;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0\n"
";;; or pass the --no-auto-compile argument to disable.\n",
scm_current_warning_port ());
scm_current_info_port ());
message_shown = 1;
}
@ -1232,9 +1232,9 @@ SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 0, 0, 1,
if (found_stale_compiled_file)
{
scm_puts (";;; found fresh local cache at ",
scm_current_warning_port ());
scm_display (fallback, scm_current_warning_port ());
scm_newline (scm_current_warning_port ());
scm_current_info_port ());
scm_display (fallback, scm_current_info_port ());
scm_newline (scm_current_info_port ());
}
compiled_thunk = try_load_thunk_from_file (fallback);
}

View file

@ -432,6 +432,7 @@ static SCM cur_inport_fluid = SCM_BOOL_F;
static SCM cur_outport_fluid = SCM_BOOL_F;
static SCM cur_errport_fluid = SCM_BOOL_F;
static SCM cur_warnport_fluid = SCM_BOOL_F;
static SCM cur_infoport_fluid = SCM_BOOL_F;
static SCM cur_loadport_fluid = SCM_BOOL_F;
SCM_DEFINE (scm_current_input_port, "current-input-port", 0, 0, 0,
@ -488,6 +489,18 @@ SCM_DEFINE (scm_current_warning_port, "current-warning-port", 0, 0, 0,
}
#undef FUNC_NAME
SCM_DEFINE (scm_current_info_port, "current-info-port", 0, 0, 0,
(void),
"Return the port to which diagnostic information should be sent.")
#define FUNC_NAME s_scm_current_info_port
{
if (scm_is_true (cur_infoport_fluid))
return scm_fluid_ref (cur_infoport_fluid);
else
return SCM_BOOL_F;
}
#undef FUNC_NAME
SCM_DEFINE (scm_current_load_port, "current-load-port", 0, 0, 0,
(),
"Return the current-load-port.\n"
@ -545,6 +558,18 @@ scm_set_current_warning_port (SCM port)
}
#undef FUNC_NAME
SCM
scm_set_current_info_port (SCM port)
#define FUNC_NAME "set-current-info-port"
{
SCM oinfop = scm_fluid_ref (cur_infoport_fluid);
port = SCM_COERCE_OUTPORT (port);
SCM_VALIDATE_OPOUTPORT (1, port);
scm_fluid_set_x (cur_infoport_fluid, port);
return oinfop;
}
#undef FUNC_NAME
void
scm_dynwind_current_input_port (SCM port)
#define FUNC_NAME NULL
@ -4187,6 +4212,7 @@ scm_init_ice_9_ports (void)
scm_c_define ("%current-output-port-fluid", cur_outport_fluid);
scm_c_define ("%current-error-port-fluid", cur_errport_fluid);
scm_c_define ("%current-warning-port-fluid", cur_warnport_fluid);
scm_c_define ("%current-info-port-fluid", cur_infoport_fluid);
}
void
@ -4221,6 +4247,7 @@ scm_init_ports (void)
cur_outport_fluid = scm_make_fluid ();
cur_errport_fluid = scm_make_fluid ();
cur_warnport_fluid = scm_make_fluid ();
cur_infoport_fluid = scm_make_fluid ();
cur_loadport_fluid = scm_make_fluid ();
default_port_encoding_var =
@ -4259,4 +4286,8 @@ scm_init_ports (void)
(scm_t_subr) scm_current_error_port);
scm_c_define_gsubr (s_scm_current_warning_port, 0, 0, 0,
(scm_t_subr) scm_current_warning_port);
/* Used by welcome and compiler routines. */
scm_c_define_gsubr (s_scm_current_info_port, 0, 0, 0,
(scm_t_subr) scm_current_info_port);
}

View file

@ -139,11 +139,13 @@ SCM_API SCM scm_current_input_port (void);
SCM_API SCM scm_current_output_port (void);
SCM_API SCM scm_current_error_port (void);
SCM_API SCM scm_current_warning_port (void);
SCM_API SCM scm_current_info_port (void);
SCM_API SCM scm_current_load_port (void);
SCM_API SCM scm_set_current_input_port (SCM port);
SCM_API SCM scm_set_current_output_port (SCM port);
SCM_API SCM scm_set_current_error_port (SCM port);
SCM_API SCM scm_set_current_warning_port (SCM port);
SCM_API SCM scm_set_current_info_port (SCM port);
SCM_API void scm_dynwind_current_input_port (SCM port);
SCM_API void scm_dynwind_current_output_port (SCM port);
SCM_API void scm_dynwind_current_error_port (SCM port);

View file

@ -190,6 +190,13 @@ This is handy for tracing function calls, e.g.:
(newline (current-warning-port))
(car (last-pair stuff)))
(define (info . stuff)
(newline (current-info-port))
(display ";;; INFO " (current-info-port))
(display stuff (current-info-port))
(newline (current-info-port))
(car (last-pair stuff)))
;;; {Features}
@ -4348,15 +4355,15 @@ when none is available, reading FILE-NAME with READER."
(load-thunk-from-file go-file-name)
(begin
(when gostat
(format (current-warning-port)
(format (current-info-port)
";;; note: source file ~a\n;;; newer than compiled ~a\n"
name go-file-name))
(cond
(%load-should-auto-compile
(%warn-auto-compilation-enabled)
(format (current-warning-port) ";;; compiling ~a\n" name)
(format (current-info-port) ";;; compiling ~a\n" name)
(let ((cfn (compile name)))
(format (current-warning-port) ";;; compiled ~a\n" cfn)
(format (current-info-port) ";;; compiled ~a\n" cfn)
(load-thunk-from-file cfn)))
(else #f)))))
#:warning "WARNING: compilation of ~a failed:\n" name))

View file

@ -135,6 +135,7 @@ If FILE begins with `-' the -s switch is mandatory.
files.
--listen[=P] listen on a local port or a path for REPL clients;
if P is not given, the default is local port 37146
-I silence informative diagnostics
-q inhibit loading of user init file
--use-srfi=LS load SRFI modules for the SRFIs in LS,
which is a list of numbers like \"2,13,14\"
@ -382,6 +383,9 @@ If FILE begins with `-' the -s switch is mandatory.
(parse args
(cons '(install-r7rs!) out)))
((string=? arg "-I") ; silence diagostics
(parse args (cons `(current-info-port (%make-void-port "w")) out)))
((string=? arg "--listen") ; start a repl server
(parse args
(cons '((@@ (system repl server) spawn-server)) out)))

View file

@ -30,10 +30,10 @@
%port-property
%set-port-property!
current-input-port current-output-port
current-error-port current-warning-port
current-error-port current-warning-port current-info-port
current-load-port
set-current-input-port set-current-output-port
set-current-error-port
set-current-error-port set-current-info-port
port-mode
port?
input-port?
@ -144,7 +144,8 @@
call-with-output-string
close-port
current-error-port
current-warning-port))
current-warning-port
current-info-port))
(load-extension (string-append "libguile-" (effective-version))
"scm_init_ice_9_ports")
@ -290,6 +291,13 @@ interpret its input and output."
(error "expected an output port" x))
x)))
(define current-info-port
(fluid->parameter %current-info-port-fluid
(lambda (x)
(unless (output-port? x)
(error "expected an output port" x))
x)))
@ -396,6 +404,10 @@ interpret its input and output."
"Set the current default error port to @var{port}."
(current-error-port port))
(define (set-current-info-port port)
"Set the current default info port to @var{port}."
(current-info-port port))
;;;; high level routines