Skip to content

Commit 1d5c782

Browse files
committed
Bsc understand .re extension
1 parent f0bc8c6 commit 1d5c782

19 files changed

+144
-89
lines changed

jscomp/bsb/bsb_build_schemas.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ let ppx_flags = "ppx-flags"
3232
let pp_flags = "pp-flags"
3333
let bsc = "bsc"
3434
let refmt = "refmt"
35-
let refmt_flags = "refmt-flags"
35+
3636
let bs_external_includes = "bs-external-includes"
3737
let bs_lib_dir = "bs-lib-dir"
3838
let bs_dependencies = "bs-dependencies"

jscomp/bsb/bsb_config_parse.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,6 @@ let interpret_json
460460
]}
461461
*)
462462
refmt;
463-
refmt_flags =
464-
(let flags =
465-
extract_string_list map Bsb_build_schemas.refmt_flags in
466-
if flags = [] then Bsb_default.refmt_flags else flags) ;
467463
js_post_build_cmd = (extract_js_post_build map cwd);
468464
package_specs =
469465
(match toplevel_package_specs with

jscomp/bsb/bsb_config_types.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ type t =
7272
[.merlin]
7373
*)
7474
refmt : refmt;
75-
refmt_flags : string list;
7675
js_post_build_cmd : string option;
7776
package_specs : Bsb_package_specs.t ;
7877
file_groups : Bsb_file_groups.t;

jscomp/bsb/bsb_default.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525

2626

2727

28-
let refmt_flags = ["--print"; "binary"]
2928

30-
let refmt_v3 = "refmt.exe"
31-
let refmt_none = "refmt.exe"
29+
3230

3331
let main_entries = [Bsb_config_types.JsTarget "Index"]

jscomp/bsb/bsb_default.mli

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,4 @@
2626

2727

2828

29-
val refmt_flags : string list
30-
31-
val refmt_v3 : string
32-
33-
val refmt_none : string
34-
3529
val main_entries : Bsb_config_types.entries_t list

jscomp/bsb/bsb_ninja_file_groups.ml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,14 @@ let emit_module_build
9191
let is_re = module_info.is_re in
9292
let filename_sans_extension = module_info.name_sans_extension in
9393
let is_dev = not (Bsb_dir_index.is_lib_dir group_dir_index) in
94-
let input =
94+
let input_impl =
9595
Bsb_config.proj_rel
9696
(if is_re then filename_sans_extension ^ Literals.suffix_re
9797
else filename_sans_extension ^ Literals.suffix_ml ) in
98+
let input_intf =
99+
Bsb_config.proj_rel
100+
(if is_re then filename_sans_extension ^ Literals.suffix_rei
101+
else filename_sans_extension ^ Literals.suffix_mli) in
98102
let output_mlast = filename_sans_extension ^ Literals.suffix_mlast in
99103
let output_mliast = filename_sans_extension ^ Literals.suffix_mliast in
100104
let output_d = filename_sans_extension ^ Literals.suffix_d in
@@ -116,7 +120,7 @@ let emit_module_build
116120
rules.build_ast in
117121
Bsb_ninja_util.output_build oc
118122
~output:output_mlast
119-
~input
123+
~input:input_impl
120124
~rule:ast_rule;
121125
Bsb_ninja_util.output_build
122126
oc
@@ -136,9 +140,7 @@ let emit_module_build
136140
(* TODO: we can get rid of absloute path if we fixed the location to be
137141
[lib/bs], better for testing?
138142
*)
139-
~input:(Bsb_config.proj_rel
140-
(if is_re then filename_sans_extension ^ Literals.suffix_rei
141-
else filename_sans_extension ^ Literals.suffix_mli))
143+
~input:input_intf
142144
~rule:ast_rule
143145
;
144146
Bsb_ninja_util.output_build oc

jscomp/bsb/bsb_ninja_gen.ml

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,6 @@ let bsb_helper_exe = "bsb_helper.exe"
3636
let dash_i = "-I"
3737

3838

39-
let output_reason_config
40-
(has_reason_files : bool)
41-
(refmt : Bsb_config_types.refmt)
42-
(bsc_dir : string)
43-
(refmt_flags : string)
44-
(oc : out_channel) : unit =
45-
if has_reason_files then
46-
Bsb_ninja_util.output_kvs
47-
[|
48-
Bsb_ninja_global_vars.refmt,
49-
(Ext_filename.maybe_quote
50-
(match refmt with
51-
| Refmt_none ->
52-
Bsb_log.warn "@{<warning>Warning:@} refmt version missing. Please set it explicitly, since we may change the default in the future.@.";
53-
bsc_dir // Bsb_default.refmt_none
54-
| Refmt_v3 ->
55-
bsc_dir // Bsb_default.refmt_v3
56-
| Refmt_custom x -> x ));
57-
Bsb_ninja_global_vars.refmt_flags, refmt_flags;
58-
|] oc
5939

6040
let get_bsc_flags
6141
~(toplevel : bool)
@@ -130,7 +110,6 @@ let output_ninja_and_namespace_map
130110
bs_dependencies;
131111
bs_dev_dependencies;
132112
refmt;
133-
refmt_flags;
134113
js_post_build_cmd;
135114
package_specs;
136115
file_groups = { files = bs_file_groups};
@@ -147,9 +126,7 @@ let output_ninja_and_namespace_map
147126

148127
let cwd_lib_bs = cwd // Bsb_config.lib_bs in
149128
let ppx_flags = Bsb_build_util.ppx_flags ppx_files in
150-
let refmt_flags = String.concat Ext_string.single_space refmt_flags in
151129
let oc = open_out_bin (cwd_lib_bs // Literals.build_ninja) in
152-
let has_reason_files = ref false in
153130
let g_pkg_flg , g_ns_flg =
154131
match namespace with
155132
| None ->
@@ -209,7 +186,6 @@ let output_ninja_and_namespace_map
209186
else Ext_list.map_append resources acc_resources (fun x -> dir // x ) )
210187
) in
211188
Bsb_db_util.sanity_check bs_group;
212-
has_reason_files := !has_reason_files || Bsb_db.has_reason_files bs_group ;
213189
[|bs_group|], source_dirs, static_resources
214190
else
215191
let bs_groups = Array.init (number_of_dev_groups + 1 ) (fun i -> String_map.empty) in
@@ -224,11 +200,9 @@ let output_ninja_and_namespace_map
224200
) in
225201
let lib = bs_groups.((Bsb_dir_index.lib_dir_index :> int)) in
226202
Bsb_db_util.sanity_check lib;
227-
has_reason_files := !has_reason_files || Bsb_db.has_reason_files lib ;
228203
for i = 1 to number_of_dev_groups do
229204
let c = bs_groups.(i) in
230205
Bsb_db_util.sanity_check c;
231-
has_reason_files := !has_reason_files || Bsb_db.has_reason_files c ;
232206
String_map.iter c
233207
(fun k a ->
234208
if String_map.mem lib k then
@@ -241,10 +215,12 @@ let output_ninja_and_namespace_map
241215
bs_groups,source_dirs.((Bsb_dir_index.lib_dir_index:>int)), static_resources
242216
in
243217

244-
output_reason_config !has_reason_files refmt bsc_dir refmt_flags oc;
245218
let digest = Bsb_db_encode.write_build_cache ~dir:cwd_lib_bs bs_groups in
246219
let rules : Bsb_ninja_rule.builtin =
247220
Bsb_ninja_rule.make_custom_rules
221+
~refmt:(match refmt with
222+
| Refmt_none | Refmt_v3 -> None
223+
| Refmt_custom x -> Some x)
248224
~has_gentype:(gentype_config <> None)
249225
~has_postbuild:(js_post_build_cmd <> None)
250226
~has_ppx:(ppx_files <> [])

jscomp/bsb/bsb_ninja_rule.ml

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ let make_custom_rules
123123
~(bs_suffix : bool)
124124
~(reason_react_jsx : Bsb_config_types.reason_react_jsx option)
125125
~(digest : string)
126+
~(refmt : string option) (* set refmt path when needed *)
126127
(custom_rules : command String_map.t) :
127128
builtin =
128129
(** FIXME: We don't need set [-o ${out}] when building ast
@@ -137,6 +138,7 @@ let make_custom_rules
137138
Buffer.add_string buf "$bsc -nostdlib $g_pkg_flg -color always";
138139
if bs_suffix then
139140
Buffer.add_string buf " -bs-suffix";
141+
(* TODO: see if we set this dynamically *)
140142
if is_re then
141143
Buffer.add_string buf " -bs-re-out -bs-super-errors";
142144
if read_cmi then
@@ -156,21 +158,24 @@ let make_custom_rules
156158
Buffer.add_string buf " $postbuild";
157159
Buffer.contents buf
158160
in
159-
let mk_ast ~has_pp ~has_ppx ~has_reason_react_jsx : string =
161+
let mk_ast ~(has_pp : bool) ~has_ppx ~has_reason_react_jsx : string =
160162
Buffer.clear buf ;
161163
Buffer.add_string buf "$bsc $warnings -color always";
162-
(match has_pp with
163-
| `regular -> Buffer.add_string buf " $pp_flags"
164-
| `refmt -> Buffer.add_string buf {| -pp "$refmt $refmt_flags"|}
165-
| `none -> ()
166-
);
164+
(match refmt with
165+
| None -> ()
166+
| Some x ->
167+
Buffer.add_string buf " -refmt ";
168+
Buffer.add_string buf (Ext_filename.maybe_quote x);
169+
);
170+
if has_pp then
171+
Buffer.add_string buf " $pp_flags";
167172
(match has_reason_react_jsx, reason_react_jsx with
168-
| false, _
169-
| _, None -> ()
170-
| _, Some Jsx_v2
171-
-> Buffer.add_string buf " -bs-jsx 2"
172-
| _, Some Jsx_v3
173-
-> Buffer.add_string buf " -bs-jsx 3"
173+
| false, _
174+
| _, None -> ()
175+
| _, Some Jsx_v2
176+
-> Buffer.add_string buf " -bs-jsx 2"
177+
| _, Some Jsx_v3
178+
-> Buffer.add_string buf " -bs-jsx 3"
174179
);
175180
if has_ppx then
176181
Buffer.add_string buf " $ppx_flags";
@@ -179,12 +184,12 @@ let make_custom_rules
179184
in
180185
let build_ast =
181186
define
182-
~command:(mk_ast ~has_pp:(if has_pp then `regular else `none) ~has_ppx ~has_reason_react_jsx:false )
183-
"build_ast_and_module_sets" in
187+
~command:(mk_ast ~has_pp ~has_ppx ~has_reason_react_jsx:false )
188+
"build_ast" in
184189
let build_ast_from_re =
185190
define
186-
~command:(mk_ast ~has_pp:`refmt ~has_ppx ~has_reason_react_jsx:true)
187-
"build_ast_and_module_sets_from_re" in
191+
~command:(mk_ast ~has_pp ~has_ppx ~has_reason_react_jsx:true)
192+
"build_ast_from_re" in
188193

189194
let copy_resources =
190195
define

jscomp/bsb/bsb_ninja_rule.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ val make_custom_rules :
8282
bs_suffix:bool ->
8383
reason_react_jsx : Bsb_config_types.reason_react_jsx option ->
8484
digest:string ->
85+
refmt:string option ->
8586
command String_map.t ->
8687
builtin
8788

jscomp/common/js_config.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,6 @@ let cmi_only = ref false
109109
let force_cmi = ref false
110110
let force_cmj = ref false
111111

112-
let jsx_version = ref (-1)
112+
let jsx_version = ref (-1)
113+
114+
let refmt = ref None

0 commit comments

Comments
 (0)