Skip to content

Commit c902ab3

Browse files
authored
Merge pull request #1161 from bloomberg/bsb_support_es6
es6 build system
2 parents a1ab8c9 + 950af90 commit c902ab3

29 files changed

+227
-91
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"program": "${file}",
99
"stopOnEntry": false,
1010
"args": [],
11-
"cwd": "${workspaceRoot}/_build",
11+
"cwd": "${workspaceRoot}",
1212
"preLaunchTask": null,
1313
"runtimeExecutable": null,
1414
"runtimeArgs": [

bsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@
320320
"infer_type_test.ml",
321321
"ignore_test.ml",
322322
"http_types.ml",
323-
"hello_reason_dep.re",
323+
/*"hello_reason_dep.re",
324324
"hello_reason.rei",
325-
"hello_reason.re",
325+
"hello_reason.re",*/
326326
"hello.foo.ml",
327327
"hashtbl_test.ml",
328328
"hash_test.ml",

docs/docson/build-schema.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"enum": [
66
"commonjs",
77
"amdjs",
8-
"goog"
8+
"goog",
9+
"es6"
910
]
1011
},
1112
"package-specs": {
@@ -21,7 +22,7 @@
2122
"enum": [
2223
"all"
2324
],
24-
"description": "All supported format with default output"
25+
"description": "(Not supported yet)All supported format with default output"
2526
}
2627
]
2728
},

jscomp/all.depend

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,8 @@ ounit_tests/ounit_json_tests.cmx : ext/string_map.cmx ounit/oUnit.cmx \
607607
ext/ext_json.cmx
608608
ounit_tests/ounit_map_tests.cmx : ounit/oUnit.cmx ext/int_map.cmx
609609
ounit_tests/ounit_ordered_hash_set_tests.cmx : \
610-
ext/ordered_hash_set_string.cmx ounit/oUnit.cmx ext/ext_util.cmx
610+
ext/ordered_hash_set_string.cmx ounit/oUnit.cmx ext/ext_util.cmx \
611+
ext/ext_string.cmx
611612
ounit_tests/ounit_vec_test.cmx : ext/set_int.cmx ounit/oUnit.cmx \
612613
ext/int_vec.cmx ext/ext_json.cmx
613614
ounit_tests/ounit_data_random.cmx :
@@ -650,12 +651,12 @@ bsb/bsb_build_ui.cmx : ext/string_vec.cmx ext/string_set.cmx \
650651
bsb/bsb_build_util.cmx : ext/ext_sys.cmx ext/ext_string.cmx ext/ext_list.cmx \
651652
ext/ext_json.cmx ext/ext_filename.cmx ext/ext_array.cmx \
652653
bsb/bsb_config.cmx bsb/bsb_build_util.cmi
653-
bsb/bsb_config.cmx : common/js_config.cmx ext/ext_filename.cmx \
654-
bsb/bsb_config.cmi
654+
bsb/bsb_config.cmx : ext/literals.cmx common/js_config.cmx \
655+
ext/ext_string.cmx ext/ext_filename.cmx bsb/bsb_config.cmi
655656
bsb/bsb_default.cmx : ext/string_set.cmx ext/literals.cmx ext/ext_sys.cmx \
656657
ext/ext_string.cmx ext/ext_json.cmx ext/ext_filename.cmx \
657-
bsb/bsb_build_util.cmx bsb/bsb_build_schemas.cmx common/bs_pkg.cmx \
658-
bsb/bsb_default.cmi
658+
bsb/bsb_config.cmx bsb/bsb_build_util.cmx bsb/bsb_build_schemas.cmx \
659+
common/bs_pkg.cmx bsb/bsb_default.cmi
659660
bsb/bsb_dep_infos.cmx : bsb/bsb_dep_infos.cmi
660661
bsb/bsb_dir.cmx : bsb/bsb_dir.cmi
661662
bsb/bsb_file.cmx : bsb/bsb_file.cmi
@@ -698,4 +699,5 @@ jscmj_main.cmx : common/js_config.cmx core/js_cmj_format.cmx \
698699
ext/ext_string.cmx ext/ext_pp.cmx ext/ext_pervasives.cmx \
699700
ext/ext_array.cmx jscmj_main.cmi
700701
jsgen_main.cmx : ext/ext_string.cmx ext/ext_pervasives.cmx ext/ext_array.cmx
702+
rollup_test.cmx :
701703
jscmj_main.cmi :

jscomp/bin/all_ounit_tests.ml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,8 +1740,10 @@ val concat4 : string -> string -> string -> string -> string
17401740

17411741
val inter2 : string -> string -> string
17421742
val inter3 : string -> string -> string -> string
1743-
1743+
val inter4 : string -> string -> string -> string -> string
17441744
val concat_array : string -> string array -> string
1745+
1746+
val single_colon : string
17451747
end = struct
17461748
#1 "ext_string.ml"
17471749
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -2125,7 +2127,7 @@ let empty = ""
21252127
external compare : string -> string -> int = "caml_string_length_based_compare" "noalloc";;
21262128

21272129
let single_space = " "
2128-
2130+
let single_colon = ":"
21292131
let concat3 a b c = a ^ b ^ c
21302132
let concat4 a b c d = a ^ b ^ c ^ d
21312133

@@ -2134,6 +2136,8 @@ let inter2 a b = a ^ single_space ^ b
21342136
let inter3 a b c =
21352137
a ^ single_space ^ b ^ single_space ^ c
21362138

2139+
let inter4 a b c d =
2140+
a ^ single_space ^ b ^ single_space ^ c ^ single_space ^ d
21372141
(** TODO: improve perf *)
21382142
let concat_array sep (s : string array) =
21392143
String.concat sep (Array.to_list s)
@@ -3453,7 +3457,7 @@ val suffix_cmti : string
34533457
val commonjs : string
34543458
val amdjs : string
34553459
val goog : string
3456-
3460+
val es6 : string
34573461
val unused_attribute : string
34583462
end = struct
34593463
#1 "literals.ml"
@@ -3553,6 +3557,7 @@ let suffix_js = ".js"
35533557
let commonjs = "commonjs"
35543558
let amdjs = "amdjs"
35553559
let goog = "goog"
3560+
let es6 = "es6"
35563561

35573562
let unused_attribute = "Unused attribute "
35583563
end
@@ -9272,12 +9277,12 @@ let suites =
92729277
let count = 1000 in
92739278
let v = Ordered_hash_set_string.of_array (Array.init count (fun i -> string_of_int i) ) in
92749279
for i = 0 to count - 1 do
9275-
Ordered_hash_set_string.replace v (string_of_int i) (string_of_int i ^ ":")
9280+
Ordered_hash_set_string.replace v (string_of_int i) (string_of_int i ^ Ext_string.single_colon)
92769281
done ;
92779282
OUnit.assert_equal (Ordered_hash_set_string.length v) count;
92789283
OUnit.assert_equal
92799284
(Ordered_hash_set_string.to_sorted_array v )
9280-
(Array.init count (fun i -> string_of_int i ^ ":"))
9285+
(Array.init count (fun i -> string_of_int i ^ Ext_string.single_colon))
92819286

92829287
end
92839288
]

jscomp/bin/bsb.ml

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ val suffix_cmti : string
9696
val commonjs : string
9797
val amdjs : string
9898
val goog : string
99-
99+
val es6 : string
100100
val unused_attribute : string
101101
end = struct
102102
#1 "literals.ml"
@@ -196,6 +196,7 @@ let suffix_js = ".js"
196196
let commonjs = "commonjs"
197197
let amdjs = "amdjs"
198198
let goog = "goog"
199+
let es6 = "es6"
199200

200201
let unused_attribute = "Unused attribute "
201202
end
@@ -825,8 +826,10 @@ val concat4 : string -> string -> string -> string -> string
825826

826827
val inter2 : string -> string -> string
827828
val inter3 : string -> string -> string -> string
828-
829+
val inter4 : string -> string -> string -> string -> string
829830
val concat_array : string -> string array -> string
831+
832+
val single_colon : string
830833
end = struct
831834
#1 "ext_string.ml"
832835
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -1210,7 +1213,7 @@ let empty = ""
12101213
external compare : string -> string -> int = "caml_string_length_based_compare" "noalloc";;
12111214

12121215
let single_space = " "
1213-
1216+
let single_colon = ":"
12141217
let concat3 a b c = a ^ b ^ c
12151218
let concat4 a b c d = a ^ b ^ c ^ d
12161219

@@ -1219,6 +1222,8 @@ let inter2 a b = a ^ single_space ^ b
12191222
let inter3 a b c =
12201223
a ^ single_space ^ b ^ single_space ^ c
12211224

1225+
let inter4 a b c d =
1226+
a ^ single_space ^ b ^ single_space ^ c ^ single_space ^ d
12221227
(** TODO: improve perf *)
12231228
let concat_array sep (s : string array) =
12241229
String.concat sep (Array.to_list s)
@@ -2858,6 +2863,12 @@ val no_dev: bool ref
28582863

28592864
(** default not install, only when -make-world, its dependencies will be installed *)
28602865
val install : bool ref
2866+
2867+
val supported_format : string -> bool
2868+
2869+
val package_flag : format:string -> string -> string
2870+
2871+
val package_output : format:string -> string -> string
28612872
end = struct
28622873
#1 "bsb_config.ml"
28632874
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -2890,23 +2901,66 @@ let lib_amd = "lib"//"amdjs"
28902901
let lib_goog = "lib" // "goog"
28912902
let lib_ocaml = Js_config.lib_ocaml_dir
28922903
let lib_bs = "lib" // "bs"
2904+
let lib_es6 = "lib" // "es6"
28932905
let rev_lib_bs = ".."// ".."
2906+
2907+
28942908
let rev_lib_bs_prefix p = rev_lib_bs // p
28952909
let common_js_prefix p = lib_js // p
28962910
let amd_js_prefix p = lib_amd // p
28972911
let goog_prefix p = lib_goog // p
2912+
let es6_prefix p = lib_es6 // p
2913+
28982914
let ocaml_bin_install_prefix p = lib_ocaml // p
28992915

29002916
let lazy_src_root_dir = "$src_root_dir"
29012917
let proj_rel path = lazy_src_root_dir // path
2902-
2918+
29032919
(** it may not be a bad idea to hard code the binary path
29042920
of bsb in configuration time
29052921
*)
29062922

29072923
let no_dev = ref false
29082924

29092925
let install = ref false
2926+
2927+
let supported_format x =
2928+
x = Literals.amdjs ||
2929+
x = Literals.commonjs ||
2930+
x = Literals.goog ||
2931+
x = Literals.es6
2932+
2933+
let bs_package_output = "-bs-package-output"
2934+
2935+
(** Assume input is valid
2936+
{[ -bs-package-output commonjs:lib/js/jscomp/test ]}
2937+
*)
2938+
let package_flag ~format:fmt dir =
2939+
Ext_string.inter2
2940+
bs_package_output
2941+
(Ext_string.concat3
2942+
fmt
2943+
Ext_string.single_colon
2944+
(if fmt = Literals.amdjs then
2945+
amd_js_prefix dir
2946+
else if fmt = Literals.commonjs then
2947+
common_js_prefix dir
2948+
else if fmt = Literals.es6 then
2949+
es6_prefix dir
2950+
else goog_prefix dir))
2951+
(** js output for each package *)
2952+
let package_output ~format:s output=
2953+
let prefix =
2954+
if s = Literals.commonjs then
2955+
common_js_prefix
2956+
else if s = Literals.amdjs then
2957+
amd_js_prefix
2958+
else if s = Literals.es6 then
2959+
es6_prefix
2960+
else goog_prefix
2961+
in
2962+
(proj_rel @@ prefix output )
2963+
(* output_file_sans_extension ^ Literals.suffix_js *)
29102964
end
29112965
module Ext_array : sig
29122966
#1 "ext_array.mli"
@@ -6983,14 +7037,16 @@ let package_specs_overriden = ref false
69837037

69847038
let get_package_specs () = !package_specs
69857039

7040+
7041+
69867042
let set_package_specs_from_array arr =
69877043
if not !package_specs_overriden then
69887044
let new_package_specs =
69897045
arr
69907046
|> get_list_string
69917047
|> List.fold_left (fun acc x ->
69927048
let v =
6993-
if x = Literals.amdjs || x = Literals.commonjs || x = Literals.goog then String_set.add x acc
7049+
if Bsb_config.supported_format x then String_set.add x acc
69947050
else
69957051
failwith ("Unkonwn package spec" ^ x) in
69967052
v
@@ -7006,7 +7062,7 @@ let internal_override_package_specs str =
70067062
package_specs :=
70077063
List.fold_left (fun acc x ->
70087064
let v =
7009-
if x = Literals.amdjs || x = Literals.commonjs || x = Literals.goog then String_set.add x acc
7065+
if Bsb_config.supported_format x then String_set.add x acc
70107066
else
70117067
failwith ("Unkonwn package spec" ^ x) in
70127068
v
@@ -8021,15 +8077,8 @@ let handle_file_group oc ~package_specs ~js_post_build_cmd acc (group: Bsb_buil
80218077
let output_cmj = output_file_sans_extension ^ Literals.suffix_cmj in
80228078
let output_js =
80238079
String_set.fold (fun s acc ->
8024-
let prefix =
8025-
if s = Literals.commonjs then
8026-
Bsb_config.common_js_prefix
8027-
else if s = Literals.amdjs then
8028-
Bsb_config.amd_js_prefix
8029-
else Bsb_config.goog_prefix
8030-
in
8031-
(Bsb_config.proj_rel @@ prefix
8032-
output_file_sans_extension ^ Literals.suffix_js) :: acc
8080+
Bsb_config.package_output ~format:s (output_file_sans_extension ^ Literals.suffix_js)
8081+
:: acc
80338082
) package_specs []
80348083
in
80358084
(* let output_mldeps = output_file_sans_extension ^ Literals.suffix_mldeps in *)
@@ -8039,14 +8088,9 @@ let handle_file_group oc ~package_specs ~js_post_build_cmd acc (group: Bsb_buil
80398088
( "bs_package_flags",
80408089
`Append
80418090
(String_set.fold (fun s acc ->
8042-
acc ^ " -bs-package-output " ^ s ^ ":" ^
8043-
if s = Literals.amdjs then
8044-
(Bsb_config.amd_js_prefix @@ Filename.dirname output_cmi)
8045-
else if s = Literals.commonjs then
8046-
(Bsb_config.common_js_prefix @@ Filename.dirname output_cmi)
8047-
else
8048-
(Bsb_config.goog_prefix @@ Filename.dirname output_cmi)
8049-
) package_specs "")
8091+
Ext_string.inter2 acc (Bsb_config.package_flag ~format:s (Filename.dirname output_cmi))
8092+
8093+
) package_specs Ext_string.empty)
80508094
) ::
80518095
(if group.dir_index = 0 then [] else
80528096
[("bsc_extra_includes",
@@ -8816,6 +8860,7 @@ let lib_amdjs = "lib" // "amdjs"
88168860
let lib_goog = "lib" // "goog"
88178861
let lib_js = "lib" // "js"
88188862
let lib_ocaml = "lib" // "ocaml" (* installed binary artifacts *)
8863+
let lib_es6 = "lib" // "es6"
88198864
let clean_bs_garbage cwd =
88208865
print_string "Doing cleaning in ";
88218866
print_endline cwd;
@@ -8828,7 +8873,8 @@ let clean_bs_garbage cwd =
88288873
aux lib_amdjs ;
88298874
aux lib_goog;
88308875
aux lib_js ;
8831-
aux lib_ocaml
8876+
aux lib_ocaml;
8877+
aux lib_es6 ;
88328878
with
88338879
e ->
88348880
prerr_endline ("Failed to clean due to " ^ Printexc.to_string e)

jscomp/bin/bsb_helper.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,10 @@ val concat4 : string -> string -> string -> string -> string
470470

471471
val inter2 : string -> string -> string
472472
val inter3 : string -> string -> string -> string
473-
473+
val inter4 : string -> string -> string -> string -> string
474474
val concat_array : string -> string array -> string
475+
476+
val single_colon : string
475477
end = struct
476478
#1 "ext_string.ml"
477479
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -855,7 +857,7 @@ let empty = ""
855857
external compare : string -> string -> int = "caml_string_length_based_compare" "noalloc";;
856858

857859
let single_space = " "
858-
860+
let single_colon = ":"
859861
let concat3 a b c = a ^ b ^ c
860862
let concat4 a b c d = a ^ b ^ c ^ d
861863

@@ -864,6 +866,8 @@ let inter2 a b = a ^ single_space ^ b
864866
let inter3 a b c =
865867
a ^ single_space ^ b ^ single_space ^ c
866868

869+
let inter4 a b c d =
870+
a ^ single_space ^ b ^ single_space ^ c ^ single_space ^ d
867871
(** TODO: improve perf *)
868872
let concat_array sep (s : string array) =
869873
String.concat sep (Array.to_list s)
@@ -966,7 +970,7 @@ val suffix_cmti : string
966970
val commonjs : string
967971
val amdjs : string
968972
val goog : string
969-
973+
val es6 : string
970974
val unused_attribute : string
971975
end = struct
972976
#1 "literals.ml"
@@ -1066,6 +1070,7 @@ let suffix_js = ".js"
10661070
let commonjs = "commonjs"
10671071
let amdjs = "amdjs"
10681072
let goog = "goog"
1073+
let es6 = "es6"
10691074

10701075
let unused_attribute = "Unused attribute "
10711076
end

0 commit comments

Comments
 (0)