Skip to content

Commit e3239d8

Browse files
author
Hongbo Zhang
committed
[feature] address #395 behavior, output_prefix for cmj files
1 parent 2ba721d commit e3239d8

File tree

9 files changed

+19
-16
lines changed

9 files changed

+19
-16
lines changed

jscomp/js_config.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type env =
3737
let default_env = ref NodeJS
3838

3939
let ext = ref ".js"
40+
let cmj_ext = ".cmj"
4041
let get_ext () = !ext
4142
let get_env () = !default_env
4243

jscomp/js_config.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type env =
3333
| AmdJS
3434
| Goog of string option
3535

36+
val cmj_ext : string
3637
val get_env : unit -> env
3738
val get_ext : unit -> string
3839

jscomp/js_implementation.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ let implementation ppf sourcefile outputprefix =
7676
match
7777
Lam_compile_group.lambda_as_module
7878
finalenv current_signature
79-
sourcefile lambda with
79+
sourcefile outputprefix lambda with
8080
| e -> e
8181
| exception e ->
8282
(* Save to a file instead so that it will not scare user *)

jscomp/js_main.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,17 @@ let process_interface_file ppf name =
4444

4545
let process_implementation_file ppf name =
4646
let opref = output_prefix name in
47-
Js_implementation.implementation ppf name opref;
48-
objfiles := (opref ^ ".cmo") :: !objfiles
47+
Js_implementation.implementation ppf name opref
48+
4949
let process_file ppf name =
5050
if Filename.check_suffix name ".ml"
5151
|| Filename.check_suffix name ".mlt" then begin
5252
let opref = output_prefix name in
53-
Js_implementation.implementation ppf name opref;
54-
objfiles := (opref ^ ".cmo") :: !objfiles
53+
Js_implementation.implementation ppf name opref
5554
end
5655
else if Filename.check_suffix name !Config.interface_suffix then begin
5756
let opref = output_prefix name in
58-
Js_implementation.interface ppf name opref;
59-
if !make_package then objfiles := (opref ^ ".cmi") :: !objfiles
57+
Js_implementation.interface ppf name opref
6058
end
6159
else
6260
raise(Arg.Bad("don't know what to do with " ^ name))

jscomp/js_pack.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ let get_files dir =
3131
let arr =
3232
Sys.readdir dir
3333
|> Ext_array.filter_map
34-
(fun x -> if Ext_string.ends_with x ".cmj" then Some (Filename.concat dir x) else None )
34+
(fun x -> if Ext_string.ends_with x Js_config.cmj_ext then Some (Filename.concat dir x) else None )
3535
in
3636
(* Sort to guarantee it works the same across OSes *)
3737
Array.sort (fun (x : string) y -> Pervasives.compare x y ) arr;

jscomp/lam_compile_env.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ let find_and_add_if_not_exist (id, pos) env ~not_found ~found =
9999
let oid = Lam_module_ident.of_ml id in
100100
begin match Hashtbl.find cached_tbl oid with
101101
| exception Not_found ->
102-
let cmj_table = Config_util.find_cmj (id.name ^ ".cmj") in
102+
let cmj_table = Config_util.find_cmj (id.name ^ Js_config.cmj_ext) in
103103
begin match
104104
Type_util.find_serializable_signatures_by_path
105105
(Pident id) env with
@@ -155,7 +155,7 @@ let query_and_add_if_not_exist (type u)
155155
begin match oid.kind with
156156
| Runtime ->
157157
let cmj_table =
158-
Config_util.find_cmj (Lam_module_ident.name oid ^ ".cmj") in
158+
Config_util.find_cmj (Lam_module_ident.name oid ^ Js_config.cmj_ext) in
159159
add_cached_tbl oid (Runtime (true,cmj_table)) ;
160160
begin match env with
161161
| Has_env _ ->
@@ -166,7 +166,7 @@ let query_and_add_if_not_exist (type u)
166166
| Ml
167167
->
168168
let cmj_table =
169-
Config_util.find_cmj (Lam_module_ident.name oid ^ ".cmj") in
169+
Config_util.find_cmj (Lam_module_ident.name oid ^ Js_config.cmj_ext) in
170170
begin match env with
171171
| Has_env env ->
172172
begin match

jscomp/lam_compile_group.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ let compile_group ({filename = file_name; env;} as meta : Lam_stats.meta)
177177
it's used or not
178178
[non_export] is only used in playground
179179
*)
180-
let compile ~filename non_export env _sigs lam =
180+
let compile ~filename output_prefix non_export env _sigs lam =
181181
let export_idents =
182182
if non_export then
183183
[]
@@ -401,7 +401,7 @@ let compile ~filename non_export env _sigs lam =
401401
in
402402
(if not @@ Ext_string.is_empty filename then
403403
Js_cmj_format.to_file
404-
(Ext_filename.chop_extension ~loc:__LOC__ filename ^ ".cmj") v);
404+
(output_prefix ^ Js_config.cmj_ext) v);
405405
Js_program_loader.decorate_deps required_modules v.effect js
406406
)
407407
| _ -> raise Not_a_module
@@ -415,14 +415,15 @@ let lambda_as_module
415415
env
416416
(sigs : Types.signature)
417417
(filename : string)
418+
(output_prefix : string)
418419
(lam : Lambda.lambda) =
419420
begin
420421
Lam_current_unit.set_file filename ;
421422
Lam_current_unit.iset_debug_file "tuple_alloc.ml";
422423
Ext_pervasives.with_file_as_chan
423424
(Js_config.get_output_file filename)
424425
(fun chan -> Js_dump.dump_deps_program
425-
(compile ~filename false env sigs lam) chan)
426+
(compile ~filename output_prefix false env sigs lam) chan)
426427
end
427428
(* We can use {!Env.current_unit = "Pervasives"} to tell if it is some specific module,
428429
We need handle some definitions in standard libraries in a special way, most are io specific,

jscomp/lam_compile_group.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
*)
4040
val compile :
4141
filename : string ->
42+
string ->
4243
bool ->
4344
Env.t ->
4445
Types.signature ->
@@ -47,4 +48,5 @@ val compile :
4748

4849
val lambda_as_module :
4950
Env.t ->
50-
Types.signature -> string -> Lambda.lambda -> unit
51+
Types.signature -> string ->
52+
string -> Lambda.lambda -> unit

jscomp/lam_stats_util.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ and all_lambdas meta (xs : Lambda.lambda list) =
215215
let dump_exports_arities (meta : Lam_stats.meta ) =
216216
let fmt =
217217
if meta.filename != "" then
218-
let cmj_file = Ext_filename.chop_extension meta.filename ^ ".cmj" in
218+
let cmj_file = Ext_filename.chop_extension meta.filename ^ Js_config.cmj_ext in
219219
let out = open_out cmj_file in
220220
Format.formatter_of_out_channel out
221221
else

0 commit comments

Comments
 (0)