diff --git a/bin/common.ml b/bin/common.ml index dcbf82e6c2e9..d773fa465c67 100644 --- a/bin/common.ml +++ b/bin/common.ml @@ -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 @@ -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" ]; @@ -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 @@ -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; diff --git a/doc/changes/8400.md b/doc/changes/8400.md new file mode 100644 index 000000000000..7aed34b311ba --- /dev/null +++ b/doc/changes/8400.md @@ -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) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/stop-on-first-error.t/bar.ml b/test/blackbox-tests/test-cases/stop-on-first-error.t/bar.ml new file mode 100644 index 000000000000..91e2b860872a --- /dev/null +++ b/test/blackbox-tests/test-cases/stop-on-first-error.t/bar.ml @@ -0,0 +1 @@ +let run = syntax error \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/stop-on-first-error.t/baz.ml b/test/blackbox-tests/test-cases/stop-on-first-error.t/baz.ml new file mode 100644 index 000000000000..91e2b860872a --- /dev/null +++ b/test/blackbox-tests/test-cases/stop-on-first-error.t/baz.ml @@ -0,0 +1 @@ +let run = syntax error \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/stop-on-first-error.t/dune b/test/blackbox-tests/test-cases/stop-on-first-error.t/dune new file mode 100644 index 000000000000..919ec748519d --- /dev/null +++ b/test/blackbox-tests/test-cases/stop-on-first-error.t/dune @@ -0,0 +1,3 @@ +(executable + (name foo) + (modules foo bar baz)) diff --git a/test/blackbox-tests/test-cases/stop-on-first-error.t/dune-project b/test/blackbox-tests/test-cases/stop-on-first-error.t/dune-project new file mode 100644 index 000000000000..2f602c3083f4 --- /dev/null +++ b/test/blackbox-tests/test-cases/stop-on-first-error.t/dune-project @@ -0,0 +1 @@ +(lang dune 3.10) diff --git a/test/blackbox-tests/test-cases/stop-on-first-error.t/foo.ml b/test/blackbox-tests/test-cases/stop-on-first-error.t/foo.ml new file mode 100644 index 000000000000..796a224c3782 --- /dev/null +++ b/test/blackbox-tests/test-cases/stop-on-first-error.t/foo.ml @@ -0,0 +1,3 @@ +let () = + Bar.run (); + Baz.run () diff --git a/test/blackbox-tests/test-cases/stop-on-first-error.t/run.t b/test/blackbox-tests/test-cases/stop-on-first-error.t/run.t new file mode 100644 index 000000000000..5ca0ae5a12bd --- /dev/null +++ b/test/blackbox-tests/test-cases/stop-on-first-error.t/run.t @@ -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]