Skip to content

Commit a5228be

Browse files
committed
conslidate package path handling
1 parent 166ee94 commit a5228be

19 files changed

+255
-217
lines changed

jscomp/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ SYNTAX_CMXS=$(addprefix syntax/, $(addsuffix .cmx, $(SYNTAX_SRCS)))
258258
DEPENDS_SRCS= bs_exception ast_extract binary_ast
259259
DEPENDS_CMXS=$(addprefix depends/, $(addsuffix .cmx, $(DEPENDS_SRCS)))
260260
CORE_SRCS= js_runtime_modules \
261+
config_util \
261262
js_packages_info\
262263
js_packages_state\
263264
type_int_to_string type_util ocaml_stdlib_slots bs_conditional_initial ocaml_options ocaml_parse\
@@ -272,7 +273,6 @@ CORE_SRCS= js_runtime_modules \
272273
lam_compile_util \
273274
lam_id_kind \
274275
lam_stats \
275-
config_util \
276276
lam_compile_defs \
277277
js_map js_fold js_fold_basic js_pass_scope\
278278
js_op_util js_analyzer js_shake js_exp_make js_long js_of_lam_exception js_of_lam_module js_of_lam_array js_of_lam_block js_of_lam_string\

jscomp/all.depend

+10-13
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ depends/ast_extract.cmx : ext/string_map.cmx ext/string_hashtbl.cmx \
263263
depends/bs_exception.cmx depends/ast_extract.cmi
264264
depends/binary_ast.cmx : common/ml_binary.cmx depends/ast_extract.cmx \
265265
depends/binary_ast.cmi
266-
core/js_packages_info.cmi :
266+
core/config_util.cmi :
267+
core/js_packages_info.cmi : core/lam_module_ident.cmi
267268
core/js_packages_state.cmi : core/js_packages_info.cmi
268269
core/type_util.cmi :
269270
core/bs_conditional_initial.cmi :
@@ -291,7 +292,6 @@ core/lam_compile_util.cmi : core/js_op.cmx
291292
core/lam_id_kind.cmi : core/lam_arity.cmi core/lam.cmi
292293
core/lam_stats.cmi : core/lam_id_kind.cmi ext/ident_set.cmi \
293294
ext/ident_hashtbl.cmi
294-
core/config_util.cmi : core/js_cmj_format.cmi
295295
core/lam_compile_defs.cmi : core/lam_stats.cmi core/lam.cmi core/j.cmx \
296296
ext/ident_map.cmi
297297
core/js_fold_basic.cmi : core/lam_module_ident.cmi core/j.cmx \
@@ -363,8 +363,10 @@ core/lam_compile_group.cmi : core/j.cmx
363363
core/js_implementation.cmi :
364364
core/ocaml_batch_compile.cmi :
365365
core/js_runtime_modules.cmx :
366-
core/js_packages_info.cmx : ext/ext_string.cmx ext/ext_pervasives.cmx \
367-
ext/ext_filename.cmx core/js_packages_info.cmi
366+
core/config_util.cmx : core/config_util.cmi
367+
core/js_packages_info.cmx : core/lam_module_ident.cmx ext/ext_sys.cmx \
368+
ext/ext_string.cmx ext/ext_pervasives.cmx ext/ext_filename.cmx \
369+
core/config_util.cmx depends/bs_exception.cmx core/js_packages_info.cmi
368370
core/js_packages_state.cmx : core/js_packages_info.cmx \
369371
ext/ext_pervasives.cmx core/js_packages_state.cmi
370372
core/type_int_to_string.cmx :
@@ -397,7 +399,7 @@ core/lam_closure.cmx : core/lam_analysis.cmx core/lam.cmx ext/ident_set.cmx \
397399
ext/ident_map.cmx core/lam_closure.cmi
398400
core/js_cmj_format.cmx : ext/string_map.cmx core/lam_arity.cmx core/lam.cmx \
399401
core/js_packages_info.cmx ext/ext_string.cmx ext/ext_pervasives.cmx \
400-
core/js_cmj_format.cmi
402+
core/config_util.cmx depends/bs_exception.cmx core/js_cmj_format.cmi
401403
core/js_fun_env.cmx : ext/ident_set.cmx ext/ext_list.cmx core/js_fun_env.cmi
402404
core/js_call_info.cmx : core/js_call_info.cmi
403405
core/js_closure.cmx : ext/ident_set.cmx core/js_closure.cmi
@@ -411,8 +413,6 @@ core/lam_compile_util.cmx : core/js_op.cmx core/lam_compile_util.cmi
411413
core/lam_id_kind.cmx : core/lam_arity.cmx core/lam.cmx core/lam_id_kind.cmi
412414
core/lam_stats.cmx : core/lam_id_kind.cmx ext/ident_set.cmx \
413415
ext/ident_hashtbl.cmx core/lam_stats.cmi
414-
core/config_util.cmx : core/js_cmj_format.cmx depends/bs_exception.cmx \
415-
core/config_util.cmi
416416
core/lam_compile_defs.cmx : core/lam_stats.cmx core/lam.cmx core/j.cmx \
417417
ext/ident_map.cmx core/lam_compile_defs.cmi
418418
core/js_map.cmx : core/j.cmx
@@ -492,7 +492,7 @@ core/lam_compile_env.cmx : core/type_util.cmx ext/string_map.cmx \
492492
ext/literals.cmx core/lam_module_ident.cmx core/lam.cmx \
493493
core/js_stmt_make.cmx core/js_packages_info.cmx core/js_exp_make.cmx \
494494
common/js_config.cmx core/js_cmj_format.cmx ext/ext_string.cmx \
495-
core/config_util.cmx core/lam_compile_env.cmi
495+
core/lam_compile_env.cmi
496496
core/lam_stats_util.cmx : core/lam_stats.cmx core/lam_compile_env.cmx \
497497
core/lam_arity.cmx core/lam.cmx ext/ident_hashtbl.cmx ext/ext_list.cmx \
498498
core/lam_stats_util.cmi
@@ -511,11 +511,8 @@ core/lam_pass_alpha_conversion.cmx : core/lam_stats_util.cmx \
511511
core/lam_pass_collect.cmx : core/lam_util.cmx core/lam_stats_util.cmx \
512512
core/lam_stats.cmx core/lam_arity.cmx core/lam.cmx ext/ident_set.cmx \
513513
ext/ident_hashtbl.cmx core/lam_pass_collect.cmi
514-
core/js_program_loader.cmx : core/lam_module_ident.cmx \
515-
core/lam_compile_env.cmx core/js_stmt_make.cmx core/js_packages_state.cmx \
516-
core/js_packages_info.cmx core/js_exp_make.cmx ext/ext_sys.cmx \
517-
ext/ext_string.cmx ext/ext_filename.cmx core/config_util.cmx \
518-
depends/bs_exception.cmx core/js_program_loader.cmi
514+
core/js_program_loader.cmx : core/lam_compile_env.cmx \
515+
core/js_packages_info.cmx core/js_program_loader.cmi
519516
core/js_dump.cmx : ext/literals.cmx core/lam_module_ident.cmx \
520517
core/js_stmt_make.cmx core/js_runtime_modules.cmx \
521518
core/js_program_loader.cmx core/js_packages_state.cmx \

jscomp/bsb/bsb_package_specs.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ let get_list_of_output_js
186186
package_specs output_file_sans_extension =
187187
Spec_set.fold (fun format acc ->
188188
package_output format
189-
(Ext_filename.output_js_basename output_file_sans_extension)
189+
(Ext_filename.js_name_of_basename output_file_sans_extension)
190190
:: acc
191191
) package_specs []
192192

jscomp/core/config_util.ml

-35
Original file line numberDiff line numberDiff line change
@@ -48,38 +48,3 @@ let find_opt file = find_in_path_uncap !Config.load_path file
4848

4949

5050

51-
(* strategy:
52-
If not installed, use the distributed [cmj] files,
53-
make sure that the distributed files are platform independent
54-
*)
55-
let find_cmj file : string * Js_cmj_format.t =
56-
match find_opt file with
57-
| Some f
58-
->
59-
f, Js_cmj_format.from_file f
60-
| None ->
61-
(* ONLY read the stored cmj data in browser environment *)
62-
#if BS_COMPILER_IN_BROWSER then
63-
"BROWSER", (
64-
let target = String.uncapitalize (Filename.basename file) in
65-
match String_map.find_exn target Js_cmj_datasets.data_sets with
66-
| v
67-
->
68-
begin match Lazy.force v with
69-
| exception _
70-
->
71-
Ext_log.warn __LOC__
72-
"@[%s corrupted in database, when looking %s while compiling %s please update @]" file target (Js_config.get_current_file ()) ;
73-
Js_cmj_format.no_pure_dummy; (* FIXME *)
74-
| v -> v
75-
(* see {!Js_program_loader.string_of_module_id} *)
76-
end
77-
| exception Not_found
78-
->
79-
Ext_log.warn __LOC__ "@[%s not found @]" file ;
80-
Js_cmj_format.no_pure_dummy )
81-
#else
82-
Bs_exception.error (Cmj_not_found file)
83-
#end
84-
85-

jscomp/core/config_util.mli

-2
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,3 @@
3737
val find_opt : string -> string option
3838
(** [find filename] Input is a file name, output is absolute path *)
3939

40-
(** return path and meta data *)
41-
val find_cmj : string -> string * Js_cmj_format.t

jscomp/core/js_cmj_format.ml

+38
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,41 @@ let to_file name (v : t) =
9797
output_string oc cmj_magic_number;
9898
output_value oc v;
9999
close_out oc
100+
101+
102+
(* strategy:
103+
If not installed, use the distributed [cmj] files,
104+
make sure that the distributed files are platform independent
105+
*)
106+
let find_cmj file : string * t =
107+
match Config_util.find_opt file with
108+
| Some f
109+
->
110+
f, from_file f
111+
| None ->
112+
(* ONLY read the stored cmj data in browser environment *)
113+
#if BS_COMPILER_IN_BROWSER then
114+
"BROWSER", (
115+
let target = String.uncapitalize (Filename.basename file) in
116+
match String_map.find_exn target Js_cmj_datasets.data_sets with
117+
| v
118+
->
119+
begin match Lazy.force v with
120+
| exception _
121+
->
122+
Ext_log.warn __LOC__
123+
"@[%s corrupted in database, when looking %s while compiling %s please update @]" file target (Js_config.get_current_file ()) ;
124+
Js_cmj_format.no_pure_dummy; (* FIXME *)
125+
| v -> v
126+
(* see {!Js_program_loader.string_of_module_id} *)
127+
end
128+
| exception Not_found
129+
->
130+
Ext_log.warn __LOC__ "@[%s not found @]" file ;
131+
Js_cmj_format.no_pure_dummy )
132+
#else
133+
Bs_exception.error (Cmj_not_found file)
134+
#end
135+
136+
137+

jscomp/core/js_cmj_format.mli

+4
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,7 @@ val from_file : string -> t
8181
val from_string : string -> t
8282

8383
val to_file : string -> t -> unit
84+
85+
86+
(** return path and meta data *)
87+
val find_cmj : string -> string * t

jscomp/core/js_dump.ml

+18-7
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ let es6_export cxt f (idents : Ident.t list) =
16901690
if id_name = default_export then
16911691
(default_export,str)::(s,str)::acc
16921692
else
1693-
(s,str) :: acc ) , max len (String.length s) )
1693+
(s,str) :: acc ) , max len (String.length s) )
16941694
(cxt, [], 0) idents in
16951695
P.newline f ;
16961696
P.string f L.export ;
@@ -1793,7 +1793,11 @@ let goog_program ~output_prefix f goog_package (x : J.deps_program) =
17931793
(fun x ->
17941794
Lam_module_ident.id x,
17951795
Js_program_loader.string_of_module_id
1796-
~hint_output_dir:(Filename.dirname output_prefix) Goog x)
1796+
~hint_output_dir:(Filename.dirname output_prefix)
1797+
Goog
1798+
(Js_packages_state.get_packages_info())
1799+
x)
1800+
17971801
x.modules)
17981802
in
17991803
program f cxt x.program
@@ -1809,7 +1813,9 @@ let node_program ~output_prefix f ( x : J.deps_program) =
18091813
Lam_module_ident.id x,
18101814
Js_program_loader.string_of_module_id
18111815
~hint_output_dir:(Filename.dirname output_prefix)
1812-
NodeJS x)
1816+
NodeJS
1817+
(Js_packages_state.get_packages_info ())
1818+
x)
18131819
x.modules)
18141820
in
18151821
program f cxt x.program
@@ -1824,9 +1830,12 @@ let amd_program ~output_prefix kind f ( x : J.deps_program) =
18241830
P.string f (Printf.sprintf "%S" L.exports);
18251831

18261832
List.iter (fun x ->
1827-
let s =
1828-
Js_program_loader.string_of_module_id
1829-
~hint_output_dir:(Filename.dirname output_prefix) kind x in
1833+
let s : string =
1834+
Js_program_loader.string_of_module_id
1835+
~hint_output_dir:(Filename.dirname output_prefix)
1836+
kind
1837+
(Js_packages_state.get_packages_info ())
1838+
x in
18301839
P.string f L.comma ;
18311840
P.space f;
18321841
pp_string f s;
@@ -1865,7 +1874,9 @@ let es6_program ~output_prefix fmt f ( x : J.deps_program) =
18651874
Lam_module_ident.id x,
18661875
Js_program_loader.string_of_module_id
18671876
~hint_output_dir:(Filename.dirname output_prefix)
1868-
fmt x)
1877+
fmt
1878+
(Js_packages_state.get_packages_info())
1879+
x)
18691880
x.modules)
18701881
in
18711882
let () = P.force_newline f in

0 commit comments

Comments
 (0)