Skip to content

Commit 6fd866c

Browse files
authored
Merge pull request #4747 from rescript-lang/no_package_name_in_cmi
various improvements over incremental build
2 parents a88c523 + bb327ad commit 6fd866c

19 files changed

+173
-99
lines changed

jscomp/bsb/bsb_ninja_file_groups.ml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ let emit_module_build
8080
(package_specs : Bsb_package_specs.t)
8181
(is_dev : bool)
8282
oc
83-
js_post_build_cmd
8483
namespace
8584
(module_info : Bsb_db.module_info)
8685
=
@@ -131,15 +130,6 @@ let emit_module_build
131130
~rule:(if is_dev then rules.mi_dev else rules.mi)
132131
;
133132
end;
134-
135-
let shadows : Bsb_ninja_targets.shadow list =
136-
match js_post_build_cmd with
137-
| None -> []
138-
| Some cmd ->
139-
[{key = Bsb_ninja_global_vars.postbuild;
140-
op = Overwrite ("&& " ^ cmd ^ Ext_string.single_space ^ String.concat Ext_string.single_space output_js)}]
141-
142-
in
143133
let rule =
144134
if has_intf_file then
145135
(if is_dev then rules.mj_dev
@@ -151,7 +141,6 @@ let emit_module_build
151141
in
152142
Bsb_ninja_targets.output_build oc
153143
~outputs:[output_cmj]
154-
~shadows
155144
~implicit_outputs:
156145
(if has_intf_file then output_js else output_cmi::output_js )
157146
~inputs:[output_mlast]
@@ -170,7 +159,6 @@ let handle_files_per_dir
170159
oc
171160
~(rules : Bsb_ninja_rule.builtin)
172161
~package_specs
173-
~js_post_build_cmd
174162
~(files_to_install : Hash_set_string.t)
175163
~(namespace : string option)
176164
(group: Bsb_file_groups.file_group )
@@ -192,7 +180,6 @@ let handle_files_per_dir
192180
package_specs
193181
group.dev_index
194182
oc
195-
js_post_build_cmd
196183
namespace module_info
197184
)
198185

jscomp/bsb/bsb_ninja_file_groups.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ val handle_files_per_dir :
2929
out_channel ->
3030
rules:Bsb_ninja_rule.builtin ->
3131
package_specs:Bsb_package_specs.t ->
32-
js_post_build_cmd:string option ->
3332
files_to_install:Hash_set_string.t ->
3433
namespace:string option ->
3534
Bsb_file_groups.file_group -> unit

jscomp/bsb/bsb_ninja_gen.ml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,11 @@ let output_ninja_and_namespace_map
122122
let cwd_lib_bs = per_proj_dir // lib_artifacts_dir in
123123
let ppx_flags = Bsb_build_util.ppx_flags ppx_files in
124124
let oc = open_out_bin (cwd_lib_bs // Literals.build_ninja) in
125-
let g_pkg_flg , g_ns_flg =
126-
match namespace with
127-
| None ->
128-
Ext_string.inter2 "-bs-package-name" package_name, Ext_string.empty
129-
| Some s ->
130-
Ext_string.inter4
131-
"-bs-package-name" package_name
132-
"-bs-ns" s
133-
,
134-
Ext_string.inter2 "-bs-ns" s in
125+
let g_pkg_flg =
126+
Ext_string.inter2 "-bs-package-name" package_name
127+
in
128+
let warnings = Bsb_warning.to_bsb_string ~toplevel warning in
129+
let bsc_flags = (get_bsc_flags bsc_flags) in
135130
let () =
136131
Ext_option.iter pp_file (fun flag ->
137132
Bsb_ninja_targets.output_kv Bsb_ninja_global_vars.pp_flags
@@ -150,15 +145,15 @@ let output_ninja_and_namespace_map
150145
Bsb_ninja_global_vars.bsc, (Ext_filename.maybe_quote Bsb_global_paths.vendor_bsc);
151146
(* The path to [bsb_heler.exe] *)
152147
Bsb_ninja_global_vars.bsdep, (Ext_filename.maybe_quote Bsb_global_paths.vendor_bsdep) ;
153-
Bsb_ninja_global_vars.warnings, Bsb_warning.to_bsb_string ~toplevel warning ;
154-
Bsb_ninja_global_vars.bsc_flags, (get_bsc_flags bsc_flags) ;
148+
Bsb_ninja_global_vars.warnings, warnings;
149+
Bsb_ninja_global_vars.bsc_flags, bsc_flags;
155150
Bsb_ninja_global_vars.ppx_flags, ppx_flags;
156151

157152
Bsb_ninja_global_vars.g_dpkg_incls,
158153
(Bsb_build_util.include_dirs_by
159154
bs_dev_dependencies
160155
(fun x -> x.package_install_path));
161-
Bsb_ninja_global_vars.g_ns , g_ns_flg ;
156+
162157
|] oc
163158
in
164159
let bs_groups : Bsb_db.t = {lib = Map_string.empty; dev = Map_string.empty} in
@@ -199,12 +194,13 @@ let output_ninja_and_namespace_map
199194
Bsb_ninja_rule.make_custom_rules
200195
~refmt
201196
~has_gentype:(gentype_config <> None)
202-
~has_postbuild:(js_post_build_cmd <> None)
197+
~has_postbuild:js_post_build_cmd
203198
~has_ppx:(ppx_files <> [])
204199
~has_pp:(pp_file <> None)
205200
~has_builtin:(built_in_dependency <> None)
206201
~reason_react_jsx
207202
~package_specs
203+
~namespace
208204
~digest
209205
generators in
210206
emit_bsc_lib_includes bs_dependencies source_dirs.lib external_includes namespace oc;
@@ -214,7 +210,6 @@ let output_ninja_and_namespace_map
214210
(fun files_per_dir ->
215211
Bsb_ninja_file_groups.handle_files_per_dir oc
216212
~rules
217-
~js_post_build_cmd
218213
~package_specs
219214
~files_to_install
220215
~namespace files_per_dir)

jscomp/bsb/bsb_ninja_global_vars.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let refmt_flags = "refmt_flags"
4646

4747
let postbuild = "postbuild"
4848

49-
let g_ns = "g_ns"
49+
5050

5151
let warnings = "warnings"
5252

jscomp/bsb/bsb_ninja_rule.ml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ let print_rule (oc : out_channel)
5050
begin match description with
5151
| None -> ()
5252
| Some description ->
53-
output_string oc " description = " ; output_string oc description
54-
end ;
55-
output_string oc "\n"
53+
output_string oc " description = " ; output_string oc description;
54+
output_string oc "\n"
55+
end
56+
5657

5758

5859

@@ -114,27 +115,35 @@ type builtin = {
114115

115116
let make_custom_rules
116117
~(has_gentype : bool)
117-
~(has_postbuild : bool)
118+
~(has_postbuild : string option)
118119
~(has_ppx : bool)
119120
~(has_pp : bool)
120121
~(has_builtin : bool)
121122
~(reason_react_jsx : Bsb_config_types.reason_react_jsx option)
122123
~(digest : string)
123124
~(refmt : string option) (* set refmt path when needed *)
124125
~(package_specs: Bsb_package_specs.t)
126+
~namespace
125127
(custom_rules : command Map_string.t) :
126128
builtin =
127129
(** FIXME: We don't need set [-o ${out}] when building ast
128130
since the default is already good -- it does not*)
129131
let buf = Ext_buffer.create 100 in
132+
let ns_flag =
133+
match namespace with None -> ""
134+
| Some n -> " -bs-ns " ^ n in
130135
let mk_ml_cmj_cmd
131136
~(read_cmi : [`yes | `is_cmi | `no])
132137
~is_dev
133138
~postbuild : string =
134139
Ext_buffer.clear buf;
135140
Ext_buffer.add_string buf "$bsc";
136-
Ext_buffer.add_ninja_prefix_var buf Bsb_ninja_global_vars.g_pkg_flg;
137-
Ext_buffer.add_string buf (Bsb_package_specs.package_flag_of_package_specs package_specs "$in_d");
141+
142+
Ext_buffer.add_string buf ns_flag;
143+
if read_cmi <> `is_cmi then begin
144+
Ext_buffer.add_ninja_prefix_var buf Bsb_ninja_global_vars.g_pkg_flg;
145+
Ext_buffer.add_string buf (Bsb_package_specs.package_flag_of_package_specs package_specs "$in_d")
146+
end;
138147
if read_cmi = `yes then
139148
Ext_buffer.add_string buf " -bs-read-cmi";
140149
if is_dev then
@@ -148,8 +157,13 @@ let make_custom_rules
148157
if has_gentype then
149158
Ext_buffer.add_ninja_prefix_var buf Bsb_ninja_global_vars.gentypeconfig;
150159
Ext_buffer.add_string buf " -o $out $in";
151-
if postbuild then
152-
Ext_buffer.add_string buf " $postbuild";
160+
begin match postbuild with
161+
| None -> ()
162+
| Some cmd ->
163+
Ext_buffer.add_string buf " && ";
164+
Ext_buffer.add_string buf cmd ;
165+
Ext_buffer.add_string buf " $out_last"
166+
end ;
153167
Ext_buffer.contents buf
154168
in
155169
let mk_ast ~(has_pp : bool) ~has_ppx ~has_reason_react_jsx : string =
@@ -172,7 +186,7 @@ let make_custom_rules
172186
);
173187
if has_ppx then
174188
Ext_buffer.add_ninja_prefix_var buf Bsb_ninja_global_vars.ppx_flags;
175-
Ext_buffer.add_string buf " $bsc_flags -o $out -bs-syntax-only -bs-binary-ast $in";
189+
Ext_buffer.add_string buf " $bsc_flags -o $out -bs-ast $in";
176190
Ext_buffer.contents buf
177191
in
178192
let build_ast =
@@ -192,17 +206,18 @@ let make_custom_rules
192206
else "cp $in $out"
193207
)
194208
"copy_resource" in
209+
195210
let build_bin_deps =
196211
define
197212
~restat:()
198213
~command:
199-
("$bsdep -hash " ^ digest ^" $g_ns $in")
214+
("$bsdep -hash " ^ digest ^ ns_flag ^ " $in")
200215
"deps" in
201216
let build_bin_deps_dev =
202217
define
203218
~restat:()
204219
~command:
205-
("$bsdep -g -hash " ^ digest ^" $g_ns $in")
220+
("$bsdep -g -hash " ^ digest ^ ns_flag ^ " $in")
206221
"deps_dev" in
207222
let aux ~name ~read_cmi ~postbuild =
208223
define
@@ -229,7 +244,7 @@ let make_custom_rules
229244
~name:"mij" ~postbuild:has_postbuild in
230245
let mi, mi_dev =
231246
aux
232-
~read_cmi:`is_cmi ~postbuild:false
247+
~read_cmi:`is_cmi ~postbuild:None
233248
~name:"mi" in
234249
let build_package =
235250
define

jscomp/bsb/bsb_ninja_rule.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,15 @@ type command = string
7070
*)
7171
val make_custom_rules :
7272
has_gentype:bool ->
73-
has_postbuild:bool ->
73+
has_postbuild:string option ->
7474
has_ppx:bool ->
7575
has_pp:bool ->
7676
has_builtin:bool ->
7777
reason_react_jsx : Bsb_config_types.reason_react_jsx option ->
7878
digest:string ->
7979
refmt:string option ->
8080
package_specs:Bsb_package_specs.t ->
81+
namespace:string option ->
8182
command Map_string.t ->
8283
builtin
8384

jscomp/bsb/bsb_ninja_targets.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ let output_build
5757
~rule
5858
oc =
5959
let rule = Bsb_ninja_rule.get_name rule oc in (* Trigger building if not used *)
60-
output_string oc "o ";
60+
output_string oc "o";
6161
Ext_list.iter outputs (fun s -> output_string oc Ext_string.single_space ; output_string oc s );
6262
if implicit_outputs <> [] then begin
63-
output_string oc " | ";
63+
output_string oc " |";
6464
Ext_list.iter implicit_outputs (fun s -> output_string oc Ext_string.single_space ; output_string oc s)
6565
end;
6666
output_string oc " : ";
@@ -74,7 +74,7 @@ let output_build
7474
;
7575
if order_only_deps <> [] then
7676
begin
77-
output_string oc " || ";
77+
output_string oc " ||";
7878
Ext_list.iter order_only_deps (fun s -> output_string oc Ext_string.single_space ; output_string oc s)
7979
end
8080
;
@@ -146,6 +146,6 @@ let output_kv key value oc =
146146
output_string oc "\n"
147147

148148
let output_kvs kvs oc =
149-
Ext_array.iter kvs (fun (k,v) -> output_kv k v oc)
149+
Ext_array.iter kvs (fun (k,v) -> if v <> "" then output_kv k v oc)
150150

151151

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
*.exe
2+
*.obj
3+
*.out
4+
*.compile
5+
*.native
6+
*.byte
7+
*.cmo
8+
*.annot
9+
*.cmi
10+
*.cmx
11+
*.cmt
12+
*.cmti
13+
*.cma
14+
*.a
15+
*.cmxa
16+
*.obj
17+
*~
18+
*.annot
19+
*.cmj
20+
*.bak
21+
lib/bs
22+
*.mlast
23+
*.mliast
24+
.vscode
25+
.merlin
26+
.bsb.lock
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
3+
# Build
4+
```
5+
npm run build
6+
```
7+
8+
# Watch
9+
10+
```
11+
npm run watch
12+
```
13+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "post-build",
3+
"version": "0.1.0",
4+
"sources": {
5+
"dir" : "src",
6+
"subdirs" : true
7+
},
8+
"js-post-build": {"cmd":"cat"},
9+
"warnings": {
10+
"error" : "+101"
11+
}
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var child_process = require('child_process')
2+
var assert = require('assert')
3+
4+
var out = child_process.spawnSync(`bsb`,{encoding : 'utf8'})
5+
6+
if(out.status !== 0 ){
7+
assert.fail(out.stdout + out.stderr)
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "post-build",
3+
"version": "0.1.0",
4+
"scripts": {
5+
"clean": "bsb -clean-world",
6+
"build": "bsb -make-world",
7+
"watch": "bsb -make-world -w"
8+
},
9+
"keywords": [
10+
"BuckleScript"
11+
],
12+
"author": "",
13+
"license": "MIT",
14+
"devDependencies": {
15+
"bs-platform": "^8.3.0-dev.2"
16+
}
17+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
3+
let () = Js.log "Hello, BuckleScript"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let a = 3

jscomp/main/js_main.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
317317
"-bs-package-output", string_call Js_packages_state.update_npm_package_path,
318318
"*internal* Set npm-output-path: [opt_module]:path, for example: 'lib/cjs', 'amdjs:lib/amdjs', 'es6:lib/es6' ";
319319

320-
"-bs-binary-ast", set Js_config.binary_ast,
321-
"*internal* Generate binary .mli_ast and ml_ast";
320+
"-bs-ast", unit_call(fun _ -> Js_config.binary_ast := true; Js_config.syntax_only := true),
321+
"*internal* Generate binary .mli_ast and ml_ast and stop";
322322

323323
"-bs-syntax-only", set Js_config.syntax_only,
324324
"Only check syntax";

0 commit comments

Comments
 (0)