Skip to content

Compiler: new -Werror flag to turn wanrings into errors #1222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Compiler: be more consistent dealing with js vs ocaml strings (#984)
* Compiler: Compiler: add BigInt to provided symbols (fix #1168) (#1191)
* Compiler: use globalThis, drop joo_global_object #1193
* Compiler: new -Werror flag to turn wanrings into errors (#1222)
* Lib: add messageEvent to Dom_html (#1164)
* Lib: add PerformanceObserver API (#1164)
* Lib: add CSSStyleDeclaration.{setProperty, getPropertyValue, getPropertyPriority, removeProperty} (#1170)
Expand Down
36 changes: 24 additions & 12 deletions compiler/bin-js_of_ocaml/js_of_ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,29 @@ let _ =
| _ -> argv
in
try
Cmdliner.Term.eval_choice
~catch:false
~argv
Compile.command_main
[ Link.command
; Build_fs.command
; Build_runtime.command
; Print_runtime.command
; Check_runtime.command
; Compile.command
]
match
Cmdliner.Term.eval_choice
~catch:false
~argv
Compile.command_main
[ Link.command
; Build_fs.command
; Build_runtime.command
; Print_runtime.command
; Check_runtime.command
; Compile.command
]
with
| `Ok () | `Help | `Version ->
if !warnings > 0 && !werror
then (
Format.eprintf "%s: all warnings being treated as errors@." Sys.argv.(0);
exit 1)
else exit 0
| `Error `Term -> exit 1
| `Error `Parse -> exit 124
| `Error `Exn -> ()
(* should not happen *)
with
| (Match_failure _ | Assert_failure _ | Not_found) as exc ->
let backtrace = Printexc.get_backtrace () in
Expand All @@ -65,7 +77,7 @@ let _ =
Sys.argv.(0);
Format.eprintf "Error: %s@." (Printexc.to_string exc);
prerr_string backtrace;
exit 1
exit 125
| Magic_number.Bad_magic_number s ->
Format.eprintf "%s: Error: Not an ocaml bytecode file@." Sys.argv.(0);
Format.eprintf "%s: Error: Invalid magic number %S@." Sys.argv.(0) s;
Expand Down
12 changes: 10 additions & 2 deletions compiler/lib-cmdline/arg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type t =
{ debug : string list on_off
; optim : string list on_off
; quiet : bool
; werror : bool
; custom_header : string option
}

Expand Down Expand Up @@ -73,6 +74,10 @@ let is_quiet =
let doc = "suppress non-error messages." in
Arg.(value & flag & info [ "quiet"; "q" ] ~doc)

let is_werror =
let doc = "turn all warnings into errors." in
Arg.(value & flag & info [ "Werror" ] ~doc)

let custom_header =
let doc =
"Provide a custom header for the generated JavaScript file, useful for making the \
Expand All @@ -82,7 +87,7 @@ let custom_header =

let t =
Term.(
pure (fun debug enable disable pretty debuginfo noinline quiet c_header ->
pure (fun debug enable disable pretty debuginfo noinline quiet werror c_header ->
let enable = if pretty then "pretty" :: enable else enable in
let enable = if debuginfo then "debuginfo" :: enable else enable in
let disable = if noinline then "inline" :: disable else disable in
Expand All @@ -94,6 +99,7 @@ let t =
{ debug = { enable = debug; disable = [] }
; optim = { enable; disable }
; quiet
; werror
; custom_header = c_header
})
$ debug
Expand All @@ -103,6 +109,7 @@ let t =
$ debuginfo
$ noinline
$ is_quiet
$ is_werror
$ custom_header)

let on_off on off t =
Expand All @@ -112,4 +119,5 @@ let on_off on off t =
let eval t =
Config.Flag.(on_off enable disable t.optim);
Debug.(on_off enable disable t.debug);
quiet := t.quiet
quiet := t.quiet;
werror := t.werror
1 change: 1 addition & 0 deletions compiler/lib-cmdline/arg.mli
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type t =
{ debug : string list on_off
; optim : string list on_off
; quiet : bool
; werror : bool
; custom_header : string option
}

Expand Down
11 changes: 10 additions & 1 deletion compiler/lib/stdlib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@ include Int_replace_polymorphic_compare

let quiet = ref false

let warn fmt = Format.ksprintf (fun s -> if not !quiet then Format.eprintf "%s%!" s) fmt
let werror = ref false

let warnings = ref 0

let warn fmt =
Format.ksprintf
(fun s ->
incr warnings;
if not !quiet then Format.eprintf "%s%!" s)
fmt

let fail = ref true

Expand Down
1 change: 1 addition & 0 deletions toplevel/examples/lwt_toplevel/dune
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
(action
(run
%{bin:js_of_ocaml}
--Werror
-I
%{lib:reactiveData:.}
-I
Expand Down