Skip to content

Support -warn-error argument #6717

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 8 commits into from
Apr 17, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#### :rocket: New Feature

- Add `%todo` extension for leaving implementation for later. https://github.com/rescript-lang/rescript-compiler/pull/6713
- Add `-warn-error` argument for generate error on CI. Useful for `%todo` extension. https://github.com/rescript-lang/rescript-compiler/pull/6717

#### :bug: Bug Fix

Expand Down
19 changes: 18 additions & 1 deletion jscomp/bsb/bsb_ninja_regen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let ( // ) = Ext_path.combine
return None if we dont need regenerate
otherwise return Some info
*)
let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir ~warn_legacy_config
let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir ~warn_legacy_config ~warn_as_error
: Bsb_config_types.t option =
let lib_artifacts_dir = Bsb_config.lib_bs in
let lib_bs_dir = per_proj_dir // lib_artifacts_dir in
Expand Down Expand Up @@ -58,6 +58,23 @@ let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir
Bsb_config_parse.interpret_json
~filename:config_filename ~json:config_json ~package_kind ~per_proj_dir
in

let warning = match config.warning with
| None -> (
match warn_as_error with
| Some e -> Some {Bsb_warning.number = Some e; error = Warn_error_number e}
| None -> None)
| Some {error} as t ->
match (warn_as_error, error) with
| (Some error_str, Warn_error_false) ->
Some {number = Some error_str; error = Warn_error_number error_str}
| (Some error_str, Warn_error_number prev) ->
let new_error = prev ^ error_str in
Some {number = Some new_error; error = Warn_error_number new_error}
| _ -> t
in

let config = {config with warning = warning} in
(* create directory, lib/bs, lib/js, lib/es6 etc *)
Bsb_build_util.mkp lib_bs_dir;
Bsb_package_specs.list_dirs_by config.package_specs (fun x ->
Expand Down
1 change: 1 addition & 0 deletions jscomp/bsb/bsb_ninja_regen.mli
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ val regenerate_ninja :
forced:bool ->
per_proj_dir:string ->
warn_legacy_config:bool ->
warn_as_error:string option ->
Bsb_config_types.t option
(** Regenerate ninja file by need based on [.bsdeps]
return None if we dont need regenerate
Expand Down
11 changes: 10 additions & 1 deletion jscomp/bsb/bsb_warning.mli
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

type t
type warning_error =
| Warn_error_false
(* default [false] to make our changes non-intrusive *)
| Warn_error_true
| Warn_error_number of string

type t0 = { number : string option; error : warning_error }

type nonrec t = t0 option


val to_merlin_string : t -> string
(** Extra work is need to make merlin happy *)
Expand Down
3 changes: 2 additions & 1 deletion jscomp/bsb/bsb_world.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let ( // ) = Ext_path.combine
let vendor_ninja = Bsb_global_paths.vendor_ninja

let make_world_deps cwd (config : Bsb_config_types.t option)
(ninja_args : string array) =
(ninja_args : string array) warn_as_error =
let package_specs, jsx, uncurried, pinned_dependencies =
match config with
| None ->
Expand Down Expand Up @@ -71,6 +71,7 @@ let make_world_deps cwd (config : Bsb_config_types.t option)
else Dependency { package_specs; jsx; uncurried })
~per_proj_dir:proj_dir ~forced:false
~warn_legacy_config:false
~warn_as_error:(if is_pinned then warn_as_error else None)
in
let command =
{ Bsb_unix.cmd = vendor_ninja; cwd = lib_bs_dir; args }
Expand Down
2 changes: 1 addition & 1 deletion jscomp/bsb/bsb_world.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

val make_world_deps :
string -> Bsb_config_types.t option -> string array -> unit
string -> Bsb_config_types.t option -> string array -> string option -> unit
17 changes: 15 additions & 2 deletions jscomp/bsb_exe/rescript_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ let no_deps_mode = ref false

let do_install = ref false

let warning_as_error = ref None

let force_regenerate = ref false

type spec = Bsb_arg.spec
Expand All @@ -40,6 +42,8 @@ let unit_set_spec b : spec = Unit (Unit_set b)

let string_set_spec s : spec = String (String_set s)

let string_call f: spec = String (String_call f)

let failed_annon ~rev_args =
match rev_args with
| x :: _ -> Bsb_arg.bad_arg ("Don't know what to do with " ^ x)
Expand Down Expand Up @@ -132,6 +136,7 @@ let build_subcommand ~start argv argv_len =
Always regenerate build.ninja no matter bsconfig.json is changed or \
not" );
("-no-deps", unit_set_spec no_deps_mode, "*internal* Needed for watcher to build without dependencies on file change");
("-warn-error", string_call (fun s -> warning_as_error := Some s), "Warning numbers and whether to turn them into errors, e.g., \"+8+32-102\"")
|]
failed_annon;

Expand All @@ -141,14 +146,20 @@ let build_subcommand ~start argv argv_len =
match ninja_args with
| [| "-h" |] -> ninja_command_exit ninja_args
| _ ->
let warn_as_error = match !warning_as_error with
| Some s ->
let () = try Warnings.parse_options true s with Arg.Bad msg -> Bsb_arg.bad_arg (msg ^ "\n") in
Some s
| None -> None in
let config_opt =
Bsb_ninja_regen.regenerate_ninja
~package_kind:Toplevel
~per_proj_dir:Bsb_global_paths.cwd
~forced:!force_regenerate
~warn_legacy_config:true
~warn_as_error
in
if not !no_deps_mode then Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args;
if not !no_deps_mode then Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args warn_as_error;
if !do_install then install_target ();
ninja_command_exit ninja_args

Expand Down Expand Up @@ -180,6 +191,7 @@ let info_subcommand ~start argv =
~per_proj_dir:Bsb_global_paths.cwd
~forced:true
~warn_legacy_config:true
~warn_as_error:None
with
| None -> assert false
| Some { file_groups = { files } } ->
Expand Down Expand Up @@ -210,8 +222,9 @@ let () =
~per_proj_dir:Bsb_global_paths.cwd
~forced:false
~warn_legacy_config:true
~warn_as_error:None
in
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt [||];
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt [||] None;
ninja_command_exit [||])
else
match argv.(1) with
Expand Down
17 changes: 17 additions & 0 deletions jscomp/build_tests/build_warn_as_error/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var p = require("child_process");
var assert = require("assert");
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;

var o = p.spawnSync(rescript_exe, ["build", "-warn-error", "+110"], {
encoding: "utf8",
cwd: __dirname,
});

var error_message = o.stdout
.split("\n")
.map(s => s.trim())
.includes("Warning number 110 (configured as error)");

if (!error_message) {
assert.fail(o.stdout);
}
5 changes: 5 additions & 0 deletions jscomp/build_tests/build_warn_as_error/rescript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "build_warn_as_error",
"version": "0.1.0",
"sources": ["src"]
}
1 change: 1 addition & 0 deletions jscomp/build_tests/build_warn_as_error/src/Demo.res
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let todo = _ => %todo
9 changes: 5 additions & 4 deletions jscomp/build_tests/cli_help/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ const buildHelp =
"`rescript build -- -h` for Ninja options (internal usage only; unstable)\n" +
"\n" +
"Options:\n" +
" -w Watch mode\n" +
" -ws [host]:port set up host & port for WebSocket build notifications\n" +
" -verbose Set the output to be verbose\n" +
" -with-deps *deprecated* This is the default behavior now. This option will be removed in a future release\n";
" -w Watch mode\n" +
" -ws [host]:port set up host & port for WebSocket build notifications\n" +
" -verbose Set the output to be verbose\n" +
" -with-deps *deprecated* This is the default behavior now. This option will be removed in a future release\n" +
' -warn-error Warning numbers and whether to turn them into errors, e.g., "+8+32-102"\n';

const cleanHelp =
"Usage: rescript clean <options>\n" +
Expand Down