diff --git a/bin/common.ml b/bin/common.ml index 889aa948bd26..1199c28bc4b0 100644 --- a/bin/common.ml +++ b/bin/common.ml @@ -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 @@ -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 = @@ -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 @@ -416,6 +424,7 @@ let term = ; default_target ; watch ; stats_trace_file + ; always_show_command_lines_on_error } let term = diff --git a/bin/common.mli b/bin/common.mli index 72130cc5f230..132d1875ee3c 100644 --- a/bin/common.mli +++ b/bin/common.mli @@ -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 diff --git a/src/clflags.ml b/src/clflags.ml index d0d11faeb203..0e7c4e373a06 100644 --- a/src/clflags.ml +++ b/src/clflags.ml @@ -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 diff --git a/src/clflags.mli b/src/clflags.mli index 387921185061..453f3510e8b7 100644 --- a/src/clflags.mli +++ b/src/clflags.mli @@ -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 diff --git a/src/config.ml b/src/config.ml index 24f3bddcfcc9..73a766f82bfd 100644 --- a/src/config.ml +++ b/src/config.ml @@ -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" diff --git a/src/config.mli b/src/config.mli index 12f4fcd06773..569fafe86cc0 100644 --- a/src/config.mli +++ b/src/config.mli @@ -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 *) diff --git a/src/process.ml b/src/process.ml index 13525a13adb5..31a2f0e0bf53 100644 --- a/src/process.ml +++ b/src/process.ml @@ -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 -> @@ -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@{Command@} [@{%d@}] exited with code %d:\n\ @{$@} %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 "@{%12s@} %a @{(exit %d)@}\n\ @{
%s@}\n\ %s"