Skip to content

Commit

Permalink
Add always-show-command-lines-on-error option
Browse files Browse the repository at this point in the history
And hide the full commands when:
* The error starts with "File "
* we aren't inside CI

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
  • Loading branch information
rgrinberg committed May 7, 2019
1 parent 1fb6b11 commit a48a95a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ unreleased
- Install the `future_syntax` preprocessor as `ocaml-syntax-shims.exe` (#2125,
@rgrinberg)

- Hide full command on errors 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-lines-on-error`
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_lines_on_error : 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_lines_on_error :=
c.always_show_command_lines_on_error;
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_lines_on_error =
let doc = "Always show full command on error" in
Arg.(value
& flag
& info ["always-show-command-lines-on-error"] ~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_lines_on_error
}

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_lines_on_error : 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_lines_on_error = 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_lines_on_error : bool ref
3 changes: 3 additions & 0 deletions src/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ 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_ci || !Clflags.always_show_command_lines_on_error

let default_build_profile =
match Wp.t with
| Dune -> "dev"
Expand Down
2 changes: 2 additions & 0 deletions src/config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ val inside_dune : bool
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
8 changes: 6 additions & 2 deletions src/process.ml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ let run_internal ?dir ?(stdout_to=Output.stdout) ?(stderr_to=Output.stderr)
~env ~purpose fail_mode prog args =
let* scheduler = Scheduler.wait_for_available_job () in
let display = Console.display () in
let show_command_on_error = not !Clflags.watch in
let dir =
match dir with
| Some p ->
Expand Down Expand Up @@ -354,13 +353,18 @@ let run_internal ?dir ?(stdout_to=Output.stdout) ?(stderr_to=Output.stderr)
end;
n
| WEXITED n ->
let show_command =
let error_starts_with_file = String.is_prefix output ~prefix:"File " in
Config.show_full_command_on_error ()
|| (not error_starts_with_file)
in
if display = Verbose then
die "\n@{<kwd>Command@} [@{<id>%d@}] exited with code %d:\n\
@{<prompt>$@} %s\n%s"
id n
(Colors.strip_colors_for_stderr command_line)
(Colors.strip_colors_for_stderr output)
else if show_command_on_error then
else if show_command then
die "@{<error>%12s@} %a @{<error>(exit %d)@}\n\
@{<details>%s@}\n\
%s"
Expand Down

0 comments on commit a48a95a

Please sign in to comment.