From 0b9c460f383a358b7a25ebb625ce59cb1f2777ee Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sat, 4 May 2019 13:36:11 +0800 Subject: [PATCH] Trim error messages when not in CI Now, dune will not output the full command if the following conditions hold: * The command outputs a location (which is determiend using a "File " prefix) * Dune doesn't think we are running in CI (detected using the CI env var) This behavior may be disabled using --always-show-command-line Signed-off-by: Rudi Grinberg --- CHANGES.md | 6 ++++++ bin/common.ml | 9 +++++++++ bin/common.mli | 1 + src/clflags.ml | 1 + src/clflags.mli | 3 +++ src/config.ml | 4 ++++ src/config.mli | 8 +++++++- src/process.ml | 13 +++++++++++-- 8 files changed, 42 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ccb38a29d35..04c002267cd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) ------------------ diff --git a/bin/common.ml b/bin/common.ml index 889aa948bd2..54de3e40bd0 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_line : 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_line := + c.always_show_command_line; 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_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 @@ -416,6 +424,7 @@ let term = ; default_target ; watch ; stats_trace_file + ; always_show_command_line } let term = diff --git a/bin/common.mli b/bin/common.mli index 72130cc5f23..db77ba65369 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_line : bool } val prefix_target : t -> string -> string diff --git a/src/clflags.ml b/src/clflags.ml index d0d11faeb20..93cb0b43cd8 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_line = ref false diff --git a/src/clflags.mli b/src/clflags.mli index 38792118506..41e8a21c63c 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_line : bool ref diff --git a/src/config.ml b/src/config.ml index a4294093585..dc6c66b4233 100644 --- a/src/config.ml +++ b/src/config.ml @@ -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 diff --git a/src/config.mli b/src/config.mli index a23decb0d7f..569fafe86cc 100644 --- a/src/config.mli +++ b/src/config.mli @@ -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 *) diff --git a/src/process.ml b/src/process.ml index ba1597dd291..8012f586270 100644 --- a/src/process.ml +++ b/src/process.ml @@ -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 @@ -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@{%s@} %a\n%s" pad progname Fancy.pp_purpose purpose output + if show_command then + print "%s@{%s@} %a\n%s" pad progname Fancy.pp_purpose purpose output + else + print "%s" output end; n | WEXITED n -> @@ -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 "@{%12s@} %a @{(exit %d)@}\n\ @{
%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@{Command@} [@{%d@}] got signal %s:\n\