Skip to content

Commit

Permalink
mdx: add --verbosity=info flag if Dune is in verbose mode
Browse files Browse the repository at this point in the history
This hack usually doesn't add much to the output and can greatly help
debugging mdx scripts with Dune.

Signed-off-by: Antonin Décimo <[email protected]>
  • Loading branch information
MisterDA committed Nov 14, 2022
1 parent f342f42 commit b9c3100
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/dune_rules/mdx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ open Import

let mdx_version_required = "1.6.0"

let mdx_verbosity = "--verbosity=info"

module Files = struct
type t =
{ src : Path.Build.t
Expand Down Expand Up @@ -64,16 +66,16 @@ module Deps = struct
]

let rule ~dir ~mdx_prog files =
let open Command.Args in
let color_always =
if Lazy.force Ansi_color.stderr_supports_color then
[ Command.Args.A "--color=always" ]
if Lazy.force Ansi_color.stderr_supports_color then [ A "--color=always" ]
else []
in
Command.(
run ~dir:(Path.build dir) mdx_prog
Args.(
[ A "deps" ] @ color_always @ [ Dep (Path.build files.Files.src) ])
~stdout_to:files.Files.deps)
let verbose = if !Log.verbose then [ A mdx_verbosity ] else [] in
Command.run ~dir:(Path.build dir) mdx_prog
([ A "deps" ] @ color_always @ verbose
@ [ Dep (Path.build files.Files.src) ])
~stdout_to:files.Files.deps

let path_escapes_dir str =
try
Expand Down Expand Up @@ -320,14 +322,15 @@ let gen_rules_for_single_file stanza ~sctx ~dir ~expander ~mdx_prog
[ A "--color=always" ]
else []
in
let verbose = if !Log.verbose then [ A mdx_verbosity ] else [] in
match mdx_prog_gen with
| Some prog -> (Ok (Path.build prog), [ Dep (Path.build files.src) ])
| None ->
let prelude_args =
List.concat_map stanza.preludes ~f:(Prelude.to_args ~dir)
in
( mdx_prog
, [ A "test" ] @ prelude_args @ color_always
, [ A "test" ] @ prelude_args @ color_always @ verbose
@ [ A "-o"; Target files.corrected; Dep (Path.build files.src) ] )
in
let deps, sandbox =
Expand Down Expand Up @@ -377,21 +380,18 @@ let mdx_prog_gen t ~sctx ~dir ~scope ~expander ~mdx_prog =
in
S args
in
let prelude_args =
Command.Args.S (List.concat_map t.preludes ~f:(Prelude.to_args ~dir))
in
let open Command.Args in
let prelude_args = S (List.concat_map t.preludes ~f:(Prelude.to_args ~dir)) in
let color_always =
if Lazy.force Ansi_color.stderr_supports_color then
[ Command.Args.A "--color=always" ]
if Lazy.force Ansi_color.stderr_supports_color then [ A "--color=always" ]
else []
in
let verbose = if !Log.verbose then [ A mdx_verbosity ] else [] in
(* We call mdx to generate the testing executable source *)
let action =
Command.(
run ~dir:(Path.build dir) mdx_prog ~stdout_to:file
Args.(
[ A "dune-gen"; prelude_args; Resolve.Memo.args directory_args ]
@ color_always))
Command.run ~dir:(Path.build dir) mdx_prog ~stdout_to:file
([ A "dune-gen"; prelude_args; Resolve.Memo.args directory_args ]
@ color_always @ verbose)
in
let open Memo.O in
let* () = Super_context.add_rule sctx ~loc ~dir action in
Expand Down

0 comments on commit b9c3100

Please sign in to comment.