Skip to content

Commit 42df720

Browse files
aspeddrocknitt
authored andcommitted
Force regenerate build.ninja (rescript-lang#6877)
* force regenerate build.ninja * fix bin path * Update CHANGELOG.md * force regenerate when `warn-error` argument change * restore `-regen` argument * regenerate if previous warn error != 0 # Conflicts: # CHANGELOG.md
1 parent 22bc07c commit 42df720

File tree

5 files changed

+54
-11
lines changed

5 files changed

+54
-11
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Fix issue with infinite loops with type errors on recursive types. https://github.com/rescript-lang/rescript-compiler/pull/6867
2020
- Ignore `@uncurry` attribute in uncurried mode, to avoid generating calls to `Curry` at runtime. https://github.com/rescript-lang/rescript-compiler/pull/6869
2121
- Avoid generating calls to Curry when adjusting arity of uncurried functions. https://github.com/rescript-lang/rescript-compiler/pull/6870
22+
- Fix build after calling without `-warn-error`, see https://github.com/rescript-lang/rescript-compiler/issues/6868 for more details. https://github.com/rescript-lang/rescript-compiler/pull/6877
2223

2324
# 11.1.3-rc.1
2425

jscomp/bsb/bsb_ninja_check.ml

+11-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type check_result =
4343
| Bsb_bsc_version_mismatch
4444
| Bsb_forced
4545
| Bsb_package_kind_inconsistent
46+
| Bsb_regenerate_required
4647
| Other of string
4748

4849
let pp_check_result fmt (check_resoult : check_result) =
@@ -55,6 +56,7 @@ let pp_check_result fmt (check_resoult : check_result) =
5556
| Bsb_bsc_version_mismatch -> "Bsc or bsb version mismatch"
5657
| Bsb_forced -> "Bsb forced rebuild"
5758
| Bsb_package_kind_inconsistent -> "The package was built in different mode"
59+
| Bsb_regenerate_required -> "Bsb need regenerate build.ninja"
5860
| Other s -> s)
5961

6062
let rec check_aux cwd (xs : string list) =
@@ -91,13 +93,14 @@ let record_global_atime buf name =
9193
Ext_buffer.add_string_char buf (hex_of_float stamp) '\n'
9294

9395
let record ~(package_kind : Bsb_package_kind.t) ~per_proj_dir ~file
94-
~(config : Bsb_config_types.t) (file_or_dirs : string list) : unit =
96+
~(config : Bsb_config_types.t) ~(warn_as_error: string option) (file_or_dirs : string list) : unit =
9597
let buf = Ext_buffer.create 1_000 in
9698
Ext_buffer.add_string_char buf Bs_version.version '\n';
9799
Ext_buffer.add_string_char buf per_proj_dir '\n';
98100
Ext_buffer.add_string_char buf
99101
(Bsb_package_kind.encode_no_nl package_kind)
100102
'\n';
103+
Ext_buffer.add_string_char buf (match warn_as_error with | Some s -> s | None -> "0") '\n';
101104
Ext_list.iter file_or_dirs (fun f ->
102105
Ext_buffer.add_string_char buf f '\t';
103106
Ext_buffer.add_string_char buf
@@ -119,21 +122,25 @@ let record ~(package_kind : Bsb_package_kind.t) ~per_proj_dir ~file
119122
Even forced, we still need walk through a little
120123
bit in case we found a different version of compiler
121124
*)
122-
let check ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string) ~forced
123-
~file : check_result =
125+
let check ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string) ~forced ~(warn_as_error: string option) ~file : check_result =
124126
match open_in_bin file with
125127
(* Windows binary mode*)
126128
| exception _ -> Bsb_file_not_exist
127129
| ic -> (
128130
match List.rev (Ext_io.rev_lines_of_chann ic) with
129131
| exception _ -> Bsb_file_corrupted
130-
| version :: source_directory :: package_kind_str :: dir_or_files -> (
132+
| version :: source_directory :: package_kind_str :: previous_warn_as_error :: dir_or_files -> (
133+
let warn_as_error_changed = match warn_as_error with
134+
| None -> previous_warn_as_error <> "0"
135+
| Some current -> current <> previous_warn_as_error in
136+
131137
if version <> Bs_version.version then Bsb_bsc_version_mismatch
132138
else if per_proj_dir <> source_directory then
133139
Bsb_source_directory_changed
134140
else if forced then Bsb_forced (* No need walk through *)
135141
else if Bsb_package_kind.encode_no_nl package_kind <> package_kind_str
136142
then Bsb_package_kind_inconsistent
143+
else if warn_as_error_changed then Bsb_regenerate_required
137144
else
138145
try check_aux per_proj_dir dir_or_files
139146
with e ->

jscomp/bsb/bsb_ninja_check.mli

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type check_result =
3838
| Bsb_bsc_version_mismatch
3939
| Bsb_forced
4040
| Bsb_package_kind_inconsistent
41+
| Bsb_regenerate_required
4142
| Other of string
4243

4344
val pp_check_result : Format.formatter -> check_result -> unit
@@ -47,6 +48,7 @@ val record :
4748
per_proj_dir:string ->
4849
file:string ->
4950
config:Bsb_config_types.t ->
51+
warn_as_error:string option ->
5052
string list ->
5153
unit
5254
(** [record cwd file relevant_file_or_dirs]
@@ -64,6 +66,7 @@ val check :
6466
package_kind:Bsb_package_kind.t ->
6567
per_proj_dir:string ->
6668
forced:bool ->
69+
warn_as_error: string option ->
6770
file:string ->
6871
check_result
6972
(** check if [build.ninja] should be regenerated *)

jscomp/bsb/bsb_ninja_regen.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir
3636
let lib_bs_dir = per_proj_dir // lib_artifacts_dir in
3737
let output_deps = lib_bs_dir // bsdeps in
3838
let check_result =
39-
Bsb_ninja_check.check ~package_kind ~per_proj_dir ~forced ~file:output_deps
39+
Bsb_ninja_check.check ~package_kind ~per_proj_dir ~forced ~warn_as_error ~file:output_deps
4040
in
4141
let config_filename, config_json =
4242
Bsb_config_load.load_json ~per_proj_dir ~warn_legacy_config
@@ -45,6 +45,7 @@ let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir
4545
| Good -> None (* Fast path, no need regenerate ninja *)
4646
| Bsb_forced | Bsb_bsc_version_mismatch | Bsb_package_kind_inconsistent
4747
| Bsb_file_corrupted | Bsb_file_not_exist | Bsb_source_directory_changed
48+
| Bsb_regenerate_required
4849
| Other _ ->
4950
Bsb_log.info "@{<info>BSB check@} build spec : %a @."
5051
Bsb_ninja_check.pp_check_result check_result;
@@ -94,7 +95,7 @@ let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir
9495
config;
9596
(* PR2184: we still need record empty dir
9697
since it may add files in the future *)
97-
Bsb_ninja_check.record ~package_kind ~per_proj_dir ~config
98+
Bsb_ninja_check.record ~package_kind ~per_proj_dir ~config ~warn_as_error
9899
~file:output_deps
99100
(config.filename :: config.file_groups.globbed_dirs);
100101
Some config

jscomp/build_tests/build_warn_as_error/input.js

+36-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,47 @@ var p = require("child_process");
22
var assert = require("assert");
33
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
44

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

10-
var error_message = o.stdout
10+
var first_message = o1.stdout
1111
.split("\n")
1212
.map(s => s.trim())
13-
.includes("Warning number 110 (configured as error)");
13+
.find(s => s == "Warning number 110");
1414

15-
if (!error_message) {
16-
assert.fail(o.stdout);
15+
if (!first_message) {
16+
assert.fail(o1.stdout);
17+
}
18+
19+
// Second build using -warn-error +110
20+
var o2 = p.spawnSync(rescript_exe, ["build", "-warn-error", "+110"], {
21+
encoding: "utf8",
22+
cwd: __dirname,
23+
});
24+
25+
var second_message = o2.stdout
26+
.split("\n")
27+
.map(s => s.trim())
28+
.find(s => s == "Warning number 110 (configured as error)");
29+
30+
if (!second_message) {
31+
assert.fail(o2.stdout);
32+
}
33+
34+
// Third build, without -warn-error +110
35+
// The result should not be a warning as error
36+
var o3 = p.spawnSync(rescript_exe, ["build"], {
37+
encoding: "utf8",
38+
cwd: __dirname,
39+
});
40+
41+
var third_message = o3.stdout
42+
.split("\n")
43+
.map(s => s.trim())
44+
.find(s => s == "Dependency Finished");
45+
46+
if (!third_message) {
47+
assert.fail(o3.stdout);
1748
}

0 commit comments

Comments
 (0)