Skip to content

Commit d4d779b

Browse files
authored
Merge pull request #1153 from chenglou/fix-hack
2 parents a40da60 + 7717163 commit d4d779b

File tree

8 files changed

+315
-285
lines changed

8 files changed

+315
-285
lines changed

jscomp/bin/bsb.ml

Lines changed: 158 additions & 142 deletions
Large diffs are not rendered by default.

jscomp/bsb/bsb_build_schemas.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ let ppx_flags = "ppx-flags"
77

88
let bsc = "bsc"
99
let refmt = "refmt"
10+
let refmt_flags = "refmt-flags"
1011
let bs_external_includes = "bs-external-includes"
1112
let bs_lib_dir = "bs-lib-dir"
1213
let bs_dependencies = "bs-dependencies"
@@ -23,7 +24,7 @@ let resources = "resources"
2324
let public = "public"
2425
let js_post_build = "js-post-build"
2526
let cmd = "cmd"
26-
let ninja = "ninja"
27+
let ninja = "ninja"
2728
let package_specs = "package-specs"
2829

2930
let generate_merlin = "generate-merlin"
@@ -35,4 +36,4 @@ let export_all = "all"
3536
let export_none = "none"
3637

3738
let bsb_dir_group = "bsb_dir_group"
38-
let bsc_lib_includes = "bsc_lib_includes"
39+
let bsc_lib_includes = "bsc_lib_includes"

jscomp/bsb/bsb_default.ml

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,25 @@ let (//) = Ext_filename.combine
2727

2828

2929
(* Magic path resolution:
30-
foo => foo
30+
foo => foo
3131
foo/ => /absolute/path/to/projectRoot/node_modules/foo
3232
foo/bar => /absolute/path/to/projectRoot/node_modules/foo.bar
3333
/foo/bar => /foo/bar
34-
./foo/bar => /absolute/path/to/projectRoot/./foo/bar
34+
./foo/bar => /absolute/path/to/projectRoot/./foo/bar
3535
Input is node path, output is OS dependent path
3636
*)
3737
let resolve_bsb_magic_file ~cwd ~desc p =
38-
let p_len = String.length p in
39-
let no_slash = Ext_string.no_slash p in
40-
if no_slash then
41-
p
38+
let p_len = String.length p in
39+
let no_slash = Ext_string.no_slash p in
40+
if no_slash then
41+
p
4242
else if Filename.is_relative p &&
4343
p_len > 0 &&
4444
String.unsafe_get p 0 <> '.' then
45-
let p = if Ext_sys.is_windows_or_cygwin then Ext_string.replace_slash_backward p else p in
45+
let p = if Ext_sys.is_windows_or_cygwin then Ext_string.replace_slash_backward p else p in
4646
match Bs_pkg.resolve_npm_package_file ~cwd p with
4747
| None -> failwith (p ^ " not found when resolving " ^ desc)
48-
| Some v -> v
48+
| Some v -> v
4949
else
5050
Bsb_build_util.convert_and_resolve_path p
5151

@@ -55,32 +55,32 @@ let (|?) m (key, cb) =
5555

5656

5757

58-
(**
59-
TODO: check duplicate package name
58+
(**
59+
TODO: check duplicate package name
6060
?use path as identity?
6161
*)
62-
let rec walk_all_deps top dir cb =
63-
let bsconfig_json = (dir // Literals.bsconfig_json) in
64-
match Ext_json.parse_json_from_file bsconfig_json with
62+
let rec walk_all_deps top dir cb =
63+
let bsconfig_json = (dir // Literals.bsconfig_json) in
64+
match Ext_json.parse_json_from_file bsconfig_json with
6565
| `Obj map ->
6666
map
67-
|?
68-
(Bsb_build_schemas.bs_dependencies,
69-
`Arr (fun (new_packages : Ext_json.t array) ->
67+
|?
68+
(Bsb_build_schemas.bs_dependencies,
69+
`Arr (fun (new_packages : Ext_json.t array) ->
7070
new_packages
71-
|> Array.iter (fun (js : Ext_json.t) ->
72-
begin match js with
73-
| `Str {Ext_json.str = new_package} ->
74-
begin match Bs_pkg.resolve_bs_package ~cwd:dir new_package with
71+
|> Array.iter (fun (js : Ext_json.t) ->
72+
begin match js with
73+
| `Str {Ext_json.str = new_package} ->
74+
begin match Bs_pkg.resolve_bs_package ~cwd:dir new_package with
7575
| None -> failwith (new_package ^ " not found as dependency of " ^ bsconfig_json )
76-
| Some package_dir ->
77-
walk_all_deps false package_dir cb ;
78-
end;
76+
| Some package_dir ->
77+
walk_all_deps false package_dir cb ;
78+
end;
7979
| _ -> () (* TODO: add a log framework, warning here *)
80-
end
80+
end
8181
)))
8282
|> ignore ;
83-
cb top dir
83+
cb top dir
8484
| _ -> ()
8585
| exception _ -> failwith ( "failed to parse" ^ bsconfig_json ^ " properly")
8686

@@ -111,17 +111,22 @@ let get_bs_external_includes () = !bs_external_includes
111111

112112

113113
let ocamllex = ref "ocamllex.opt"
114-
let set_ocamllex ~cwd s =
114+
let set_ocamllex ~cwd s =
115115
ocamllex := resolve_bsb_magic_file ~cwd ~desc:"ocamllex" s
116116
let get_ocamllex () = !ocamllex
117117

118118

119119

120120
let refmt = ref "refmt"
121121
let get_refmt () = !refmt
122-
let set_refmt ~cwd p =
122+
let set_refmt ~cwd p =
123123
refmt := resolve_bsb_magic_file ~cwd ~desc:"refmt" p
124124

125+
let refmt_flags = ref []
126+
let get_refmt_flags () = !refmt_flags
127+
let set_refmt_flags s =
128+
refmt_flags := get_list_string s
129+
125130

126131
let ppx_flags = ref []
127132
let get_ppx_flags () = !ppx_flags
@@ -136,7 +141,7 @@ let set_ppx_flags ~cwd s =
136141
ppx_flags := s
137142

138143

139-
let js_post_build_cmd = ref None
144+
let js_post_build_cmd = ref None
140145
let get_js_post_build_cmd () = !js_post_build_cmd
141146
let set_js_post_build_cmd ~cwd s =
142147
js_post_build_cmd := Some (resolve_bsb_magic_file ~cwd ~desc:"js-post-build:cmd" s )
@@ -149,49 +154,49 @@ let get_ninja () = !ninja
149154
Second we need store it so that we can call ninja correctly
150155
*)
151156
let set_ninja ~cwd p =
152-
ninja := resolve_bsb_magic_file ~cwd ~desc:"ninja" p
157+
ninja := resolve_bsb_magic_file ~cwd ~desc:"ninja" p
153158

154159

155160
type package_specs = String_set.t
156161

157162
let package_specs = ref (String_set.singleton Literals.commonjs)
158-
let package_specs_overriden = ref false
163+
let package_specs_overriden = ref false
159164

160165
let get_package_specs () = !package_specs
161166

162-
let set_package_specs_from_array arr =
163-
if not !package_specs_overriden then
164-
let new_package_specs =
165-
arr
167+
let set_package_specs_from_array arr =
168+
if not !package_specs_overriden then
169+
let new_package_specs =
170+
arr
166171
|> get_list_string
167172
|> List.fold_left (fun acc x ->
168-
let v =
173+
let v =
169174
if x = Literals.amdjs || x = Literals.commonjs || x = Literals.goog then String_set.add x acc
170-
else
171-
failwith ("Unkonwn package spec" ^ x) in
175+
else
176+
failwith ("Unkonwn package spec" ^ x) in
172177
v
173-
) String_set.empty in
178+
) String_set.empty in
174179
package_specs := new_package_specs
175180

176181

177182

178183

179-
let internal_override_package_specs str =
180-
package_specs_overriden := true ;
181-
let lst = Ext_string.split ~keep_empty:false str ',' in
182-
package_specs :=
183-
List.fold_left (fun acc x ->
184-
let v =
184+
let internal_override_package_specs str =
185+
package_specs_overriden := true ;
186+
let lst = Ext_string.split ~keep_empty:false str ',' in
187+
package_specs :=
188+
List.fold_left (fun acc x ->
189+
let v =
185190
if x = Literals.amdjs || x = Literals.commonjs || x = Literals.goog then String_set.add x acc
186-
else
187-
failwith ("Unkonwn package spec" ^ x) in
191+
else
192+
failwith ("Unkonwn package spec" ^ x) in
188193
v
189-
) String_set.empty lst
194+
) String_set.empty lst
190195

191196

192197
let generate_merlin = ref true
193198

194-
let get_generate_merlin () = !generate_merlin
199+
let get_generate_merlin () = !generate_merlin
195200

196-
let set_generate_merlin b =
201+
let set_generate_merlin b =
197202
generate_merlin := b

jscomp/bsb/bsb_default.mli

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ val get_package_name : unit -> string option
4747
val set_refmt : cwd:string -> string -> unit
4848
val get_refmt : unit -> string
4949

50+
val set_refmt_flags : Ext_json.t array -> unit
51+
val get_refmt_flags : unit -> string list
5052

5153
val get_bs_dependencies : unit -> string list
5254
val set_bs_dependencies : Ext_json.t array -> unit
@@ -55,16 +57,16 @@ val set_bs_dependencies : Ext_json.t array -> unit
5557
val get_js_post_build_cmd : unit -> string option
5658
val set_js_post_build_cmd : cwd:string -> string -> unit
5759

58-
val get_ninja : unit -> string
60+
val get_ninja : unit -> string
5961
val set_ninja : cwd:string -> string -> unit
6062

6163
type package_specs = String_set.t
6264
val get_package_specs : unit -> package_specs
63-
val set_package_specs_from_array : Ext_json.t array -> unit
64-
val internal_override_package_specs : string -> unit
65+
val set_package_specs_from_array : Ext_json.t array -> unit
66+
val internal_override_package_specs : string -> unit
6567

6668

67-
val get_generate_merlin : unit -> bool
68-
val set_generate_merlin : bool -> unit
69+
val get_generate_merlin : unit -> bool
70+
val set_generate_merlin : bool -> unit
6971

70-
val walk_all_deps : bool -> string -> (bool -> string -> unit) -> unit
72+
val walk_all_deps : bool -> string -> (bool -> string -> unit) -> unit

jscomp/bsb/bsb_gen.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ let merge_module_info_map acc sources =
3434
| None , None ->
3535
assert false
3636
| Some a, Some b ->
37-
failwith ("conflict files found: " ^ modname ^ "in ("
37+
failwith ("conflict files found: " ^ modname ^ "in ("
3838
^ Binary_cache.dir_of_module_info a ^ Ext_string.single_space ^ Binary_cache.dir_of_module_info b ^ " )")
3939
| Some v, None -> Some v
4040
| None, Some v -> Some v
@@ -56,10 +56,12 @@ let output_ninja
5656
ppx_flags
5757
bs_dependencies
5858
refmt
59+
refmt_flags
5960

6061
=
6162
let ppx_flags = Bsb_build_util.flag_concat "-ppx" ppx_flags in
6263
let bsc_flags = String.concat Ext_string.single_space bsc_flags in
64+
let refmt_flags = String.concat Ext_string.single_space refmt_flags in
6365
let oc = open_out_bin (builddir // Literals.build_ninja) in
6466
begin
6567
let () =
@@ -80,7 +82,8 @@ let output_ninja
8082
"bsc_flags", bsc_flags ;
8183
"ppx_flags", ppx_flags;
8284
"bs_package_includes", (Bsb_build_util.flag_concat "-bs-package-include" bs_dependencies);
83-
"refmt", "\"" ^ refmt ^ "\"";
85+
"refmt", refmt;
86+
"refmt_flags", refmt_flags;
8487
Bsb_build_schemas.bsb_dir_group, "0" (*TODO: avoid name conflict in the future *)
8588
|] oc ;
8689
in

jscomp/bsb/bsb_gen.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
val output_ninja :
2727
builddir:string ->
2828
cwd:string ->
29-
js_post_build_cmd:string option ->
29+
js_post_build_cmd:string option ->
3030
package_specs:Bsb_default.package_specs ->
3131
string ->
3232
string ->
@@ -38,4 +38,5 @@ val output_ninja :
3838
string list ->
3939
string list ->
4040
string ->
41+
string list ->
4142
unit

0 commit comments

Comments
 (0)