Skip to content

Commit 7aa559f

Browse files
committed
enable -warn-as-eror refined control while still catpure warnings output
TODO: - restore configure as error message - remove unneed exit code 77 handling in ninja
1 parent 7588709 commit 7aa559f

35 files changed

+203
-139
lines changed

Diff for: jscomp/bsb/bsb_templates.ml

+3-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@ let root = OCamlRes.Res.([
1414
\ \"dir\" : \"src\",\n\
1515
\ \"subdirs\" : true\n\
1616
\ },\n\
17-
\ \"package-specs\": {\n\
18-
\ \"module\": \"commonjs\",\n\
19-
\ \"in-source\": true\n\
20-
\ },\n\
21-
\ \"suffix\": \".bs.js\",\n\
22-
\ \"bs-dependencies\": [\n\
23-
\ ],\n\
24-
\ \"refmt\": 3\n\
17+
\ \"warnings\": {\n\
18+
\ \"error\" : \"+101\"\n\
19+
\ }\n\
2520
}\n\
2621
") ;
2722
File ("package.json",

Diff for: jscomp/bsb/bsb_warning.ml

+39-10
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525

26+
type warning_error =
27+
| Warn_error_false
28+
(* default [false] to make our changes non-intrusive *)
29+
| Warn_error_true
30+
| Warn_error_number of string
2631

2732
type t0 = {
28-
number : string option;
29-
} [@@ocaml.unboxed]
33+
number : string option;
34+
error : warning_error
35+
}
3036

3137
type nonrec t = t0 option
3238

@@ -64,13 +70,27 @@ let to_merlin_string x =
6470

6571
let from_map (m : Ext_json_types.t Map_string.t) =
6672
let number_opt = Map_string.find_opt m Bsb_build_schemas.number in
67-
let number =
68-
match number_opt with
69-
| Some (Str { str = number}) -> Some number
70-
| None -> None
71-
| Some x -> Bsb_exception.config_error x "expect a string"
72-
in
73-
Some {number }
73+
let error_opt = Map_string.find_opt m Bsb_build_schemas.error in
74+
match number_opt, error_opt with
75+
| None, None -> None
76+
| _, _ ->
77+
let error =
78+
match error_opt with
79+
| Some (True _) -> Warn_error_true
80+
| Some (False _) -> Warn_error_false
81+
| Some (Str {str ; })
82+
-> Warn_error_number str
83+
| Some x -> Bsb_exception.config_error x "expect true/false or string"
84+
| None -> Warn_error_false
85+
(** To make it less intrusive : warning error has to be enabled*)
86+
in
87+
let number =
88+
match number_opt with
89+
| Some (Str { str = number}) -> Some number
90+
| None -> None
91+
| Some x -> Bsb_exception.config_error x "expect a string"
92+
in
93+
Some {number; error }
7494

7595

7696
let to_bsb_string ~toplevel warning =
@@ -83,6 +103,15 @@ let to_bsb_string ~toplevel warning =
83103
Ext_string.empty
84104
| Some x ->
85105
prepare_warning_concat ~beg:true x
86-
)
106+
) ^
107+
(
108+
match warning.error with
109+
| Warn_error_true ->
110+
" -warn-error A"
111+
| Warn_error_number y ->
112+
" -warn-error " ^ y
113+
| Warn_error_false ->
114+
Ext_string.empty
115+
)
87116
else " -w a"
88117
(* TODO: this is the current default behavior *)

Diff for: jscomp/bsb/templates/basic/bsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
"sources": {
55
"dir" : "src",
66
"subdirs" : true
7+
},
8+
"warnings": {
9+
"error" : "+101"
710
}
811
}

Diff for: jscomp/build_tests/case3/bsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"suffix": ".bs.js",
1313
"bs-dependencies": [
1414
],
15+
"warnings": {"error" : "+101"},
1516
"refmt": 3
1617
}

Diff for: jscomp/build_tests/custom_namespace/bsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"bsc-flags" : ["-bs-no-version-header"],
1414
"bs-dependencies": [],
1515
"warnings": {
16-
"number" : "-40+6+7"
16+
"number" : "-40+6+7",
17+
"error" : true
1718
},
1819
"suffix": ".bs.js"
1920
}

Diff for: jscomp/build_tests/customize_namespace/bsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
"depa",
1515
"depb"
1616
],
17+
"warnings": {"error" : "+101"},
1718
"refmt": 3
1819
}

Diff for: jscomp/build_tests/cycle/bsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"suffix": ".bs.js",
1313
"bs-dependencies": [
1414
],
15+
"warnings": {"error" : "+101"},
1516
"refmt": 3
1617
}

Diff for: jscomp/build_tests/devdeps/bsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
"bs-dependencies": [
1919
],
2020
"bs-dev-dependencies": ["weird"],
21+
"warnings": {"error":"+101"},
2122
"refmt": 3
2223
}

Diff for: jscomp/build_tests/devonly/bsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
"suffix": ".bs.js",
1717
"bs-dependencies": [
1818
],
19+
"warnings": {"error" : "+101"},
1920
"refmt": 3
2021
}

Diff for: jscomp/build_tests/duplicated_symlinked_packages/a/bsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"c",
1515
"z"
1616
],
17+
"warnings": {"error" : "+101"},
1718
"namespace": true,
1819
"refmt": 3
1920
}

Diff for: jscomp/build_tests/duplicated_symlinked_packages/b/bsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"bs-dependencies": [
1414
"c"
1515
],
16+
"warnings": {"error" : "+101"},
1617
"namespace": true,
1718
"refmt": 3
1819
}

Diff for: jscomp/build_tests/duplicated_symlinked_packages/c/bsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"bs-dependencies": [
1414

1515
],
16+
"warnings": {"error" : "+101"},
1617
"namespace": true,
1718
"refmt": 3
1819
}

Diff for: jscomp/build_tests/install/bsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"suffix": ".bs.js",
1313
"bs-dependencies": [
1414
],
15+
"warnings": {"error" : "+101"},
1516
"refmt": 3
1617
}
1718

Diff for: jscomp/build_tests/namespace/bsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"libb"
1717
],
1818
"warnings": {
19-
"number" : "-40+6+7"
19+
"number" : "-40+6+7",
20+
"error" : true
2021
},
2122
"suffix": ".bs.js"
2223
}

Diff for: jscomp/build_tests/namespace/src/demo.bs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var Demo$Liba = require("liba/src/demo.bs.js");
4-
var Demo$Libb = require("libb/src/demo.js");
4+
var Demo$Libb = require("libb/src/demo.bs.js");
55

66
var v = Demo$Liba.v + Demo$Libb.v | 0;
77

Diff for: jscomp/build_tests/nested/bsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"package-specs" : {
1010
"module": "commonjs",
1111
"in-source": true
12-
}
12+
},
13+
"warnings": {"error" : true}
1314
}

Diff for: jscomp/build_tests/nnest/bsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"module": "commonjs",
1111
"in-source": true
1212
},
13-
"namespace": true
13+
"namespace": true,
14+
"warnings": {"error": true}
1415
}

Diff for: jscomp/build_tests/top/bsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
"suffix": ".bs.js",
2121
"bs-dependencies": [
2222
],
23+
"warnings": {"error" : "+101"},
2324
"refmt": 3
2425
}

Diff for: jscomp/build_tests/white space/bsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
,"in-source": true
1010
}],
1111
"warnings": {
12-
"number": "A"
12+
"number": "A",
13+
"error" : true
1314
}
1415
}

Diff for: jscomp/core/bs_conditional_initial.ml

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ let setup_env () =
3535
Matching.call_switcher_variant_constr := Polyvar_pattern_match.call_switcher_variant_constr;
3636
Clflags.no_std_include := true;
3737
Warnings.parse_options false Bsc_warnings.defaults_w;
38+
Warnings.parse_options true Bsc_warnings.defaults_warn_error;
3839
Clflags.dump_location := false;
3940
Clflags.compile_only := true;
4041
Config.bs_only := true;

Diff for: jscomp/core/lam_compile_main.ml

+5-12
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ let compile
260260
Ext_string.compare (Lam_module_ident.name id1) (Lam_module_ident.name id2)
261261
)
262262
in
263+
Warnings.check_fatal();
263264
let effect =
264265
Lam_stats_export.get_dependent_module_effect
265266
maybe_pure external_module_ids in
@@ -286,11 +287,7 @@ let lambda_as_module
286287
: unit =
287288
let package_info = Js_packages_state.get_packages_info () in
288289
if Js_packages_info.is_empty package_info && !Js_config.js_stdout then begin
289-
Js_dump_program.dump_deps_program ~output_prefix NodeJS lambda_output stdout;
290-
if !Warnings.nerrors > 0 then begin
291-
Warnings.nerrors := 0;
292-
exit 77
293-
end
290+
Js_dump_program.dump_deps_program ~output_prefix NodeJS lambda_output stdout
294291
end else
295292
Js_packages_info.iter package_info (fun {module_system; path; suffix} ->
296293
let output_chan chan =
@@ -313,15 +310,11 @@ let lambda_as_module
313310
(if not !Clflags.dont_write_files then
314311
Ext_pervasives.with_file_as_chan
315312
target_file output_chan );
316-
if !Warnings.nerrors > 0 then begin
317-
Warnings.nerrors := 0 ;
313+
if !Warnings.has_warnings then begin
314+
Warnings.has_warnings := false ;
318315
if Sys.file_exists target_file then begin
319316
Bs_hash_stubs.set_as_old_file target_file
320-
end;
321-
exit 77
322-
(* don't write js file, we need remove js files
323-
otherwise the js files are out-of-date
324-
exit 177 *)
317+
end
325318
end
326319
)
327320

Diff for: jscomp/ext/bsc_warnings.ml

+1
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,5 @@
7373
- 102 Bs_polymorphic_comparison
7474
*)
7575
let defaults_w = "+a-4-9-20-40-41-42-50-61-102"
76+
let defaults_warn_error = "-a+5+6+101";;
7677
(*TODO: add +10*)

Diff for: jscomp/main/js_main.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,10 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
498498
"*internal* keep the compatibility with RLS";
499499
"-c", Unit_dummy,
500500
"*internal* keep the compatibility with RLS";
501-
"-warn-error", string_call (fun _ -> ()),
502-
"Deprecated: warnings are errors";
501+
"-warn-error", string_call (Warnings.parse_options true),
502+
"<list> Enable or disable error status for warnings according\n\
503+
to <list>. See option -w for the syntax of <list>.\n\
504+
Default setting is " ^ Bsc_warnings.defaults_warn_error;
503505

504506
|]
505507

Diff for: jscomp/others/release.ninja

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
bsc_flags = -no-keep-locs -absname -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -nopervasives -unsafe -w +50 -open Bs_stdlib_mini -I ./runtime
2+
bsc_flags = -no-keep-locs -absname -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -nopervasives -unsafe -w +50 -warn-error A -open Bs_stdlib_mini -I ./runtime
33

44
rule cc
55
command = $bsc -bs-cmi -bs-cmj $bsc_flags -I others $in

Diff for: jscomp/runtime/release.ninja

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
bsc_no_open_flags = -no-keep-locs -absname -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -nopervasives -unsafe -w +50
2+
bsc_no_open_flags = -no-keep-locs -absname -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -nopervasives -unsafe -w +50 -warn-error A
33
bsc_flags = $bsc_no_open_flags -open Bs_stdlib_mini
44

55
rule cc

Diff for: jscomp/stdlib-406/release.ninja

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
bsc_flags = -no-keep-locs -absname -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -w -9-3-106 -I runtime -I others
2+
bsc_flags = -no-keep-locs -absname -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -w -9-3-106 -warn-error A -I runtime -I others
33

44
rule cc
55
command = $bsc -bs-cmi -bs-cmj $bsc_flags -I stdlib-406 $in

Diff for: jscomp/test/build.ninja

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
bsc_flags = -absname -bs-no-version-header -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:jscomp/test -w -3-6-26-27-29-30-32..40-44-45-52-60-9-106+104 -I runtime -I $stdlib -I others
2+
bsc_flags = -absname -bs-no-version-header -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:jscomp/test -w -3-6-26-27-29-30-32..40-44-45-52-60-9-106+104 -warn-error A -I runtime -I $stdlib -I others
33

44
rule cc
55
command = $bsc -bs-cmi -bs-cmj $bsc_flags -I test $in

Diff for: jscomp/test/recursive_react_component.re

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

22
[@bs.config {
33
flags : [|"-bs-jsx","3", "-dsource",
4-
// "-w","A"
4+
// "-w","A",
5+
// "-warn-error", "a"
56
|]
67
}];
78

0 commit comments

Comments
 (0)