Skip to content

Commit

Permalink
Trim error messages in watch mode (#2120)
Browse files Browse the repository at this point in the history
Trim error messages in watch mode
  • Loading branch information
rgrinberg authored May 7, 2019
2 parents 83188d7 + 0b9c460 commit 1bef76a
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ unreleased
- Install the `future_syntax` preprocessor as `ocaml-syntax-shims.exe` (#2125,
@rgrinberg)

- Hide full command on errors and warnings in CI (detected using the `CI`
environment variable) and whenever the failed command outputs a location
(detected using the `File ` prefix heuristic). Add an
`--always-show-command-line` option to disable this behavior and always show
the full command.

1.9.2 (02/05/2019)
------------------

Expand Down
9 changes: 9 additions & 0 deletions bin/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type t =
(* For build & runtest only *)
; watch : bool
; stats_trace_file : string option
; always_show_command_line : bool
}

let prefix_target common s = common.target_prefix ^ s
Expand Down Expand Up @@ -67,6 +68,8 @@ let set_common_other c ~targets =
; c.orig_args
; targets
];
Clflags.always_show_command_line :=
c.always_show_command_line;
Option.iter ~f:Dune.Stats.enable c.stats_trace_file

let set_common c ~targets =
Expand Down Expand Up @@ -153,6 +156,11 @@ let term =
| false , Some x -> `Ok (Some x)
| true , None -> `Ok (Some Config.Display.Verbose)
| true , Some _ -> incompatible "--display" "--verbose"
and+ always_show_command_line =
let doc = "Always show the full command lines of programs executed by dune" in
Arg.(value
& flag
& info ["always-show-command-line"] ~docs ~doc)
and+ no_buffer =
Arg.(value
& flag
Expand Down Expand Up @@ -416,6 +424,7 @@ let term =
; default_target
; watch
; stats_trace_file
; always_show_command_line
}

let term =
Expand Down
1 change: 1 addition & 0 deletions bin/common.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type t =
(* For build & runtest only *)
; watch : bool
; stats_trace_file : string option
; always_show_command_line : bool
}

val prefix_target : t -> string -> string
Expand Down
1 change: 1 addition & 0 deletions src/clflags.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ let force = ref false
let watch = ref false
let no_print_directory = ref false
let store_orig_src_dir = ref false
let always_show_command_line = ref false
3 changes: 3 additions & 0 deletions src/clflags.mli
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ val no_print_directory : bool ref

(** Store original source directory in dune-package metadata *)
val store_orig_src_dir : bool ref

(** Always show full command on error *)
val always_show_command_line : bool ref
4 changes: 4 additions & 0 deletions src/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ let dune_keep_fname = ".dune-keep"

let inside_emacs = Option.is_some (Env.get Env.initial "INSIDE_EMACS")
let inside_dune = Option.is_some (Env.get Env.initial "INSIDE_DUNE")
let inside_ci = Option.is_some (Env.get Env.initial "CI")

let show_full_command_on_error () =
inside_dune || inside_ci || !Clflags.always_show_command_line

let default_build_profile =
match Wp.t with
Expand Down
8 changes: 7 additions & 1 deletion src/config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ val dune_keep_fname : string
(** Are we running inside an emacs shell? *)
val inside_emacs : bool

(** Are we running insinde Dune? *)
(** Are we running inside Dune? *)
val inside_dune : bool

(** Are we running in CI?. This checks the CI environment variable which is
supported by travis, gitlab.*)
val inside_ci : bool

val show_full_command_on_error : unit -> bool

val default_build_profile : string

(** Dune configuration *)
Expand Down
13 changes: 11 additions & 2 deletions src/process.ml
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ let run_internal ?dir ?(stdout_to=Output.stdout) ?(stderr_to=Output.stderr)
Log.command (Scheduler.log scheduler) ~command_line ~output ~exit_status;
let _, progname, _ = Fancy.split_prog prog_str in
let print fmt = Errors.kerrf ~f:Console.print fmt in
let show_command =
Config.show_full_command_on_error ()
|| (not (String.is_prefix output ~prefix:"File "))
in
match exit_status with
| WEXITED n when code_is_ok ok_codes n ->
if display = Verbose then begin
Expand All @@ -349,7 +353,10 @@ let run_internal ?dir ?(stdout_to=Output.stdout) ?(stderr_to=Output.stderr)
end else if output <> "" ||
(display = Short && purpose <> Internal_job) then begin
let pad = String.make (max 0 (12 - String.length progname)) ' ' in
print "%s@{<ok>%s@} %a\n%s" pad progname Fancy.pp_purpose purpose output
if show_command then
print "%s@{<ok>%s@} %a\n%s" pad progname Fancy.pp_purpose purpose output
else
print "%s" output
end;
n
| WEXITED n ->
Expand All @@ -359,13 +366,15 @@ let run_internal ?dir ?(stdout_to=Output.stdout) ?(stderr_to=Output.stderr)
id n
(Colors.strip_colors_for_stderr command_line)
(Colors.strip_colors_for_stderr output)
else
else if show_command then
die "@{<error>%12s@} %a @{<error>(exit %d)@}\n\
@{<details>%s@}\n\
%s"
progname Fancy.pp_purpose purpose n
(Ansi_color.strip command_line)
output
else
die "%s" output
| WSIGNALED n ->
if display = Verbose then
die "\n@{<kwd>Command@} [@{<id>%d@}] got signal %s:\n\
Expand Down

0 comments on commit 1bef76a

Please sign in to comment.