Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lift the restriction that -bs-package-name is mandatory for -bs-package-output #384

Merged
merged 23 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
06ff546
Lift the restriction that `-bs-package-name` is mandatory for `-bs-pa…
anmonteiro Oct 26, 2022
a61e5bb
fix previous test
anmonteiro Oct 26, 2022
8215d02
Fix `-bs-module-type`, get the suffix from the `-o <filename>.bs.js`
anmonteiro Oct 26, 2022
e5b0939
fix
anmonteiro Oct 26, 2022
b37e524
update flake.lock
anmonteiro Oct 27, 2022
224c106
fix package output
anmonteiro Oct 27, 2022
c1bbfdf
no `-nopervasives`
anmonteiro Oct 27, 2022
766ba50
fix some code review items
anmonteiro Oct 27, 2022
0a75eb2
Merge remote-tracking branch 'origin/main' into anmonteiro/no-bs-pack…
anmonteiro Oct 27, 2022
f93e1a6
Separate `Js_packages_info` into "Batch" and "Separate" compilation
anmonteiro Oct 27, 2022
9791702
Wait until `[@@@bs.config { flags = [| ... |] }]` is processed before
anmonteiro Oct 27, 2022
6926995
wip (#388)
anmonteiro Oct 28, 2022
77486ae
Merge remote-tracking branch 'origin/main' into anmonteiro/no-bs-pack…
anmonteiro Oct 28, 2022
172c22e
Merge branch 'anmonteiro/no-bs-package-name' of github.com:melange-re…
anmonteiro Oct 28, 2022
3768ce6
update flake lock
anmonteiro Oct 28, 2022
e3f02b3
bundle output_info instead of passing suffix and module_system around
anmonteiro Oct 28, 2022
5948f8c
refactor: clearer definition of query_package_infos
anmonteiro Oct 28, 2022
832b84e
fix: type error
anmonteiro Oct 28, 2022
3d8a41a
fix test
anmonteiro Oct 28, 2022
52095b2
refactor: less bindings in `Js_name_of_module_id.string_of_module_id`
anmonteiro Oct 28, 2022
f9f9692
refactor: Js_name_of_module_id.get_runtime_module_path
anmonteiro Oct 28, 2022
8ea2bad
rename function
anmonteiro Oct 28, 2022
78cb849
refactor: improve readability of `Js_name_of_module_id.string_of_modu…
anmonteiro Oct 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
724 changes: 362 additions & 362 deletions dune.mel

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions jscomp/core/config_util.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand All @@ -17,20 +17,20 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

(** A simple wrapper around [Config] module in compiler-libs, so that the search path
(* A simple wrapper around [Config] module in compiler-libs, so that the search path
is the same
*)

val find_opt : string -> string option
(** [find filename] Input is a file name, output is absolute path *)
(* [find filename] Input is a file name, output is absolute path *)

val output_prefix : string -> string
(** given the input, calculate the output prefix
(* given the input, calculate the output prefix

in: src/hello.ast
out: src/hello
Expand Down
40 changes: 36 additions & 4 deletions jscomp/core/dune
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@
(source_tree ../../ocaml-tree))
(action
;; requires `npm install` in the `ocaml-tree` directory... what a mess
(run node --no-experimental-fetch ../../ocaml-tree/wasm.js -fold -i %{deps} -o %{targets})))
(run
node
--no-experimental-fetch
../../ocaml-tree/wasm.js
-fold
-i
%{deps}
-o
%{targets})))

(rule
(targets js_record_iter.ml)
Expand All @@ -34,7 +42,15 @@
j.ml
(source_tree ../../ocaml-tree))
(action
(run node --no-experimental-fetch ../../ocaml-tree/wasm.js -record-iter -i %{deps} -o %{targets})))
(run
node
--no-experimental-fetch
../../ocaml-tree/wasm.js
-record-iter
-i
%{deps}
-o
%{targets})))

(rule
(targets js_record_map.ml)
Expand All @@ -43,7 +59,15 @@
j.ml
(source_tree ../../ocaml-tree))
(action
(run node --no-experimental-fetch ../../ocaml-tree/wasm.js -record-map -i %{deps} -o %{targets})))
(run
node
--no-experimental-fetch
../../ocaml-tree/wasm.js
-record-map
-i
%{deps}
-o
%{targets})))

(rule
(targets js_record_fold.ml)
Expand All @@ -52,4 +76,12 @@
j.ml
(source_tree ../../ocaml-tree))
(action
(run node --no-experimental-fetch ../../ocaml-tree/wasm.js -record-fold -i %{deps} -o %{targets})))
(run
node
--no-experimental-fetch
../../ocaml-tree/wasm.js
-record-fold
-i
%{deps}
-o
%{targets})))
28 changes: 16 additions & 12 deletions jscomp/core/js_dump_program.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,26 @@ let dump_program (x : J.program) oc =
let[@inline] is_default (x : Js_op.kind) =
match x with External { default } -> default | _ -> false

let node_program ~output_dir f (x : J.deps_program) =
let node_program ~package_info ~output_info ~output_dir f (x : J.deps_program) =
P.string f L.strict_directive;
P.newline f;
let cxt =
Js_dump_import_export.requires L.require Ext_pp_scope.empty f
(Ext_list.map x.modules (fun x ->
( x.id,
Js_name_of_module_id.string_of_module_id x ~output_dir NodeJS,
Js_name_of_module_id.string_of_module_id ~package_info ~output_info
~output_dir x,
is_default x.kind )))
in
program f cxt x.program

let es6_program ~output_dir fmt f (x : J.deps_program) =
let es6_program ~package_info ~output_info ~output_dir f (x : J.deps_program) =
let cxt =
Js_dump_import_export.imports Ext_pp_scope.empty f
(Ext_list.map x.modules (fun x ->
( x.id,
Js_name_of_module_id.string_of_module_id x ~output_dir fmt,
Js_name_of_module_id.string_of_module_id ~package_info x
~output_dir ~output_info,
is_default x.kind )))
in
let () = P.at_least_two_lines f in
Expand All @@ -99,9 +101,8 @@ let es6_program ~output_dir fmt f (x : J.deps_program) =
]}
*)

let pp_deps_program ~(output_prefix : string)
(kind : Js_packages_info.module_system) (program : J.deps_program)
(f : Ext_pp.t) =
let pp_deps_program ~package_info ~(output_info : Js_packages_info.output_info)
~(output_prefix : string) (f : Ext_pp.t) (program : J.deps_program) =
if not !Js_config.no_version_header then (
P.string f Bs_version.header;
P.newline f);
Expand All @@ -114,9 +115,10 @@ let pp_deps_program ~(output_prefix : string)
P.newline f);
let output_dir = Filename.dirname output_prefix in
ignore
(match kind with
| Es6 | Es6_global -> es6_program ~output_dir kind f program
| NodeJS -> node_program ~output_dir f program);
(match output_info.module_system with
| Js_packages_info.Es6 | Es6_global ->
es6_program ~package_info ~output_dir ~output_info f program
| NodeJS -> node_program ~package_info ~output_info ~output_dir f program);
P.newline f;
P.string f
(match program.side_effect with
Expand All @@ -125,5 +127,7 @@ let pp_deps_program ~(output_prefix : string)
P.newline f;
P.flush f ()

let dump_deps_program ~output_prefix kind x (oc : out_channel) =
pp_deps_program ~output_prefix kind x (P.from_channel oc)
let dump_deps_program ~package_info ~output_info ~output_prefix x
(oc : out_channel) =
pp_deps_program ~package_info ~output_info ~output_prefix (P.from_channel oc)
x
14 changes: 4 additions & 10 deletions jscomp/core/js_dump_program.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* Copyright (C) 2017 Authors of ReScript
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand All @@ -17,24 +17,18 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

val dump_program : J.program -> out_channel -> unit
(** only used for debugging purpose *)

val pp_deps_program :
output_prefix:string ->
Js_packages_info.module_system ->
J.deps_program ->
Ext_pp.t ->
unit

val dump_deps_program :
package_info:Js_packages_info.t ->
output_info:Js_packages_info.output_info ->
output_prefix:string ->
Js_packages_info.module_system ->
J.deps_program ->
out_channel ->
unit
14 changes: 9 additions & 5 deletions jscomp/core/js_implementation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) =
|> Lam_compile_main.compile outputprefix
in
if not !Js_config.cmj_only then
Lam_compile_main.lambda_as_module js_program outputprefix);
(* XXX(anmonteiro): important that we get package_info after
processing, as `[@@@config {flags = [| ... |]}]` could have added to
package specs. *)
let package_info = Js_packages_state.get_packages_info () in
Lam_compile_main.lambda_as_module ~package_info js_program outputprefix);
process_with_gentype (outputprefix ^ ".cmt")

let implementation ~parser ~lang ppf fname =
Expand Down Expand Up @@ -213,7 +217,8 @@ let implementation_cmj _ppf fname =
(* this is needed because the path is used to find other modules path *)
Res_compmisc.init_path ();
let cmj = Js_cmj_format.from_file fname in
Lam_compile_main.lambda_as_module cmj.delayed_program
Lam_compile_main.lambda_as_module ~package_info:cmj.package_spec
cmj.delayed_program
(Config_util.output_prefix fname)

let make_structure_item ~ns cunit : Parsetree.structure_item =
Expand All @@ -223,9 +228,8 @@ let make_structure_item ~ns cunit : Parsetree.structure_item =
(Mb.mk { txt = Some cunit; loc }
(Mod.ident { txt = Lident (Ext_namespace_encode.make ~ns cunit); loc }))

(** decoding [.mlmap]
keep in sync {!Bsb_namespace_map_gen.output}
*)
(* decoding [.mlmap]
keep in sync {!Bsb_namespace_map_gen.output} *)
let implementation_map ppf sourcefile =
let () = Js_config.cmj_only := true in
let ichan = open_in_bin sourcefile in
Expand Down