Skip to content

Commit ad61bb6

Browse files
committed
1 parent c51a64b commit ad61bb6

12 files changed

+94
-18
lines changed

bsconfig.json

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
// [
1717
// "reason/bin/ppx_lwt"
1818
// ],
19+
"js-post-build" :
20+
{
21+
"cmd" : "/bin/cat"
22+
},
1923
"sources" :
2024
[
2125

docs/docson/build-schema.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,14 @@
180180
"bs-dependencies": {
181181
"$ref": "#/definitions/bs-dependencies",
182182
"description" : "OCaml dependencies applied to all modules inside"
183-
},
183+
},
184184
"properties": {
185+
"js-post-build" : {
186+
"cmd" : {
187+
"type" : "string"
188+
},
189+
"description": "Experimental, the build system will invoke `cmd ${file}` whenever a ${file} is generated"
190+
},
185191
"ppx-flags": {
186192
"$ref": "#/definitions/ppx-specs",
187193
"description": "TODO: ppx flags"

jscomp/bin/bsb.ml

+36-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ let excludes = "excludes"
2424
let slow_re = "slow-re"
2525
let resources = "resources"
2626
let public = "public"
27+
let js_post_build = "js-post-build"
28+
let cmd = "cmd"
2729

2830
end
2931
module Ext_pervasives : sig
@@ -4987,6 +4989,10 @@ val get_refmt : unit -> string
49874989
val get_bs_dependencies : unit -> string list
49884990
val set_bs_dependencies : Bsb_json.t array -> unit
49894991

4992+
4993+
val get_js_post_build_cmd : unit -> string option
4994+
val set_js_post_build_cmd : cwd:string -> string -> unit
4995+
49904996
end = struct
49914997
#1 "bsb_default.ml"
49924998
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -5081,6 +5087,12 @@ let set_ppx_flags ~cwd s =
50815087
) in
50825088
ppx_flags := s
50835089

5090+
5091+
let js_post_build_cmd = ref None
5092+
let get_js_post_build_cmd () = !js_post_build_cmd
5093+
let set_js_post_build_cmd ~cwd s =
5094+
js_post_build_cmd := Some (resolve_bsb_magic_path ~cwd ~desc:"js-post-build:cmd" s )
5095+
50845096
end
50855097
module Bsb_dep_infos : sig
50865098
#1 "bsb_dep_infos.mli"
@@ -5302,6 +5314,7 @@ val output_kvs : (string * string) list -> out_channel -> unit
53025314

53035315
type info = string list * string list
53045316
val handle_file_groups : out_channel ->
5317+
js_post_build_cmd:string option ->
53055318
Bsb_build_ui.file_group list ->
53065319
info -> info
53075320

@@ -5433,15 +5446,15 @@ module Rules = struct
54335446
let build_cmj_js =
54345447
define
54355448
~command:"${bsc} ${bs_package_flags} -bs-no-builtin-ppx-ml -bs-no-implicit-include \
5436-
${bs_package_includes} ${bsc_includes} ${bsc_flags} -o ${in} -c -impl ${in}"
5449+
${bs_package_includes} ${bsc_includes} ${bsc_flags} -o ${in} -c -impl ${in} ${postbuild}"
54375450

54385451
~depfile:"${in}.d"
54395452
"build_cmj_only"
54405453

54415454
let build_cmi_cmj_js =
54425455
define
54435456
~command:"${bsc} ${bs_package_flags} -bs-assume-no-mli -bs-no-builtin-ppx-ml -bs-no-implicit-include \
5444-
${bs_package_includes} ${bsc_includes} ${bsc_flags} -o ${in} -c -impl ${in}"
5457+
${bs_package_includes} ${bsc_includes} ${bsc_flags} -o ${in} -c -impl ${in} ${postbuild}"
54455458
~depfile:"${in}.d"
54465459
"build_cmj_cmi"
54475460
let build_cmi =
@@ -5556,7 +5569,7 @@ let (++) (us : info) (vs : info) =
55565569

55575570

55585571

5559-
let handle_file_group oc acc (group: Bsb_build_ui.file_group) =
5572+
let handle_file_group oc ~js_post_build_cmd acc (group: Bsb_build_ui.file_group) =
55605573
let handle_module_info oc module_name
55615574
( module_info : Binary_cache.module_info)
55625575
bs_dependencies
@@ -5628,7 +5641,13 @@ let handle_file_group oc acc (group: Bsb_build_ui.file_group) =
56285641
[ output_cmi] , []
56295642
else Rules.build_cmi_cmj_js, [], [output_cmi]
56305643
in
5631-
5644+
let shadows =
5645+
match js_post_build_cmd with
5646+
| None -> shadows
5647+
| Some cmd ->
5648+
("postbuild",
5649+
`Overwrite ("&& " ^ cmd ^ " " ^ output_js)) :: shadows
5650+
in
56325651
output_build oc
56335652
~output:output_cmj
56345653
~shadows
@@ -5708,8 +5727,8 @@ let handle_file_group oc acc (group: Bsb_build_ui.file_group) =
57085727
handle_module_info oc k v group.bs_dependencies acc
57095728
) group.sources acc
57105729

5711-
let handle_file_groups oc (file_groups : Bsb_build_ui.file_group list) st =
5712-
List.fold_left (handle_file_group oc) st file_groups
5730+
let handle_file_groups oc ~js_post_build_cmd (file_groups : Bsb_build_ui.file_group list) st =
5731+
List.fold_left (handle_file_group oc ~js_post_build_cmd ) st file_groups
57135732

57145733
end
57155734
module Bsb_gen : sig
@@ -5742,6 +5761,7 @@ module Bsb_gen : sig
57425761
val output_ninja :
57435762
builddir:string ->
57445763
cwd:string ->
5764+
js_post_build_cmd:string option ->
57455765
string ->
57465766
string ->
57475767
string option ->
@@ -5785,6 +5805,7 @@ let (//) = Ext_filename.combine
57855805
let output_ninja
57865806
~builddir
57875807
~cwd
5808+
~js_post_build_cmd
57885809
bsc
57895810
bsdep
57905811
package_name
@@ -5795,6 +5816,7 @@ let output_ninja
57955816
ppx_flags
57965817
bs_dependencies
57975818
refmt
5819+
57985820
=
57995821
let ppx_flags = Bsb_build_util.flag_concat "-ppx" ppx_flags in
58005822
let bs_groups, source_dirs,static_resources =
@@ -5847,7 +5869,7 @@ let output_ninja
58475869
]
58485870
in
58495871
let all_deps, all_cmis =
5850-
Bsb_ninja.handle_file_groups oc bs_file_groups ([],[]) in
5872+
Bsb_ninja.handle_file_groups oc ~js_post_build_cmd bs_file_groups ([],[]) in
58515873
let all_deps =
58525874
(* we need copy package.json into [_build] since it does affect build output *)
58535875
(* Literals.package_json ::
@@ -5931,6 +5953,11 @@ let write_ninja_file cwd =
59315953
|?
59325954
(Bsb_build_schemas.ocaml_config, `Obj begin fun m ->
59335955
m
5956+
|? (Bsb_build_schemas.js_post_build, `Obj begin fun m ->
5957+
m |? (Bsb_build_schemas.cmd , `Str (Bsb_default.set_js_post_build_cmd ~cwd)
5958+
)
5959+
|> ignore
5960+
end)
59345961
|? (Bsb_build_schemas.ocamllex, `Str Bsb_default.set_ocamllex)
59355962
|? (Bsb_build_schemas.bs_dependencies, `Arr Bsb_default.set_bs_dependencies)
59365963
(* More design *)
@@ -5962,7 +5989,7 @@ let write_ninja_file cwd =
59625989
Unix.unlink Literals.bsconfig_json;
59635990
Unix.rename config_file_bak Literals.bsconfig_json
59645991
end;
5965-
Bsb_gen.output_ninja ~builddir ~cwd
5992+
Bsb_gen.output_ninja ~builddir ~cwd ~js_post_build_cmd: Bsb_default.(get_js_post_build_cmd ())
59665993
bsc
59675994
bsdep
59685995
(Bsb_default.get_package_name ())
@@ -5973,6 +6000,7 @@ let write_ninja_file cwd =
59736000
Bsb_default.(get_ppx_flags ())
59746001
Bsb_default.(get_bs_dependencies ())
59756002
Bsb_default.(get_refmt ())
6003+
59766004
;
59776005
!globbed_dirs
59786006

jscomp/bsb/bsb.adoc

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,14 @@ All output (not just js in case we support native build)
77

88
It's hard to bake it in built rules, since it is flag dependent, if you have `-bin-annot`
99
then you would like to install `cmt` too, however, it might be or not be there
10-
10+
11+
# post-build
12+
13+
Here we have `js` generated, we can do either post-build or
14+
create a new rule.
15+
16+
Note creating new rules will get more concurrency while post-build is easy
17+
and can do in source modification
18+
19+
https://groups.google.com/forum/#!searchin/ninja-build/post$20process%7Csort:relevance/ninja-build/Q4hpcDmhPzw/KZpDyOEFuTkJ
20+

jscomp/bsb/bsb_build_schemas.ml

+2
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ let excludes = "excludes"
2121
let slow_re = "slow-re"
2222
let resources = "resources"
2323
let public = "public"
24+
let js_post_build = "js-post-build"
25+
let cmd = "cmd"

jscomp/bsb/bsb_default.ml

+6
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,9 @@ let set_ppx_flags ~cwd s =
8989
else resolve_bsb_magic_path ~cwd ~desc:"ppx" p
9090
) in
9191
ppx_flags := s
92+
93+
94+
let js_post_build_cmd = ref None
95+
let get_js_post_build_cmd () = !js_post_build_cmd
96+
let set_js_post_build_cmd ~cwd s =
97+
js_post_build_cmd := Some (resolve_bsb_magic_path ~cwd ~desc:"js-post-build:cmd" s )

jscomp/bsb/bsb_default.mli

+4
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ val get_refmt : unit -> string
4949

5050
val get_bs_dependencies : unit -> string list
5151
val set_bs_dependencies : Bsb_json.t array -> unit
52+
53+
54+
val get_js_post_build_cmd : unit -> string option
55+
val set_js_post_build_cmd : cwd:string -> string -> unit

jscomp/bsb/bsb_gen.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ let (//) = Ext_filename.combine
2727
let output_ninja
2828
~builddir
2929
~cwd
30+
~js_post_build_cmd
3031
bsc
3132
bsdep
3233
package_name
@@ -37,6 +38,7 @@ let output_ninja
3738
ppx_flags
3839
bs_dependencies
3940
refmt
41+
4042
=
4143
let ppx_flags = Bsb_build_util.flag_concat "-ppx" ppx_flags in
4244
let bs_groups, source_dirs,static_resources =
@@ -89,7 +91,7 @@ let output_ninja
8991
]
9092
in
9193
let all_deps, all_cmis =
92-
Bsb_ninja.handle_file_groups oc bs_file_groups ([],[]) in
94+
Bsb_ninja.handle_file_groups oc ~js_post_build_cmd bs_file_groups ([],[]) in
9395
let all_deps =
9496
(* we need copy package.json into [_build] since it does affect build output *)
9597
(* Literals.package_json ::

jscomp/bsb/bsb_gen.mli

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
val output_ninja :
2727
builddir:string ->
2828
cwd:string ->
29+
js_post_build_cmd:string option ->
2930
string ->
3031
string ->
3132
string option ->

jscomp/bsb/bsb_main.ml

+7-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ let write_ninja_file cwd =
5555
|?
5656
(Bsb_build_schemas.ocaml_config, `Obj begin fun m ->
5757
m
58+
|? (Bsb_build_schemas.js_post_build, `Obj begin fun m ->
59+
m |? (Bsb_build_schemas.cmd , `Str (Bsb_default.set_js_post_build_cmd ~cwd)
60+
)
61+
|> ignore
62+
end)
5863
|? (Bsb_build_schemas.ocamllex, `Str Bsb_default.set_ocamllex)
5964
|? (Bsb_build_schemas.bs_dependencies, `Arr Bsb_default.set_bs_dependencies)
6065
(* More design *)
@@ -86,7 +91,7 @@ let write_ninja_file cwd =
8691
Unix.unlink Literals.bsconfig_json;
8792
Unix.rename config_file_bak Literals.bsconfig_json
8893
end;
89-
Bsb_gen.output_ninja ~builddir ~cwd
94+
Bsb_gen.output_ninja ~builddir ~cwd ~js_post_build_cmd: Bsb_default.(get_js_post_build_cmd ())
9095
bsc
9196
bsdep
9297
(Bsb_default.get_package_name ())
@@ -97,6 +102,7 @@ let write_ninja_file cwd =
97102
Bsb_default.(get_ppx_flags ())
98103
Bsb_default.(get_bs_dependencies ())
99104
Bsb_default.(get_refmt ())
105+
100106
;
101107
!globbed_dirs
102108

jscomp/bsb/bsb_ninja.ml

+12-6
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ module Rules = struct
124124
let build_cmj_js =
125125
define
126126
~command:"${bsc} ${bs_package_flags} -bs-no-builtin-ppx-ml -bs-no-implicit-include \
127-
${bs_package_includes} ${bsc_includes} ${bsc_flags} -o ${in} -c -impl ${in}"
127+
${bs_package_includes} ${bsc_includes} ${bsc_flags} -o ${in} -c -impl ${in} ${postbuild}"
128128

129129
~depfile:"${in}.d"
130130
"build_cmj_only"
131131

132132
let build_cmi_cmj_js =
133133
define
134134
~command:"${bsc} ${bs_package_flags} -bs-assume-no-mli -bs-no-builtin-ppx-ml -bs-no-implicit-include \
135-
${bs_package_includes} ${bsc_includes} ${bsc_flags} -o ${in} -c -impl ${in}"
135+
${bs_package_includes} ${bsc_includes} ${bsc_flags} -o ${in} -c -impl ${in} ${postbuild}"
136136
~depfile:"${in}.d"
137137
"build_cmj_cmi"
138138
let build_cmi =
@@ -247,7 +247,7 @@ let (++) (us : info) (vs : info) =
247247

248248

249249

250-
let handle_file_group oc acc (group: Bsb_build_ui.file_group) =
250+
let handle_file_group oc ~js_post_build_cmd acc (group: Bsb_build_ui.file_group) =
251251
let handle_module_info oc module_name
252252
( module_info : Binary_cache.module_info)
253253
bs_dependencies
@@ -319,7 +319,13 @@ let handle_file_group oc acc (group: Bsb_build_ui.file_group) =
319319
[ output_cmi] , []
320320
else Rules.build_cmi_cmj_js, [], [output_cmi]
321321
in
322-
322+
let shadows =
323+
match js_post_build_cmd with
324+
| None -> shadows
325+
| Some cmd ->
326+
("postbuild",
327+
`Overwrite ("&& " ^ cmd ^ " " ^ output_js)) :: shadows
328+
in
323329
output_build oc
324330
~output:output_cmj
325331
~shadows
@@ -399,5 +405,5 @@ let handle_file_group oc acc (group: Bsb_build_ui.file_group) =
399405
handle_module_info oc k v group.bs_dependencies acc
400406
) group.sources acc
401407

402-
let handle_file_groups oc (file_groups : Bsb_build_ui.file_group list) st =
403-
List.fold_left (handle_file_group oc) st file_groups
408+
let handle_file_groups oc ~js_post_build_cmd (file_groups : Bsb_build_ui.file_group list) st =
409+
List.fold_left (handle_file_group oc ~js_post_build_cmd ) st file_groups

jscomp/bsb/bsb_ninja.mli

+1
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,6 @@ val output_kvs : (string * string) list -> out_channel -> unit
7070

7171
type info = string list * string list
7272
val handle_file_groups : out_channel ->
73+
js_post_build_cmd:string option ->
7374
Bsb_build_ui.file_group list ->
7475
info -> info

0 commit comments

Comments
 (0)