Skip to content

Commit

Permalink
[feature] address #395 behavior, output_prefix for cmj files
Browse files Browse the repository at this point in the history
  • Loading branch information
Hongbo Zhang committed May 23, 2016
1 parent 2ba721d commit e3239d8
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 16 deletions.
1 change: 1 addition & 0 deletions jscomp/js_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type env =
let default_env = ref NodeJS

let ext = ref ".js"
let cmj_ext = ".cmj"
let get_ext () = !ext
let get_env () = !default_env

Expand Down
1 change: 1 addition & 0 deletions jscomp/js_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type env =
| AmdJS
| Goog of string option

val cmj_ext : string
val get_env : unit -> env
val get_ext : unit -> string

Expand Down
2 changes: 1 addition & 1 deletion jscomp/js_implementation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let implementation ppf sourcefile outputprefix =
match
Lam_compile_group.lambda_as_module
finalenv current_signature
sourcefile lambda with
sourcefile outputprefix lambda with
| e -> e
| exception e ->
(* Save to a file instead so that it will not scare user *)
Expand Down
10 changes: 4 additions & 6 deletions jscomp/js_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,17 @@ let process_interface_file ppf name =

let process_implementation_file ppf name =
let opref = output_prefix name in
Js_implementation.implementation ppf name opref;
objfiles := (opref ^ ".cmo") :: !objfiles
Js_implementation.implementation ppf name opref

let process_file ppf name =
if Filename.check_suffix name ".ml"
|| Filename.check_suffix name ".mlt" then begin
let opref = output_prefix name in
Js_implementation.implementation ppf name opref;
objfiles := (opref ^ ".cmo") :: !objfiles
Js_implementation.implementation ppf name opref
end
else if Filename.check_suffix name !Config.interface_suffix then begin
let opref = output_prefix name in
Js_implementation.interface ppf name opref;
if !make_package then objfiles := (opref ^ ".cmi") :: !objfiles
Js_implementation.interface ppf name opref
end
else
raise(Arg.Bad("don't know what to do with " ^ name))
Expand Down
2 changes: 1 addition & 1 deletion jscomp/js_pack.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let get_files dir =
let arr =
Sys.readdir dir
|> Ext_array.filter_map
(fun x -> if Ext_string.ends_with x ".cmj" then Some (Filename.concat dir x) else None )
(fun x -> if Ext_string.ends_with x Js_config.cmj_ext then Some (Filename.concat dir x) else None )
in
(* Sort to guarantee it works the same across OSes *)
Array.sort (fun (x : string) y -> Pervasives.compare x y ) arr;
Expand Down
6 changes: 3 additions & 3 deletions jscomp/lam_compile_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ let find_and_add_if_not_exist (id, pos) env ~not_found ~found =
let oid = Lam_module_ident.of_ml id in
begin match Hashtbl.find cached_tbl oid with
| exception Not_found ->
let cmj_table = Config_util.find_cmj (id.name ^ ".cmj") in
let cmj_table = Config_util.find_cmj (id.name ^ Js_config.cmj_ext) in
begin match
Type_util.find_serializable_signatures_by_path
(Pident id) env with
Expand Down Expand Up @@ -155,7 +155,7 @@ let query_and_add_if_not_exist (type u)
begin match oid.kind with
| Runtime ->
let cmj_table =
Config_util.find_cmj (Lam_module_ident.name oid ^ ".cmj") in
Config_util.find_cmj (Lam_module_ident.name oid ^ Js_config.cmj_ext) in
add_cached_tbl oid (Runtime (true,cmj_table)) ;
begin match env with
| Has_env _ ->
Expand All @@ -166,7 +166,7 @@ let query_and_add_if_not_exist (type u)
| Ml
->
let cmj_table =
Config_util.find_cmj (Lam_module_ident.name oid ^ ".cmj") in
Config_util.find_cmj (Lam_module_ident.name oid ^ Js_config.cmj_ext) in
begin match env with
| Has_env env ->
begin match
Expand Down
7 changes: 4 additions & 3 deletions jscomp/lam_compile_group.ml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ let compile_group ({filename = file_name; env;} as meta : Lam_stats.meta)
it's used or not
[non_export] is only used in playground
*)
let compile ~filename non_export env _sigs lam =
let compile ~filename output_prefix non_export env _sigs lam =
let export_idents =
if non_export then
[]
Expand Down Expand Up @@ -401,7 +401,7 @@ let compile ~filename non_export env _sigs lam =
in
(if not @@ Ext_string.is_empty filename then
Js_cmj_format.to_file
(Ext_filename.chop_extension ~loc:__LOC__ filename ^ ".cmj") v);
(output_prefix ^ Js_config.cmj_ext) v);
Js_program_loader.decorate_deps required_modules v.effect js
)
| _ -> raise Not_a_module
Expand All @@ -415,14 +415,15 @@ let lambda_as_module
env
(sigs : Types.signature)
(filename : string)
(output_prefix : string)
(lam : Lambda.lambda) =
begin
Lam_current_unit.set_file filename ;
Lam_current_unit.iset_debug_file "tuple_alloc.ml";
Ext_pervasives.with_file_as_chan
(Js_config.get_output_file filename)
(fun chan -> Js_dump.dump_deps_program
(compile ~filename false env sigs lam) chan)
(compile ~filename output_prefix false env sigs lam) chan)
end
(* We can use {!Env.current_unit = "Pervasives"} to tell if it is some specific module,
We need handle some definitions in standard libraries in a special way, most are io specific,
Expand Down
4 changes: 3 additions & 1 deletion jscomp/lam_compile_group.mli
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
*)
val compile :
filename : string ->
string ->
bool ->
Env.t ->
Types.signature ->
Expand All @@ -47,4 +48,5 @@ val compile :

val lambda_as_module :
Env.t ->
Types.signature -> string -> Lambda.lambda -> unit
Types.signature -> string ->
string -> Lambda.lambda -> unit
2 changes: 1 addition & 1 deletion jscomp/lam_stats_util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ and all_lambdas meta (xs : Lambda.lambda list) =
let dump_exports_arities (meta : Lam_stats.meta ) =
let fmt =
if meta.filename != "" then
let cmj_file = Ext_filename.chop_extension meta.filename ^ ".cmj" in
let cmj_file = Ext_filename.chop_extension meta.filename ^ Js_config.cmj_ext in
let out = open_out cmj_file in
Format.formatter_of_out_channel out
else
Expand Down

0 comments on commit e3239d8

Please sign in to comment.