Skip to content

Commit

Permalink
feature: add --stop-on-first-error CLI option (#8400)
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.

Signed-off-by: Ali Caglayan <alizter@gmail.com>
  • Loading branch information
Alizter authored Aug 16, 2023
1 parent b07afc3 commit 5f57c3d
Show file tree
Hide file tree
Showing 5 changed files with 47 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 an error 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 is encountered. (#8400, @pmwhite and @Alizter)
9 changes: 9 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,9 @@
(rule
(target foo)
(action
(system "exit 1")))

(rule
(target bar)
(action
(system "exit 1")))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 3.10)
25 changes: 25 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,25 @@
Here we demonstrate the --stop-on-first-error behaviour.

$ dune build
File "dune", line 1, characters 0-50:
1 | (rule
2 | (target foo)
3 | (action
4 | (system "exit 1")))
Command exited with code 1.
File "dune", line 6, characters 0-50:
6 | (rule
7 | (target bar)
8 | (action
9 | (system "exit 1")))
Command exited with code 1.
[1]

$ dune build --stop-on-first-error
File "dune", line 6, characters 0-50:
6 | (rule
7 | (target bar)
8 | (action
9 | (system "exit 1")))
Command exited with code 1.
[1]

0 comments on commit 5f57c3d

Please sign in to comment.