Skip to content

Commit 69c3185

Browse files
authored
Merge pull request #4431 from BuckleScript/build_dev
refactor build
2 parents 0904880 + 68574b5 commit 69c3185

19 files changed

+301
-193
lines changed

jscomp/bsb/bsb_build_schemas.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ let dev = "dev"
6161
let export_all = "all"
6262
let export_none = "none"
6363

64-
let bsb_dir_group = "bsb_dir_group"
64+
6565
let g_lib_incls = "g_lib_incls"
6666
let use_stdlib = "use-stdlib"
6767
let reason = "reason"

jscomp/bsb/bsb_config_parse.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,6 @@ let extract_reason_react_jsx (map : json_map) =
261261
match Map_string.find_opt m Bsb_build_schemas.react_jsx with
262262
| Some (Flo{loc; flo}) ->
263263
begin match flo with
264-
| "2" ->
265-
default := Some Jsx_v2
266264
| "3" ->
267265
default := Some Jsx_v3
268266
| _ -> Bsb_exception.errorf ~loc "Unsupported jsx version %s" flo

jscomp/bsb/bsb_config_types.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ type entries_t = JsTarget of string | NativeTarget of string | BytecodeTarget of
3636
type compilation_kind_t = Js | Bytecode | Native
3737

3838
type reason_react_jsx =
39-
| Jsx_v2
4039
| Jsx_v3
4140
(* string option *)
4241

jscomp/bsb/bsb_merlin_gen.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ let merlin_file_gen ~per_proj_dir:(per_proj_dir:string)
156156
else "'%s -as-ppx -bs-jsx %d'"
157157
in
158158
Printf.sprintf fmt Bsb_global_paths.vendor_bsc
159-
(match opt with Jsx_v2 -> 2 | Jsx_v3 -> 3)
159+
(match opt with Jsx_v3 -> 3)
160160
)
161161
);
162162
Ext_list.iter external_includes (fun path ->

jscomp/bsb/bsb_ninja_file_groups.ml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,7 @@ let emit_module_build
110110
oc
111111
~outputs:[output_d]
112112
~inputs:(if has_intf_file then [output_mlast;output_mliast] else [output_mlast] )
113-
~rule:rules.build_bin_deps
114-
?shadows:(if is_dev then
115-
Some [{Bsb_ninja_targets.key = Bsb_build_schemas.bsb_dir_group ;
116-
op =
117-
Overwrite "-g" }]
118-
else None)
113+
~rule:(if is_dev then rules.build_bin_deps_dev else rules.build_bin_deps)
119114
;
120115
if has_intf_file then begin
121116
Bsb_ninja_targets.output_build oc

jscomp/bsb/bsb_ninja_rule.ml

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ type builtin = {
9494
copy_resources : t;
9595
(** Rules below all need restat *)
9696
build_bin_deps : t ;
97-
97+
build_bin_deps_dev : t;
9898
ml_cmj_js : t;
9999
ml_cmj_js_dev : t;
100100
ml_cmj_cmi_js : t ;
@@ -123,55 +123,53 @@ let make_custom_rules
123123
builtin =
124124
(** FIXME: We don't need set [-o ${out}] when building ast
125125
since the default is already good -- it does not*)
126-
let buf = Buffer.create 100 in
126+
let buf = Ext_buffer.create 100 in
127127
let mk_ml_cmj_cmd
128128
~read_cmi
129129
~is_dev
130130
~postbuild : string =
131-
Buffer.clear buf;
132-
Buffer.add_string buf "$bsc $g_pkg_flg -color always";
131+
Ext_buffer.clear buf;
132+
Ext_buffer.add_string buf "$bsc $g_pkg_flg -color always";
133133
if bs_suffix then
134-
Buffer.add_string buf " -bs-suffix";
134+
Ext_buffer.add_string buf " -bs-suffix";
135135
if read_cmi then
136-
Buffer.add_string buf " -bs-read-cmi";
136+
Ext_buffer.add_string buf " -bs-read-cmi";
137137
if is_dev then
138-
Buffer.add_string buf " $g_dev_incls";
139-
Buffer.add_string buf " $g_lib_incls" ;
138+
Ext_buffer.add_ninja_prefix_var buf Bsb_ninja_global_vars.g_dev_incls;
139+
Ext_buffer.add_ninja_prefix_var buf Bsb_build_schemas.g_lib_incls;
140140
if is_dev then
141-
Buffer.add_string buf " $g_dpkg_incls";
141+
Ext_buffer.add_ninja_prefix_var buf Bsb_ninja_global_vars.g_dpkg_incls;
142142
if not has_builtin then
143-
Buffer.add_string buf " -nostdlib";
144-
Buffer.add_string buf " $warnings $bsc_flags";
143+
Ext_buffer.add_string buf " -nostdlib";
144+
Ext_buffer.add_string buf " $warnings $bsc_flags";
145145
if has_gentype then
146-
Buffer.add_string buf " $gentypeconfig";
147-
Buffer.add_string buf " -o $out $in";
146+
Ext_buffer.add_ninja_prefix_var buf Bsb_ninja_global_vars.gentypeconfig;
147+
Ext_buffer.add_string buf " -o $out $in";
148148
if postbuild then
149-
Buffer.add_string buf " $postbuild";
150-
Buffer.contents buf
149+
Ext_buffer.add_string buf " $postbuild";
150+
Ext_buffer.contents buf
151151
in
152152
let mk_ast ~(has_pp : bool) ~has_ppx ~has_reason_react_jsx : string =
153-
Buffer.clear buf ;
154-
Buffer.add_string buf "$bsc $warnings -color always";
153+
Ext_buffer.clear buf ;
154+
Ext_buffer.add_string buf "$bsc $warnings -color always";
155155
(match refmt with
156156
| None -> ()
157157
| Some x ->
158-
Buffer.add_string buf " -bs-refmt ";
159-
Buffer.add_string buf (Ext_filename.maybe_quote x);
158+
Ext_buffer.add_string buf " -bs-refmt ";
159+
Ext_buffer.add_string buf (Ext_filename.maybe_quote x);
160160
);
161161
if has_pp then
162-
Buffer.add_string buf " $pp_flags";
162+
Ext_buffer.add_ninja_prefix_var buf Bsb_ninja_global_vars.pp_flags;
163163
(match has_reason_react_jsx, reason_react_jsx with
164164
| false, _
165165
| _, None -> ()
166-
| _, Some Jsx_v2
167-
-> Buffer.add_string buf " -bs-jsx 2"
168166
| _, Some Jsx_v3
169-
-> Buffer.add_string buf " -bs-jsx 3"
167+
-> Ext_buffer.add_string buf " -bs-jsx 3"
170168
);
171169
if has_ppx then
172-
Buffer.add_string buf " $ppx_flags";
173-
Buffer.add_string buf " $bsc_flags -o $out -bs-syntax-only -bs-binary-ast $in";
174-
Buffer.contents buf
170+
Ext_buffer.add_ninja_prefix_var buf Bsb_ninja_global_vars.ppx_flags;
171+
Ext_buffer.add_string buf " $bsc_flags -o $out -bs-syntax-only -bs-binary-ast $in";
172+
Ext_buffer.contents buf
175173
in
176174
let build_ast =
177175
define
@@ -194,8 +192,14 @@ let make_custom_rules
194192
define
195193
~restat:()
196194
~command:
197-
("$bsdep -hash " ^ digest ^" $g_ns $bsb_dir_group $in")
198-
"build_deps" in
195+
("$bsdep -hash " ^ digest ^" $g_ns $in")
196+
"mk_deps" in
197+
let build_bin_deps_dev =
198+
define
199+
~restat:()
200+
~command:
201+
("$bsdep -g -hash " ^ digest ^" $g_ns $in")
202+
"mk_deps_dev" in
199203
let aux ~name ~read_cmi ~postbuild =
200204
let postbuild = has_postbuild && postbuild in
201205
define
@@ -239,7 +243,7 @@ let make_custom_rules
239243
copy_resources;
240244
(** Rules below all need restat *)
241245
build_bin_deps ;
242-
246+
build_bin_deps_dev;
243247
ml_cmj_js ;
244248
ml_cmj_js_dev ;
245249
ml_cmj_cmi_js ;

jscomp/bsb/bsb_ninja_rule.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type builtin = {
4545
copy_resources : t;
4646
(** Rules below all need restat *)
4747
build_bin_deps : t ;
48-
48+
build_bin_deps_dev : t ;
4949
ml_cmj_js : t;
5050
ml_cmj_js_dev : t;
5151
ml_cmj_cmi_js : t ;

jscomp/ext/ext_buffer.ml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ let contents b = Bytes.sub_string b.buffer 0 b.position
4848

4949
let length b = b.position
5050
let is_empty b = b.position = 0
51-
(* let clear b = b.position <- 0 *)
51+
let clear b = b.position <- 0
5252

5353
(* let reset b =
5454
b.position <- 0; b.buffer <- b.initial_buffer;
@@ -121,6 +121,19 @@ let add_char_string b c s =
121121
Ext_bytes.unsafe_blit_string s 0 b_buffer (b_position + 1) s_len;
122122
b.position <- new_position
123123

124+
(* equivalent to add_char " "; add_char "$"; add_string s *)
125+
let add_ninja_prefix_var b s =
126+
let s_len = String.length s in
127+
let len = s_len + 2 in
128+
let new_position = b.position + len in
129+
if new_position > b.length then resize b len;
130+
let b_buffer = b.buffer in
131+
let b_position = b.position in
132+
Bytes.unsafe_set b_buffer b_position ' ' ;
133+
Bytes.unsafe_set b_buffer (b_position + 1) '$' ;
134+
Ext_bytes.unsafe_blit_string s 0 b_buffer (b_position + 2) s_len;
135+
b.position <- new_position
136+
124137

125138
(* let add_bytes b s = add_string b (Bytes.unsafe_to_string s)
126139

jscomp/ext/ext_buffer.mli

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ val length : t -> int
4747

4848
val is_empty : t -> bool
4949

50-
(* val clear : t -> unit *)
50+
val clear : t -> unit
5151
(** Empty the buffer. *)
5252

5353

@@ -108,7 +108,13 @@ val add_string_char :
108108
string ->
109109
char ->
110110
unit
111-
111+
112+
val add_ninja_prefix_var :
113+
t ->
114+
string ->
115+
unit
116+
117+
112118
val add_char_string :
113119
t ->
114120
char ->

jscomp/main/builtin_cmi_datasets.ml

Lines changed: 1 addition & 5 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)