Skip to content

Commit

Permalink
feature: add --stop-on-first-error CLI option
Browse files Browse the repository at this point in the history
We expose a CLI option called --stop-on-first-error that exposes to the
user the internal behaviour of stopping the build on the first
encountered error.

- [x] option documentation
- [x] changelog
- [x] test

Signed-off-by: Ali Caglayan <alizter@gmail.com>
  • Loading branch information
Alizter committed Aug 15, 2023
1 parent e11fd63 commit 4b10798
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bin/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ module Builder = struct
; cache_debug_flags : Dune_engine.Cache_debug_flags.t
; report_errors_config : Dune_engine.Report_errors_config.t
; separate_error_messages : bool
; stop_on_first_error : bool
; require_dune_project_file : bool
; insignificant_changes : [ `React | `Ignore ]
; watch_exclusions : string list
Expand Down Expand Up @@ -952,6 +953,13 @@ module Builder = struct
& info
[ "display-separate-messages" ]
~doc:"Separate error messages with a blank line.")
and+ stop_on_first_error =
Arg.(
value
& flag
& info
[ "stop-on-first-error" ]
~doc:"Stop the build as soon as the first error message is encountered.")
in
if Option.is_none stats_trace_file && stats_trace_extended
then User_error.raise [ Pp.text "--trace-extended can only be used with --trace" ];
Expand Down Expand Up @@ -996,6 +1004,7 @@ module Builder = struct
; cache_debug_flags
; report_errors_config
; separate_error_messages
; stop_on_first_error
; require_dune_project_file
; insignificant_changes = (if react_to_insignificant_changes then `React else `Ignore)
; watch_exclusions
Expand Down Expand Up @@ -1191,6 +1200,7 @@ let init ?action_runner ?log_file c =
Dune_engine.Clflags.diff_command := c.builder.diff_command;
Dune_engine.Clflags.promote := c.builder.promote;
Dune_engine.Clflags.force := c.builder.force;
Dune_engine.Clflags.stop_on_first_error := c.builder.stop_on_first_error;
Dune_rules.Clflags.store_orig_src_dir := c.builder.store_orig_src_dir;
Dune_rules.Clflags.promote_install_files := c.builder.promote_install_files;
Dune_engine.Clflags.always_show_command_line := c.builder.always_show_command_line;
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/8400.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add `--stop-on-first-error` option to `dune build` which will terminate the build when
the first error message is encountered. (#8400, @pmwhite and @Alizter)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let run = syntax error
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let run = syntax error
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/stop-on-first-error.t/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executable
(name foo)
(modules foo bar baz))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 3.10)
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/stop-on-first-error.t/foo.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let () =
Bar.run ();
Baz.run ()
19 changes: 19 additions & 0 deletions test/blackbox-tests/test-cases/stop-on-first-error.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Here we demonstrate the --stop-on-first-error behaviour.

$ dune build
File "bar.ml", line 1, characters 10-16:
1 | let run = syntax error
^^^^^^
Error: Unbound value syntax
File "baz.ml", line 1, characters 10-16:
1 | let run = syntax error
^^^^^^
Error: Unbound value syntax
[1]

$ dune build --stop-on-first-error
File "bar.ml", line 1, characters 10-16:
1 | let run = syntax error
^^^^^^
Error: Unbound value syntax
[1]

0 comments on commit 4b10798

Please sign in to comment.