diff --git a/jscomp/bsb/bsb_config.ml b/jscomp/bsb/bsb_config.ml index 63a764db0a..0308f060c9 100644 --- a/jscomp/bsb/bsb_config.ml +++ b/jscomp/bsb/bsb_config.ml @@ -62,7 +62,7 @@ let rev_lib_bs_prefix p = rev_lib_bs // p let ocaml_bin_install_prefix p = lib_ocaml // p -let proj_rel path = Bsb_ninja_global_vars.lazy_src_root_dir // path +let proj_rel path = rev_lib_bs // path (** it may not be a bad idea to hard code the binary path of bsb in configuration time diff --git a/jscomp/bsb/bsb_ninja_gen.ml b/jscomp/bsb/bsb_ninja_gen.ml index 336e2fdf5c..37a6e6fd91 100644 --- a/jscomp/bsb/bsb_ninja_gen.ml +++ b/jscomp/bsb/bsb_ninja_gen.ml @@ -236,9 +236,9 @@ let output_ninja_and_namespace_map let oc = open_out_bin (cwd_lib_bs // Literals.build_ninja) in mark_rescript oc; - Bsb_ninja_targets.output_kv + (* Bsb_ninja_targets.output_kv Bsb_ninja_global_vars.src_root_dir per_proj_dir - oc ; + oc ; *) output_static_resources static_resources rules.copy_resources oc ; (** Generate build statement for each file *) Ext_list.iter bs_file_groups diff --git a/jscomp/bsb/bsb_ninja_global_vars.ml b/jscomp/bsb/bsb_ninja_global_vars.ml index 2f472a98ae..1db8998fdc 100644 --- a/jscomp/bsb/bsb_ninja_global_vars.ml +++ b/jscomp/bsb/bsb_ninja_global_vars.ml @@ -30,9 +30,9 @@ to be "a" and "$a" *) -let src_root_dir = "g_root" +(* let src_root_dir = "g_root" -let lazy_src_root_dir = "$g_root" +let lazy_src_root_dir = "$g_root" *) diff --git a/jscomp/bsb/bsb_ninja_rule.ml b/jscomp/bsb/bsb_ninja_rule.ml index 2ab278fa37..b8d826846f 100644 --- a/jscomp/bsb/bsb_ninja_rule.ml +++ b/jscomp/bsb/bsb_ninja_rule.ml @@ -218,7 +218,7 @@ let make_custom_rules ); Ext_buffer.add_char_string buf ' ' bsc_flags; - Ext_buffer.add_string buf " -bs-ast -o $out $i"; + Ext_buffer.add_string buf " -absname -bs-ast -o $out $i"; Ext_buffer.contents buf in let build_ast = diff --git a/jscomp/core/config_util.ml b/jscomp/core/config_util.ml index 48a45c2280..15d04c886d 100644 --- a/jscomp/core/config_util.ml +++ b/jscomp/core/config_util.ml @@ -47,4 +47,12 @@ let find_opt file = find_in_path_uncap !Config.load_path file +let output_prefix name = + match !Clflags.output_name with + | None -> + Ext_namespace_encode.make + (Filename.remove_extension name) + ?ns:!Clflags.dont_record_crc_unit + | Some oname -> + Filename.remove_extension oname diff --git a/jscomp/core/config_util.mli b/jscomp/core/config_util.mli index 0c621e3970..cad2a82d0e 100644 --- a/jscomp/core/config_util.mli +++ b/jscomp/core/config_util.mli @@ -37,3 +37,16 @@ val find_opt : string -> string option (** [find filename] Input is a file name, output is absolute path *) + +(** given the input, calculate the output prefix + + in: src/hello.ast + out: src/hello + + with namespace: + in: src/hello.ast + out: src/hello-Ns +*) +val output_prefix : + string -> + string \ No newline at end of file diff --git a/jscomp/core/js_implementation.ml b/jscomp/core/js_implementation.ml index 4d9b94b706..caa99a3dc8 100644 --- a/jscomp/core/js_implementation.ml +++ b/jscomp/core/js_implementation.ml @@ -102,7 +102,11 @@ let after_parsing_sig ppf outputprefix ast = -let interface ~parser ppf fname outputprefix = +let interface ~parser ppf ?outputprefix fname = + let outputprefix = + match outputprefix with + | None -> Config_util.output_prefix fname + | Some x -> x in Res_compmisc.init_path (); parser fname |> Cmd_ppx_apply.apply_rewriters ~restore:false ~tool_name:Js_config.tool_name Mli @@ -111,12 +115,12 @@ let interface ~parser ppf fname outputprefix = |> print_if_pipe ppf Clflags.dump_source Pprintast.signature |> after_parsing_sig ppf outputprefix -let interface_mliast ppf fname outputprefix setup = +let interface_mliast ppf fname setup = Res_compmisc.init_path (); Binary_ast.read_ast_exn ~fname Mli setup |> print_if_pipe ppf Clflags.dump_parsetree Printast.interface |> print_if_pipe ppf Clflags.dump_source Pprintast.signature - |> after_parsing_sig ppf outputprefix + |> after_parsing_sig ppf (Config_util.output_prefix fname) let all_module_alias (ast : Parsetree.structure)= Ext_list.for_all ast (fun {pstr_desc} -> @@ -196,7 +200,11 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) = end; process_with_gentype (outputprefix ^ ".cmt") end -let implementation ~parser ppf fname outputprefix = +let implementation ~parser ppf ?outputprefix fname = + let outputprefix = + match outputprefix with + | None -> Config_util.output_prefix fname + | Some x -> x in Res_compmisc.init_path (); parser fname |> Cmd_ppx_apply.apply_rewriters ~restore:false ~tool_name:Js_config.tool_name Ml @@ -205,12 +213,13 @@ let implementation ~parser ppf fname outputprefix = |> print_if_pipe ppf Clflags.dump_source Pprintast.structure |> after_parsing_impl ppf outputprefix -let implementation_mlast ppf fname outputprefix setup = +let implementation_mlast ppf fname setup = + Res_compmisc.init_path (); Binary_ast.read_ast_exn ~fname Ml setup |> print_if_pipe ppf Clflags.dump_parsetree Printast.implementation |> print_if_pipe ppf Clflags.dump_source Pprintast.structure - |> after_parsing_impl ppf outputprefix + |> after_parsing_impl ppf (Config_util.output_prefix fname ) @@ -232,7 +241,7 @@ let make_structure_item ~ns cunit : Parsetree.structure_item = (** decoding [.mlmap] keep in sync {!Bsb_namespace_map_gen.output} *) -let implementation_map ppf sourcefile outputprefix = +let implementation_map ppf sourcefile = let () = Js_config.cmj_only := true in let ichan = open_in_bin sourcefile in seek_in ichan (Ext_digest.length +1); @@ -247,5 +256,5 @@ let implementation_map ppf sourcefile outputprefix = ml_ast |> print_if_pipe ppf Clflags.dump_parsetree Printast.implementation |> print_if_pipe ppf Clflags.dump_source Pprintast.structure - |> after_parsing_impl ppf outputprefix + |> after_parsing_impl ppf (Config_util.output_prefix sourcefile) diff --git a/jscomp/core/js_implementation.mli b/jscomp/core/js_implementation.mli index b73fa9ff34..2b2acc9b20 100644 --- a/jscomp/core/js_implementation.mli +++ b/jscomp/core/js_implementation.mli @@ -38,13 +38,12 @@ val interface : parser:(string -> Parsetree.signature) -> Format.formatter -> - string -> + ?outputprefix:string -> string -> unit val interface_mliast : Format.formatter -> - string -> string -> ([`ml | `rescript | `reason ] -> unit) -> unit @@ -64,7 +63,7 @@ val interface_mliast : val implementation : parser:(string -> Parsetree.structure) -> Format.formatter -> - string -> + ?outputprefix:string -> string -> unit (** [implementation ppf sourcefile outprefix] compiles to JS directly *) @@ -72,8 +71,8 @@ val implementation : val implementation_mlast : Format.formatter -> string -> - string -> ([`ml | `rescript | `reason ] -> unit) -> unit -val implementation_map : Format.formatter -> string -> string -> unit \ No newline at end of file +val implementation_map : + Format.formatter -> string -> unit \ No newline at end of file diff --git a/jscomp/main/js_main.ml b/jscomp/main/js_main.ml index 8df4ceaaf4..8fa2e11483 100644 --- a/jscomp/main/js_main.ml +++ b/jscomp/main/js_main.ml @@ -10,16 +10,14 @@ (* *) (***********************************************************************) -let output_prefix name = - match !Clflags.output_name with - | None -> - Ext_namespace_encode.make - (Filename.remove_extension name) - ?ns:!Clflags.dont_record_crc_unit - | Some oname -> - Filename.remove_extension oname - +let set_abs_input_name sourcefile = + let sourcefile = + if !Location.absname && Filename.is_relative sourcefile then + Ext_path.absolute_cwd_path sourcefile + else sourcefile in + Location.set_input_name sourcefile; + sourcefile let setup_error_printer (syntax_kind : [ `ml | `reason | `rescript ])= @@ -36,9 +34,10 @@ let setup_error_printer (syntax_kind : [ `ml | `reason | `rescript ])= -let handle_reason (type a) (kind : a Ml_binary.kind) sourcefile ppf opref = +let handle_reason (type a) (kind : a Ml_binary.kind) sourcefile ppf = setup_error_printer `reason; let tmpfile = Ast_reason_pp.pp sourcefile in + let outputprefix = Config_util.output_prefix sourcefile in (match kind with | Ml_binary.Ml -> Js_implementation.implementation @@ -47,7 +46,7 @@ let handle_reason (type a) (kind : a Ml_binary.kind) sourcefile ppf opref = let ast = Ml_binary.read_ast Ml in_chan in close_in in_chan; ast ) - ppf tmpfile opref + ppf tmpfile ~outputprefix | Ml_binary.Mli -> Js_implementation.interface @@ -56,10 +55,9 @@ let handle_reason (type a) (kind : a Ml_binary.kind) sourcefile ppf opref = let ast = Ml_binary.read_ast Mli in_chan in close_in in_chan; ast ) - ppf tmpfile opref ; ); + ppf tmpfile ~outputprefix ); Ast_reason_pp.clean tmpfile - let process_file sourcefile ?(kind ) ppf = @@ -67,44 +65,51 @@ let process_file sourcefile The {!Location.input_name} relies on that we write the binary ast properly *) - Location.set_input_name sourcefile; - let opref = output_prefix sourcefile in let kind = match kind with | None -> Ext_file_extensions.classify_input (Ext_filename.get_extension_maybe sourcefile) | Some kind -> kind in match kind with - | Re -> handle_reason Ml sourcefile ppf opref + | Re -> + let sourcefile = set_abs_input_name sourcefile in + handle_reason Ml sourcefile ppf | Rei -> - handle_reason Mli sourcefile ppf opref + let sourcefile = set_abs_input_name sourcefile in + handle_reason Mli sourcefile ppf | Ml -> + let sourcefile = set_abs_input_name sourcefile in Js_implementation.implementation ~parser:Pparse_driver.parse_implementation - ppf sourcefile opref + ppf sourcefile | Mli -> + let sourcefile = set_abs_input_name sourcefile in Js_implementation.interface ~parser:Pparse_driver.parse_interface - ppf sourcefile opref + ppf sourcefile | Res -> + let sourcefile = set_abs_input_name sourcefile in setup_error_printer `rescript; Js_implementation.implementation ~parser:Res_driver.parse_implementation - ppf sourcefile opref + ppf sourcefile | Resi -> + let sourcefile = set_abs_input_name sourcefile in setup_error_printer `rescript; Js_implementation.interface ~parser:Res_driver.parse_interface - ppf sourcefile opref + ppf sourcefile | Intf_ast -> - Js_implementation.interface_mliast ppf sourcefile opref + Js_implementation.interface_mliast ppf sourcefile setup_error_printer ; | Impl_ast -> - Js_implementation.implementation_mlast ppf sourcefile opref + Js_implementation.implementation_mlast ppf sourcefile setup_error_printer; | Mlmap - -> Js_implementation.implementation_map ppf sourcefile opref + -> + Location.set_input_name sourcefile; + Js_implementation.implementation_map ppf sourcefile | Cmi -> let cmi_sign = (Cmi_format.read_cmi sourcefile).cmi_sign in diff --git a/jscomp/others/release.ninja b/jscomp/others/release.ninja index 326fee256e..779090ab9a 100644 --- a/jscomp/others/release.ninja +++ b/jscomp/others/release.ninja @@ -1,5 +1,5 @@ -bsc_flags = -no-keep-locs -absname -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -nopervasives -unsafe -w +50 -warn-error A -open Bs_stdlib_mini -I ./runtime +bsc_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -nopervasives -unsafe -w +50 -warn-error A -open Bs_stdlib_mini -I ./runtime rule cc command = $bsc -bs-cmi -bs-cmj $bsc_flags -I others $in diff --git a/jscomp/runtime/release.ninja b/jscomp/runtime/release.ninja index 5bc51c1f52..529d7d827b 100644 --- a/jscomp/runtime/release.ninja +++ b/jscomp/runtime/release.ninja @@ -1,5 +1,5 @@ -bsc_no_open_flags = -no-keep-locs -absname -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -nopervasives -unsafe -w +50 -warn-error A +bsc_no_open_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -nopervasives -unsafe -w +50 -warn-error A bsc_flags = $bsc_no_open_flags -open Bs_stdlib_mini rule cc diff --git a/jscomp/stdlib-406/release.ninja b/jscomp/stdlib-406/release.ninja index 647b3f12fb..d4538ad2c3 100644 --- a/jscomp/stdlib-406/release.ninja +++ b/jscomp/stdlib-406/release.ninja @@ -1,5 +1,5 @@ -bsc_flags = -no-keep-locs -absname -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -w -9-3-106 -warn-error A -I runtime -I others +bsc_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -w -9-3-106 -warn-error A -I runtime -I others rule cc command = $bsc -bs-cmi -bs-cmj $bsc_flags -I stdlib-406 $in diff --git a/jscomp/syntax/ast_exp_extension.ml b/jscomp/syntax/ast_exp_extension.ml index 72dda1f456..72a7c7794c 100644 --- a/jscomp/syntax/ast_exp_extension.ml +++ b/jscomp/syntax/ast_exp_extension.ml @@ -60,7 +60,7 @@ let handle_extension record_as_js_object e (self : Bs_ast_mapper.mapper) let loc_start = loc.loc_start in let (file, lnum, __) = Location.get_pos_info loc_start in Printf.sprintf "%s %d" - file lnum in + (Filename.basename file) lnum in let e = self.expr self e in Exp.sequence ~loc (Ast_compatible.app1 ~loc diff --git a/jscomp/test/bs_hashtbl_string_test.js b/jscomp/test/bs_hashtbl_string_test.js index 4d1345d28c..4f173e0f5d 100644 --- a/jscomp/test/bs_hashtbl_string_test.js +++ b/jscomp/test/bs_hashtbl_string_test.js @@ -179,12 +179,12 @@ function bench4(param) { function bench5(param) { var table = Belt_internalBucketsType.make(Int.hash, Int.eq, 1000000); - console.time("test/bs_hashtbl_string_test.ml 133"); + console.time("bs_hashtbl_string_test.ml 133"); for(var i = 0; i <= 1000000; ++i){ Belt_HashMap.set(table, i, i); } - console.timeEnd("test/bs_hashtbl_string_test.ml 133"); - console.time("test/bs_hashtbl_string_test.ml 137"); + console.timeEnd("bs_hashtbl_string_test.ml 133"); + console.time("bs_hashtbl_string_test.ml 137"); for(var i$1 = 0; i$1 <= 1000000; ++i$1){ if (!Belt_HashMap.has(table, i$1)) { throw { @@ -199,12 +199,12 @@ function bench5(param) { } } - console.timeEnd("test/bs_hashtbl_string_test.ml 137"); - console.time("test/bs_hashtbl_string_test.ml 141"); + console.timeEnd("bs_hashtbl_string_test.ml 137"); + console.time("bs_hashtbl_string_test.ml 141"); for(var i$2 = 0; i$2 <= 1000000; ++i$2){ Belt_HashMap.remove(table, i$2); } - console.timeEnd("test/bs_hashtbl_string_test.ml 141"); + console.timeEnd("bs_hashtbl_string_test.ml 141"); if (Belt_HashMap.isEmpty(table)) { return ; } @@ -291,11 +291,11 @@ function bench7(param) { }; } -console.time("test/bs_hashtbl_string_test.ml 203"); +console.time("bs_hashtbl_string_test.ml 203"); bench7(undefined); -console.timeEnd("test/bs_hashtbl_string_test.ml 203"); +console.timeEnd("bs_hashtbl_string_test.ml 203"); var N; diff --git a/jscomp/test/bs_rbset_int_bench.js b/jscomp/test/bs_rbset_int_bench.js index b197957a13..85cf974cd6 100644 --- a/jscomp/test/bs_rbset_int_bench.js +++ b/jscomp/test/bs_rbset_int_bench.js @@ -4,12 +4,12 @@ var Rbset = require("./rbset.js"); function bench(param) { var data = /* Empty */0; - console.time("test/bs_rbset_int_bench.ml 7"); + console.time("bs_rbset_int_bench.ml 7"); for(var i = 0; i <= 1000000; ++i){ data = Rbset.add(i, data); } - console.timeEnd("test/bs_rbset_int_bench.ml 7"); - console.time("test/bs_rbset_int_bench.ml 11"); + console.timeEnd("bs_rbset_int_bench.ml 7"); + console.time("bs_rbset_int_bench.ml 11"); for(var i$1 = 0; i$1 <= 1000000; ++i$1){ if (!Rbset.mem(i$1, data)) { throw { @@ -24,12 +24,12 @@ function bench(param) { } } - console.timeEnd("test/bs_rbset_int_bench.ml 11"); - console.time("test/bs_rbset_int_bench.ml 14"); + console.timeEnd("bs_rbset_int_bench.ml 11"); + console.time("bs_rbset_int_bench.ml 14"); for(var i$2 = 0; i$2 <= 1000000; ++i$2){ data = Rbset.remove(i$2, data); } - console.timeEnd("test/bs_rbset_int_bench.ml 14"); + console.timeEnd("bs_rbset_int_bench.ml 14"); if (Rbset.cardinal(data) === 0) { return ; } @@ -44,11 +44,11 @@ function bench(param) { }; } -console.time("test/bs_rbset_int_bench.ml 21"); +console.time("bs_rbset_int_bench.ml 21"); bench(undefined); -console.timeEnd("test/bs_rbset_int_bench.ml 21"); +console.timeEnd("bs_rbset_int_bench.ml 21"); var count = 1000000; diff --git a/jscomp/test/bs_set_bench.js b/jscomp/test/bs_set_bench.js index 067b7c711c..bb657eab98 100644 --- a/jscomp/test/bs_set_bench.js +++ b/jscomp/test/bs_set_bench.js @@ -4,12 +4,12 @@ var Belt_SetInt = require("../../lib/js/belt_SetInt.js"); function bench(param) { var data; - console.time("test/bs_set_bench.ml 7"); + console.time("bs_set_bench.ml 7"); for(var i = 0; i <= 1000000; ++i){ data = Belt_SetInt.add(data, i); } - console.timeEnd("test/bs_set_bench.ml 7"); - console.time("test/bs_set_bench.ml 11"); + console.timeEnd("bs_set_bench.ml 7"); + console.time("bs_set_bench.ml 11"); for(var i$1 = 0; i$1 <= 1000000; ++i$1){ if (!Belt_SetInt.has(data, i$1)) { throw { @@ -24,12 +24,12 @@ function bench(param) { } } - console.timeEnd("test/bs_set_bench.ml 11"); - console.time("test/bs_set_bench.ml 14"); + console.timeEnd("bs_set_bench.ml 11"); + console.time("bs_set_bench.ml 14"); for(var i$2 = 0; i$2 <= 1000000; ++i$2){ data = Belt_SetInt.remove(data, i$2); } - console.timeEnd("test/bs_set_bench.ml 14"); + console.timeEnd("bs_set_bench.ml 14"); if (Belt_SetInt.size(data) === 0) { return ; } @@ -44,11 +44,11 @@ function bench(param) { }; } -console.time("test/bs_set_bench.ml 21"); +console.time("bs_set_bench.ml 21"); bench(undefined); -console.timeEnd("test/bs_set_bench.ml 21"); +console.timeEnd("bs_set_bench.ml 21"); var count = 1000000; diff --git a/jscomp/test/bs_sort_test.js b/jscomp/test/bs_sort_test.js index 95719af2a3..30fd18c0f5 100644 --- a/jscomp/test/bs_sort_test.js +++ b/jscomp/test/bs_sort_test.js @@ -123,27 +123,27 @@ var u1 = u.slice(0); var u2 = u.slice(0); -console.time("test/bs_sort_test.ml 80"); +console.time("bs_sort_test.ml 80"); Belt_SortArray.stableSortInPlaceBy(u, cmp); -console.timeEnd("test/bs_sort_test.ml 80"); +console.timeEnd("bs_sort_test.ml 80"); b("File \"bs_sort_test.ml\", line 81, characters 4-11", Belt_SortArray.isSorted(u, cmp)); -console.time("test/bs_sort_test.ml 82"); +console.time("bs_sort_test.ml 82"); Belt_SortArrayInt.stableSortInPlace(u2); -console.timeEnd("test/bs_sort_test.ml 82"); +console.timeEnd("bs_sort_test.ml 82"); b("File \"bs_sort_test.ml\", line 83, characters 4-11", Belt_SortArray.isSorted(u2, cmp)); -console.time("test/bs_sort_test.ml 84"); +console.time("bs_sort_test.ml 84"); Belt_SortArray.stableSortInPlaceBy(u1, cmp); -console.timeEnd("test/bs_sort_test.ml 84"); +console.timeEnd("bs_sort_test.ml 84"); b("File \"bs_sort_test.ml\", line 85, characters 4-11", Belt_SortArray.isSorted(u1, cmp)); diff --git a/jscomp/test/imm_map_bench.js b/jscomp/test/imm_map_bench.js index baa16edf7d..a07c8df507 100644 --- a/jscomp/test/imm_map_bench.js +++ b/jscomp/test/imm_map_bench.js @@ -45,17 +45,17 @@ function test2(param) { } -console.time("test/imm_map_bench.ml 44"); +console.time("imm_map_bench.ml 44"); test(undefined); -console.timeEnd("test/imm_map_bench.ml 44"); +console.timeEnd("imm_map_bench.ml 44"); -console.time("test/imm_map_bench.ml 45"); +console.time("imm_map_bench.ml 45"); test2(undefined); -console.timeEnd("test/imm_map_bench.ml 45"); +console.timeEnd("imm_map_bench.ml 45"); var A; diff --git a/lib/4.06.1/bsb.ml b/lib/4.06.1/bsb.ml index a3edd62d18..3e0dd45202 100644 --- a/lib/4.06.1/bsb.ml +++ b/lib/4.06.1/bsb.ml @@ -4943,51 +4943,6 @@ let is_empty (x : file_group) = Map_string.is_empty x.sources && x.resources = [] && x.generators = [] -end -module Bsb_ninja_global_vars -= struct -#1 "bsb_ninja_global_vars.ml" -(* Copyright (C) 2017 Authors of BuckleScript - * - * 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 - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * 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. *) - - - - - -(* Invariant: the two string literal has - to be "a" and "$a" -*) - -let src_root_dir = "g_root" - -let lazy_src_root_dir = "$g_root" - - - - - - end module Ext_module_system = struct @@ -5959,7 +5914,7 @@ let rev_lib_bs_prefix p = rev_lib_bs // p let ocaml_bin_install_prefix p = lib_ocaml // p -let proj_rel path = Bsb_ninja_global_vars.lazy_src_root_dir // path +let proj_rel path = rev_lib_bs // path (** it may not be a bad idea to hard code the binary path of bsb in configuration time @@ -13045,7 +13000,7 @@ let make_custom_rules ); Ext_buffer.add_char_string buf ' ' bsc_flags; - Ext_buffer.add_string buf " -bs-ast -o $out $i"; + Ext_buffer.add_string buf " -absname -bs-ast -o $out $i"; Ext_buffer.contents buf in let build_ast = @@ -13807,9 +13762,9 @@ let output_ninja_and_namespace_map let oc = open_out_bin (cwd_lib_bs // Literals.build_ninja) in mark_rescript oc; - Bsb_ninja_targets.output_kv + (* Bsb_ninja_targets.output_kv Bsb_ninja_global_vars.src_root_dir per_proj_dir - oc ; + oc ; *) output_static_resources static_resources rules.copy_resources oc ; (** Generate build statement for each file *) Ext_list.iter bs_file_groups diff --git a/lib/4.06.1/bsb.ml.d b/lib/4.06.1/bsb.ml.d index a56413c555..1b53671a37 100644 --- a/lib/4.06.1/bsb.ml.d +++ b/lib/4.06.1/bsb.ml.d @@ -32,7 +32,6 @@ ../lib/4.06.1/bsb.ml: ./bsb/bsb_ninja_file_groups.mli ../lib/4.06.1/bsb.ml: ./bsb/bsb_ninja_gen.ml ../lib/4.06.1/bsb.ml: ./bsb/bsb_ninja_gen.mli -../lib/4.06.1/bsb.ml: ./bsb/bsb_ninja_global_vars.ml ../lib/4.06.1/bsb.ml: ./bsb/bsb_ninja_regen.ml ../lib/4.06.1/bsb.ml: ./bsb/bsb_ninja_regen.mli ../lib/4.06.1/bsb.ml: ./bsb/bsb_ninja_rule.ml diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index 6253d5c05d..24b80c275e 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -8057,6 +8057,220 @@ let () = ) end +module Literals += struct +#1 "literals.ml" +(* 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 + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a later version). + * + * This program is distributed in the hope that it will be useful, + * 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. *) + + + + + + + +let js_array_ctor = "Array" +let js_type_number = "number" +let js_type_string = "string" +let js_type_object = "object" +let js_type_boolean = "boolean" +let js_undefined = "undefined" +let js_prop_length = "length" + +let prim = "prim" +let param = "param" +let partial_arg = "partial_arg" +let tmp = "tmp" + +let create = "create" (* {!Caml_exceptions.create}*) + +let runtime = "runtime" (* runtime directory *) + +let stdlib = "stdlib" + +let imul = "imul" (* signed int32 mul *) + +let setter_suffix = "#=" +let setter_suffix_len = String.length setter_suffix + +let debugger = "debugger" +let unsafe_downgrade = "unsafe_downgrade" +let fn_run = "fn_run" +let method_run = "method_run" + +let fn_method = "fn_method" +let fn_mk = "fn_mk" +(*let js_fn_runmethod = "js_fn_runmethod"*) + + + + + +(** nodejs *) +let node_modules = "node_modules" +let node_modules_length = String.length "node_modules" +let package_json = "package.json" +let bsconfig_json = "bsconfig.json" +let build_ninja = "build.ninja" + +(* Name of the library file created for each external dependency. *) +let library_file = "lib" + +let suffix_a = ".a" +let suffix_cmj = ".cmj" +let suffix_cmo = ".cmo" +let suffix_cma = ".cma" +let suffix_cmi = ".cmi" +let suffix_cmx = ".cmx" +let suffix_cmxa = ".cmxa" +let suffix_mll = ".mll" +let suffix_ml = ".ml" +let suffix_mli = ".mli" +let suffix_re = ".re" +let suffix_rei = ".rei" +let suffix_res = ".res" +let suffix_resi = ".resi" +let suffix_mlmap = ".mlmap" + +let suffix_cmt = ".cmt" +let suffix_cmti = ".cmti" +let suffix_ast = ".ast" +let suffix_iast = ".iast" +let suffix_d = ".d" +let suffix_js = ".js" +let suffix_bs_js = ".bs.js" +let suffix_mjs = ".mjs" +let suffix_cjs = ".cjs" +let suffix_gen_js = ".gen.js" +let suffix_gen_tsx = ".gen.tsx" + +let commonjs = "commonjs" + +let es6 = "es6" +let es6_global = "es6-global" + +let unused_attribute = "Unused attribute " + + + + + + + +(** Used when produce node compatible paths *) +let node_sep = "/" +let node_parent = ".." +let node_current = "." + +let gentype_import = "genType.import" + +let bsbuild_cache = ".bsbuild" + +let sourcedirs_meta = ".sourcedirs.json" + +(* Note the build system should check the validity of filenames + espeically, it should not contain '-' +*) +let ns_sep_char = '-' +let ns_sep = "-" +let exception_id = "RE_EXN_ID" + +let polyvar_hash = "NAME" +let polyvar_value = "VAL" + +let cons = "::" +let hd = "hd" +let tl = "tl" + +let lazy_done = "LAZY_DONE" +let lazy_val = "VAL" + +end +module Ext_namespace_encode : sig +#1 "ext_namespace_encode.mli" +(* Copyright (C) 2020- Authors of BuckleScript + * + * 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 + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a later version). + * + * This program is distributed in the hope that it will be useful, + * 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. *) + +(** [make ~ns:"Ns" "a" ] + A typical example would return "a-Ns" + Note the namespace comes from the output of [namespace_of_package_name] +*) +val make : + ?ns:string -> string -> string + +end = struct +#1 "ext_namespace_encode.ml" +(* Copyright (C) 2020- Authors of BuckleScript + * + * 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 + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a later version). + * + * This program is distributed in the hope that it will be useful, + * 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. *) + + let make ?ns cunit = + match ns with + | None -> cunit + | Some ns -> cunit ^ Literals.ns_sep ^ ns +end module Bs_hash_stubs = struct #1 "bs_hash_stubs.ml" @@ -8921,6 +9135,18 @@ val find_opt : string -> string option (** [find filename] Input is a file name, output is absolute path *) +(** given the input, calculate the output prefix + + in: src/hello.ast + out: src/hello + + with namespace: + in: src/hello.ast + out: src/hello-Ns +*) +val output_prefix : + string -> + string end = struct #1 "config_util.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. @@ -8972,6 +9198,14 @@ let find_opt file = find_in_path_uncap !Config.load_path file +let output_prefix name = + match !Clflags.output_name with + | None -> + Ext_namespace_encode.make + (Filename.remove_extension name) + ?ns:!Clflags.dont_record_crc_unit + | Some oname -> + Filename.remove_extension oname end @@ -69478,156 +69712,6 @@ let as_module ~basename = let name_len = String.length basename in search_dot (name_len - 1) basename name_len -end -module Literals -= struct -#1 "literals.ml" -(* 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 - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * 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. *) - - - - - - - -let js_array_ctor = "Array" -let js_type_number = "number" -let js_type_string = "string" -let js_type_object = "object" -let js_type_boolean = "boolean" -let js_undefined = "undefined" -let js_prop_length = "length" - -let prim = "prim" -let param = "param" -let partial_arg = "partial_arg" -let tmp = "tmp" - -let create = "create" (* {!Caml_exceptions.create}*) - -let runtime = "runtime" (* runtime directory *) - -let stdlib = "stdlib" - -let imul = "imul" (* signed int32 mul *) - -let setter_suffix = "#=" -let setter_suffix_len = String.length setter_suffix - -let debugger = "debugger" -let unsafe_downgrade = "unsafe_downgrade" -let fn_run = "fn_run" -let method_run = "method_run" - -let fn_method = "fn_method" -let fn_mk = "fn_mk" -(*let js_fn_runmethod = "js_fn_runmethod"*) - - - - - -(** nodejs *) -let node_modules = "node_modules" -let node_modules_length = String.length "node_modules" -let package_json = "package.json" -let bsconfig_json = "bsconfig.json" -let build_ninja = "build.ninja" - -(* Name of the library file created for each external dependency. *) -let library_file = "lib" - -let suffix_a = ".a" -let suffix_cmj = ".cmj" -let suffix_cmo = ".cmo" -let suffix_cma = ".cma" -let suffix_cmi = ".cmi" -let suffix_cmx = ".cmx" -let suffix_cmxa = ".cmxa" -let suffix_mll = ".mll" -let suffix_ml = ".ml" -let suffix_mli = ".mli" -let suffix_re = ".re" -let suffix_rei = ".rei" -let suffix_res = ".res" -let suffix_resi = ".resi" -let suffix_mlmap = ".mlmap" - -let suffix_cmt = ".cmt" -let suffix_cmti = ".cmti" -let suffix_ast = ".ast" -let suffix_iast = ".iast" -let suffix_d = ".d" -let suffix_js = ".js" -let suffix_bs_js = ".bs.js" -let suffix_mjs = ".mjs" -let suffix_cjs = ".cjs" -let suffix_gen_js = ".gen.js" -let suffix_gen_tsx = ".gen.tsx" - -let commonjs = "commonjs" - -let es6 = "es6" -let es6_global = "es6-global" - -let unused_attribute = "Unused attribute " - - - - - - - -(** Used when produce node compatible paths *) -let node_sep = "/" -let node_parent = ".." -let node_current = "." - -let gentype_import = "genType.import" - -let bsbuild_cache = ".bsbuild" - -let sourcedirs_meta = ".sourcedirs.json" - -(* Note the build system should check the validity of filenames - espeically, it should not contain '-' -*) -let ns_sep_char = '-' -let ns_sep = "-" -let exception_id = "RE_EXN_ID" - -let polyvar_hash = "NAME" -let polyvar_value = "VAL" - -let cons = "::" -let hd = "hd" -let tl = "tl" - -let lazy_done = "LAZY_DONE" -let lazy_val = "VAL" - end module Ext_js_suffix = struct @@ -406902,7 +406986,7 @@ let handle_extension record_as_js_object e (self : Bs_ast_mapper.mapper) let loc_start = loc.loc_start in let (file, lnum, __) = Location.get_pos_info loc_start in Printf.sprintf "%s %d" - file lnum in + (Filename.basename file) lnum in let e = self.expr self e in Exp.sequence ~loc (Ast_compatible.app1 ~loc diff --git a/lib/4.06.1/unstable/js_compiler.ml.d b/lib/4.06.1/unstable/js_compiler.ml.d index 4d8d2d55b1..2a638f27bc 100644 --- a/lib/4.06.1/unstable/js_compiler.ml.d +++ b/lib/4.06.1/unstable/js_compiler.ml.d @@ -367,6 +367,8 @@ ../lib/4.06.1/unstable/js_compiler.ml: ./ext/ext_modulename.mli ../lib/4.06.1/unstable/js_compiler.ml: ./ext/ext_namespace.ml ../lib/4.06.1/unstable/js_compiler.ml: ./ext/ext_namespace.mli +../lib/4.06.1/unstable/js_compiler.ml: ./ext/ext_namespace_encode.ml +../lib/4.06.1/unstable/js_compiler.ml: ./ext/ext_namespace_encode.mli ../lib/4.06.1/unstable/js_compiler.ml: ./ext/ext_option.ml ../lib/4.06.1/unstable/js_compiler.ml: ./ext/ext_option.mli ../lib/4.06.1/unstable/js_compiler.ml: ./ext/ext_path.ml diff --git a/lib/4.06.1/unstable/js_refmt_compiler.ml b/lib/4.06.1/unstable/js_refmt_compiler.ml index ff66e15022..a29bae2899 100644 --- a/lib/4.06.1/unstable/js_refmt_compiler.ml +++ b/lib/4.06.1/unstable/js_refmt_compiler.ml @@ -8057,6 +8057,220 @@ let () = ) end +module Literals += struct +#1 "literals.ml" +(* 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 + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a later version). + * + * This program is distributed in the hope that it will be useful, + * 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. *) + + + + + + + +let js_array_ctor = "Array" +let js_type_number = "number" +let js_type_string = "string" +let js_type_object = "object" +let js_type_boolean = "boolean" +let js_undefined = "undefined" +let js_prop_length = "length" + +let prim = "prim" +let param = "param" +let partial_arg = "partial_arg" +let tmp = "tmp" + +let create = "create" (* {!Caml_exceptions.create}*) + +let runtime = "runtime" (* runtime directory *) + +let stdlib = "stdlib" + +let imul = "imul" (* signed int32 mul *) + +let setter_suffix = "#=" +let setter_suffix_len = String.length setter_suffix + +let debugger = "debugger" +let unsafe_downgrade = "unsafe_downgrade" +let fn_run = "fn_run" +let method_run = "method_run" + +let fn_method = "fn_method" +let fn_mk = "fn_mk" +(*let js_fn_runmethod = "js_fn_runmethod"*) + + + + + +(** nodejs *) +let node_modules = "node_modules" +let node_modules_length = String.length "node_modules" +let package_json = "package.json" +let bsconfig_json = "bsconfig.json" +let build_ninja = "build.ninja" + +(* Name of the library file created for each external dependency. *) +let library_file = "lib" + +let suffix_a = ".a" +let suffix_cmj = ".cmj" +let suffix_cmo = ".cmo" +let suffix_cma = ".cma" +let suffix_cmi = ".cmi" +let suffix_cmx = ".cmx" +let suffix_cmxa = ".cmxa" +let suffix_mll = ".mll" +let suffix_ml = ".ml" +let suffix_mli = ".mli" +let suffix_re = ".re" +let suffix_rei = ".rei" +let suffix_res = ".res" +let suffix_resi = ".resi" +let suffix_mlmap = ".mlmap" + +let suffix_cmt = ".cmt" +let suffix_cmti = ".cmti" +let suffix_ast = ".ast" +let suffix_iast = ".iast" +let suffix_d = ".d" +let suffix_js = ".js" +let suffix_bs_js = ".bs.js" +let suffix_mjs = ".mjs" +let suffix_cjs = ".cjs" +let suffix_gen_js = ".gen.js" +let suffix_gen_tsx = ".gen.tsx" + +let commonjs = "commonjs" + +let es6 = "es6" +let es6_global = "es6-global" + +let unused_attribute = "Unused attribute " + + + + + + + +(** Used when produce node compatible paths *) +let node_sep = "/" +let node_parent = ".." +let node_current = "." + +let gentype_import = "genType.import" + +let bsbuild_cache = ".bsbuild" + +let sourcedirs_meta = ".sourcedirs.json" + +(* Note the build system should check the validity of filenames + espeically, it should not contain '-' +*) +let ns_sep_char = '-' +let ns_sep = "-" +let exception_id = "RE_EXN_ID" + +let polyvar_hash = "NAME" +let polyvar_value = "VAL" + +let cons = "::" +let hd = "hd" +let tl = "tl" + +let lazy_done = "LAZY_DONE" +let lazy_val = "VAL" + +end +module Ext_namespace_encode : sig +#1 "ext_namespace_encode.mli" +(* Copyright (C) 2020- Authors of BuckleScript + * + * 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 + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a later version). + * + * This program is distributed in the hope that it will be useful, + * 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. *) + +(** [make ~ns:"Ns" "a" ] + A typical example would return "a-Ns" + Note the namespace comes from the output of [namespace_of_package_name] +*) +val make : + ?ns:string -> string -> string + +end = struct +#1 "ext_namespace_encode.ml" +(* Copyright (C) 2020- Authors of BuckleScript + * + * 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 + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a later version). + * + * This program is distributed in the hope that it will be useful, + * 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. *) + + let make ?ns cunit = + match ns with + | None -> cunit + | Some ns -> cunit ^ Literals.ns_sep ^ ns +end module Bs_hash_stubs = struct #1 "bs_hash_stubs.ml" @@ -8921,6 +9135,18 @@ val find_opt : string -> string option (** [find filename] Input is a file name, output is absolute path *) +(** given the input, calculate the output prefix + + in: src/hello.ast + out: src/hello + + with namespace: + in: src/hello.ast + out: src/hello-Ns +*) +val output_prefix : + string -> + string end = struct #1 "config_util.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. @@ -8972,6 +9198,14 @@ let find_opt file = find_in_path_uncap !Config.load_path file +let output_prefix name = + match !Clflags.output_name with + | None -> + Ext_namespace_encode.make + (Filename.remove_extension name) + ?ns:!Clflags.dont_record_crc_unit + | Some oname -> + Filename.remove_extension oname end @@ -69478,156 +69712,6 @@ let as_module ~basename = let name_len = String.length basename in search_dot (name_len - 1) basename name_len -end -module Literals -= struct -#1 "literals.ml" -(* 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 - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * 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. *) - - - - - - - -let js_array_ctor = "Array" -let js_type_number = "number" -let js_type_string = "string" -let js_type_object = "object" -let js_type_boolean = "boolean" -let js_undefined = "undefined" -let js_prop_length = "length" - -let prim = "prim" -let param = "param" -let partial_arg = "partial_arg" -let tmp = "tmp" - -let create = "create" (* {!Caml_exceptions.create}*) - -let runtime = "runtime" (* runtime directory *) - -let stdlib = "stdlib" - -let imul = "imul" (* signed int32 mul *) - -let setter_suffix = "#=" -let setter_suffix_len = String.length setter_suffix - -let debugger = "debugger" -let unsafe_downgrade = "unsafe_downgrade" -let fn_run = "fn_run" -let method_run = "method_run" - -let fn_method = "fn_method" -let fn_mk = "fn_mk" -(*let js_fn_runmethod = "js_fn_runmethod"*) - - - - - -(** nodejs *) -let node_modules = "node_modules" -let node_modules_length = String.length "node_modules" -let package_json = "package.json" -let bsconfig_json = "bsconfig.json" -let build_ninja = "build.ninja" - -(* Name of the library file created for each external dependency. *) -let library_file = "lib" - -let suffix_a = ".a" -let suffix_cmj = ".cmj" -let suffix_cmo = ".cmo" -let suffix_cma = ".cma" -let suffix_cmi = ".cmi" -let suffix_cmx = ".cmx" -let suffix_cmxa = ".cmxa" -let suffix_mll = ".mll" -let suffix_ml = ".ml" -let suffix_mli = ".mli" -let suffix_re = ".re" -let suffix_rei = ".rei" -let suffix_res = ".res" -let suffix_resi = ".resi" -let suffix_mlmap = ".mlmap" - -let suffix_cmt = ".cmt" -let suffix_cmti = ".cmti" -let suffix_ast = ".ast" -let suffix_iast = ".iast" -let suffix_d = ".d" -let suffix_js = ".js" -let suffix_bs_js = ".bs.js" -let suffix_mjs = ".mjs" -let suffix_cjs = ".cjs" -let suffix_gen_js = ".gen.js" -let suffix_gen_tsx = ".gen.tsx" - -let commonjs = "commonjs" - -let es6 = "es6" -let es6_global = "es6-global" - -let unused_attribute = "Unused attribute " - - - - - - - -(** Used when produce node compatible paths *) -let node_sep = "/" -let node_parent = ".." -let node_current = "." - -let gentype_import = "genType.import" - -let bsbuild_cache = ".bsbuild" - -let sourcedirs_meta = ".sourcedirs.json" - -(* Note the build system should check the validity of filenames - espeically, it should not contain '-' -*) -let ns_sep_char = '-' -let ns_sep = "-" -let exception_id = "RE_EXN_ID" - -let polyvar_hash = "NAME" -let polyvar_value = "VAL" - -let cons = "::" -let hd = "hd" -let tl = "tl" - -let lazy_done = "LAZY_DONE" -let lazy_val = "VAL" - end module Ext_js_suffix = struct @@ -406902,7 +406986,7 @@ let handle_extension record_as_js_object e (self : Bs_ast_mapper.mapper) let loc_start = loc.loc_start in let (file, lnum, __) = Location.get_pos_info loc_start in Printf.sprintf "%s %d" - file lnum in + (Filename.basename file) lnum in let e = self.expr self e in Exp.sequence ~loc (Ast_compatible.app1 ~loc diff --git a/lib/4.06.1/unstable/js_refmt_compiler.ml.d b/lib/4.06.1/unstable/js_refmt_compiler.ml.d index 18963c7ffd..bc8b3539bb 100644 --- a/lib/4.06.1/unstable/js_refmt_compiler.ml.d +++ b/lib/4.06.1/unstable/js_refmt_compiler.ml.d @@ -369,6 +369,8 @@ ../lib/4.06.1/unstable/js_refmt_compiler.ml: ./ext/ext_modulename.mli ../lib/4.06.1/unstable/js_refmt_compiler.ml: ./ext/ext_namespace.ml ../lib/4.06.1/unstable/js_refmt_compiler.ml: ./ext/ext_namespace.mli +../lib/4.06.1/unstable/js_refmt_compiler.ml: ./ext/ext_namespace_encode.ml +../lib/4.06.1/unstable/js_refmt_compiler.ml: ./ext/ext_namespace_encode.mli ../lib/4.06.1/unstable/js_refmt_compiler.ml: ./ext/ext_option.ml ../lib/4.06.1/unstable/js_refmt_compiler.ml: ./ext/ext_option.mli ../lib/4.06.1/unstable/js_refmt_compiler.ml: ./ext/ext_path.ml diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index 041b414fc0..65583a33fe 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -4344,7 +4344,7 @@ let absolute_path s = (* This function could go into Filename *) let show_filename file = let file = if file = "_none_" then !input_name else file in - if true then absolute_path file else file + if !absname then absolute_path file else file let print_filename ppf file = Format.fprintf ppf "%s" (show_filename file) @@ -297500,6 +297500,220 @@ let () = ) end +module Literals += struct +#1 "literals.ml" +(* 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 + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a later version). + * + * This program is distributed in the hope that it will be useful, + * 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. *) + + + + + + + +let js_array_ctor = "Array" +let js_type_number = "number" +let js_type_string = "string" +let js_type_object = "object" +let js_type_boolean = "boolean" +let js_undefined = "undefined" +let js_prop_length = "length" + +let prim = "prim" +let param = "param" +let partial_arg = "partial_arg" +let tmp = "tmp" + +let create = "create" (* {!Caml_exceptions.create}*) + +let runtime = "runtime" (* runtime directory *) + +let stdlib = "stdlib" + +let imul = "imul" (* signed int32 mul *) + +let setter_suffix = "#=" +let setter_suffix_len = String.length setter_suffix + +let debugger = "debugger" +let unsafe_downgrade = "unsafe_downgrade" +let fn_run = "fn_run" +let method_run = "method_run" + +let fn_method = "fn_method" +let fn_mk = "fn_mk" +(*let js_fn_runmethod = "js_fn_runmethod"*) + + + + + +(** nodejs *) +let node_modules = "node_modules" +let node_modules_length = String.length "node_modules" +let package_json = "package.json" +let bsconfig_json = "bsconfig.json" +let build_ninja = "build.ninja" + +(* Name of the library file created for each external dependency. *) +let library_file = "lib" + +let suffix_a = ".a" +let suffix_cmj = ".cmj" +let suffix_cmo = ".cmo" +let suffix_cma = ".cma" +let suffix_cmi = ".cmi" +let suffix_cmx = ".cmx" +let suffix_cmxa = ".cmxa" +let suffix_mll = ".mll" +let suffix_ml = ".ml" +let suffix_mli = ".mli" +let suffix_re = ".re" +let suffix_rei = ".rei" +let suffix_res = ".res" +let suffix_resi = ".resi" +let suffix_mlmap = ".mlmap" + +let suffix_cmt = ".cmt" +let suffix_cmti = ".cmti" +let suffix_ast = ".ast" +let suffix_iast = ".iast" +let suffix_d = ".d" +let suffix_js = ".js" +let suffix_bs_js = ".bs.js" +let suffix_mjs = ".mjs" +let suffix_cjs = ".cjs" +let suffix_gen_js = ".gen.js" +let suffix_gen_tsx = ".gen.tsx" + +let commonjs = "commonjs" + +let es6 = "es6" +let es6_global = "es6-global" + +let unused_attribute = "Unused attribute " + + + + + + + +(** Used when produce node compatible paths *) +let node_sep = "/" +let node_parent = ".." +let node_current = "." + +let gentype_import = "genType.import" + +let bsbuild_cache = ".bsbuild" + +let sourcedirs_meta = ".sourcedirs.json" + +(* Note the build system should check the validity of filenames + espeically, it should not contain '-' +*) +let ns_sep_char = '-' +let ns_sep = "-" +let exception_id = "RE_EXN_ID" + +let polyvar_hash = "NAME" +let polyvar_value = "VAL" + +let cons = "::" +let hd = "hd" +let tl = "tl" + +let lazy_done = "LAZY_DONE" +let lazy_val = "VAL" + +end +module Ext_namespace_encode : sig +#1 "ext_namespace_encode.mli" +(* Copyright (C) 2020- Authors of BuckleScript + * + * 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 + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a later version). + * + * This program is distributed in the hope that it will be useful, + * 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. *) + +(** [make ~ns:"Ns" "a" ] + A typical example would return "a-Ns" + Note the namespace comes from the output of [namespace_of_package_name] +*) +val make : + ?ns:string -> string -> string + +end = struct +#1 "ext_namespace_encode.ml" +(* Copyright (C) 2020- Authors of BuckleScript + * + * 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 + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a later version). + * + * This program is distributed in the hope that it will be useful, + * 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. *) + + let make ?ns cunit = + match ns with + | None -> cunit + | Some ns -> cunit ^ Literals.ns_sep ^ ns +end module Config_util : sig #1 "config_util.mli" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. @@ -297542,6 +297756,18 @@ val find_opt : string -> string option (** [find filename] Input is a file name, output is absolute path *) +(** given the input, calculate the output prefix + + in: src/hello.ast + out: src/hello + + with namespace: + in: src/hello.ast + out: src/hello-Ns +*) +val output_prefix : + string -> + string end = struct #1 "config_util.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. @@ -297593,6 +297819,14 @@ let find_opt file = find_in_path_uncap !Config.load_path file +let output_prefix name = + match !Clflags.output_name with + | None -> + Ext_namespace_encode.make + (Filename.remove_extension name) + ?ns:!Clflags.dont_record_crc_unit + | Some oname -> + Filename.remove_extension oname end @@ -353410,156 +353644,6 @@ let add_int_4 (b : t ) (x : int ) = -end -module Literals -= struct -#1 "literals.ml" -(* 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 - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * 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. *) - - - - - - - -let js_array_ctor = "Array" -let js_type_number = "number" -let js_type_string = "string" -let js_type_object = "object" -let js_type_boolean = "boolean" -let js_undefined = "undefined" -let js_prop_length = "length" - -let prim = "prim" -let param = "param" -let partial_arg = "partial_arg" -let tmp = "tmp" - -let create = "create" (* {!Caml_exceptions.create}*) - -let runtime = "runtime" (* runtime directory *) - -let stdlib = "stdlib" - -let imul = "imul" (* signed int32 mul *) - -let setter_suffix = "#=" -let setter_suffix_len = String.length setter_suffix - -let debugger = "debugger" -let unsafe_downgrade = "unsafe_downgrade" -let fn_run = "fn_run" -let method_run = "method_run" - -let fn_method = "fn_method" -let fn_mk = "fn_mk" -(*let js_fn_runmethod = "js_fn_runmethod"*) - - - - - -(** nodejs *) -let node_modules = "node_modules" -let node_modules_length = String.length "node_modules" -let package_json = "package.json" -let bsconfig_json = "bsconfig.json" -let build_ninja = "build.ninja" - -(* Name of the library file created for each external dependency. *) -let library_file = "lib" - -let suffix_a = ".a" -let suffix_cmj = ".cmj" -let suffix_cmo = ".cmo" -let suffix_cma = ".cma" -let suffix_cmi = ".cmi" -let suffix_cmx = ".cmx" -let suffix_cmxa = ".cmxa" -let suffix_mll = ".mll" -let suffix_ml = ".ml" -let suffix_mli = ".mli" -let suffix_re = ".re" -let suffix_rei = ".rei" -let suffix_res = ".res" -let suffix_resi = ".resi" -let suffix_mlmap = ".mlmap" - -let suffix_cmt = ".cmt" -let suffix_cmti = ".cmti" -let suffix_ast = ".ast" -let suffix_iast = ".iast" -let suffix_d = ".d" -let suffix_js = ".js" -let suffix_bs_js = ".bs.js" -let suffix_mjs = ".mjs" -let suffix_cjs = ".cjs" -let suffix_gen_js = ".gen.js" -let suffix_gen_tsx = ".gen.tsx" - -let commonjs = "commonjs" - -let es6 = "es6" -let es6_global = "es6-global" - -let unused_attribute = "Unused attribute " - - - - - - - -(** Used when produce node compatible paths *) -let node_sep = "/" -let node_parent = ".." -let node_current = "." - -let gentype_import = "genType.import" - -let bsbuild_cache = ".bsbuild" - -let sourcedirs_meta = ".sourcedirs.json" - -(* Note the build system should check the validity of filenames - espeically, it should not contain '-' -*) -let ns_sep_char = '-' -let ns_sep = "-" -let exception_id = "RE_EXN_ID" - -let polyvar_hash = "NAME" -let polyvar_value = "VAL" - -let cons = "::" -let hd = "hd" -let tl = "tl" - -let lazy_done = "LAZY_DONE" -let lazy_val = "VAL" - end module Ext_js_suffix = struct @@ -366102,9 +366186,32 @@ let write_file f content = end end -module Ext_namespace_encode : sig -#1 "ext_namespace_encode.mli" -(* Copyright (C) 2020- Authors of BuckleScript +module Ext_fmt += struct +#1 "ext_fmt.ml" + + +let with_file_as_pp filename f = + Ext_pervasives.finally (open_out_bin filename) ~clean:close_out + (fun chan -> + let fmt = Format.formatter_of_out_channel chan in + let v = f fmt in + Format.pp_print_flush fmt (); + v + ) + + + +let failwithf ~loc fmt = Format.ksprintf (fun s -> failwith (loc ^ s)) + fmt + +let invalid_argf fmt = Format.ksprintf invalid_arg fmt + + +end +module Ext_sys : sig +#1 "ext_sys.mli" +(* 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 @@ -366128,16 +366235,156 @@ module Ext_namespace_encode : sig * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(** [make ~ns:"Ns" "a" ] - A typical example would return "a-Ns" - Note the namespace comes from the output of [namespace_of_package_name] + + +val is_directory_no_exn : string -> bool + + +val is_windows_or_cygwin : bool + + +end = struct +#1 "ext_sys.ml" +(* 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 + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a later version). + * + * This program is distributed in the hope that it will be useful, + * 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. *) + +(** TODO: not exported yet, wait for Windows Fix*) +let is_directory_no_exn f = + try Sys.is_directory f with _ -> false + + +let is_windows_or_cygwin = Sys.win32 || Sys.cygwin + + + +end +module Ext_path : sig +#1 "ext_path.mli" +(* Copyright (C) 2017 Authors of BuckleScript + * + * 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 + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a later version). + * + * This program is distributed in the hope that it will be useful, + * 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. *) + +type t + + +(** Js_output is node style, which means + separator is only '/' + + if the path contains 'node_modules', + [node_relative_path] will discard its prefix and + just treat it as a library instead *) -val make : - ?ns:string -> string -> string - +val simple_convert_node_path_to_os_path : string -> string + + + +(** + [combine path1 path2] + 1. add some simplifications when concatenating + 2. when [path2] is absolute, return [path2] +*) +val combine : + string -> + string -> + string + + + +(** + {[ + get_extension "a.txt" = ".txt" + get_extension "a" = "" + ]} +*) + + + + + +val node_rebase_file : + from:string -> + to_:string -> + string -> + string + +(** + TODO: could be highly optimized + if [from] and [to] resolve to the same path, a zero-length string is returned + Given that two paths are directory + + A typical use case is + {[ + Filename.concat + (rel_normalized_absolute_path cwd (Filename.dirname a)) + (Filename.basename a) + ]} +*) +val rel_normalized_absolute_path : from:string -> string -> string + + +val normalize_absolute_path : string -> string + + +val absolute_cwd_path : string -> string + +(** [concat dirname filename] + The same as {!Filename.concat} except a tiny optimization + for current directory simplification +*) +val concat : string -> string -> string + +val check_suffix_case : + string -> string -> bool + + + +(* It is lazy so that it will not hit errors when in script mode *) +val package_dir : string Lazy.t + end = struct -#1 "ext_namespace_encode.ml" -(* Copyright (C) 2020- Authors of BuckleScript +#1 "ext_path.ml" +(* Copyright (C) 2017 Authors of BuckleScript * * 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 @@ -366161,10 +366408,308 @@ end = struct * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - let make ?ns cunit = - match ns with - | None -> cunit - | Some ns -> cunit ^ Literals.ns_sep ^ ns +(* [@@@warning "-37"] *) +type t = + (* | File of string *) + | Dir of string +[@@unboxed] + +let simple_convert_node_path_to_os_path = + if Sys.unix then fun x -> x + else if Sys.win32 || Sys.cygwin then + Ext_string.replace_slash_backward + else failwith ("Unknown OS : " ^ Sys.os_type) + + +let cwd = lazy (Sys.getcwd()) + +let split_by_sep_per_os : string -> string list = + if Ext_sys.is_windows_or_cygwin then + fun x -> + (* on Windows, we can still accept -bs-package-output lib/js *) + Ext_string.split_by + (fun x -> match x with |'/' |'\\' -> true | _ -> false) x + else + fun x -> Ext_string.split x '/' + +(** example + {[ + "/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib/external/pervasives.cmj" + "/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib/ocaml_array.ml" + ]} + + The other way + {[ + + "/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib/ocaml_array.ml" + "/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib/external/pervasives.cmj" + ]} + {[ + "/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib//ocaml_array.ml" + ]} + {[ + /a/b + /c/d + ]} +*) +let node_relative_path + ~from:(file_or_dir_2 : t ) + (file_or_dir_1 : t) + = + let relevant_dir1 = + match file_or_dir_1 with + | Dir x -> x + (* | File file1 -> Filename.dirname file1 *) in + let relevant_dir2 = + match file_or_dir_2 with + | Dir x -> x + (* | File file2 -> Filename.dirname file2 *) in + let dir1 = split_by_sep_per_os relevant_dir1 in + let dir2 = split_by_sep_per_os relevant_dir2 in + let rec go (dir1 : string list) (dir2 : string list) = + match dir1, dir2 with + | "." :: xs, ys -> go xs ys + | xs , "." :: ys -> go xs ys + | x::xs , y :: ys when x = y + -> go xs ys + | _, _ -> + Ext_list.map_append dir2 dir1 (fun _ -> Literals.node_parent) + in + match go dir1 dir2 with + | (x :: _ ) as ys when x = Literals.node_parent -> + String.concat Literals.node_sep ys + | ys -> + String.concat Literals.node_sep + @@ Literals.node_current :: ys + + +let node_concat ~dir base = + dir ^ Literals.node_sep ^ base + +let node_rebase_file ~from ~to_ file = + + node_concat + ~dir:( + if from = to_ then Literals.node_current + else node_relative_path ~from:(Dir from) (Dir to_)) + file + + +(*** + {[ + Filename.concat "." "";; + "./" + ]} +*) +let combine path1 path2 = + if Filename.is_relative path2 then + if Ext_string.is_empty path2 then + path1 + else + if path1 = Filename.current_dir_name then + path2 + else + if path2 = Filename.current_dir_name + then path1 + else + Filename.concat path1 path2 + else + path2 + + + + + + + + +let (//) x y = + if x = Filename.current_dir_name then y + else if y = Filename.current_dir_name then x + else Filename.concat x y + +(** + {[ + split_aux "//ghosg//ghsogh/";; + - : string * string list = ("/", ["ghosg"; "ghsogh"]) + ]} + Note that + {[ + Filename.dirname "/a/" = "/" + Filename.dirname "/a/b/" = Filename.dirname "/a/b" = "/a" + ]} + Special case: + {[ + basename "//" = "/" + basename "///" = "/" + ]} + {[ + basename "" = "." + basename "" = "." + dirname "" = "." + dirname "" = "." + ]} +*) +let split_aux p = + let rec go p acc = + let dir = Filename.dirname p in + if dir = p then dir, acc + else + let new_path = Filename.basename p in + if Ext_string.equal new_path Filename.dir_sep then + go dir acc + (* We could do more path simplification here + leave to [rel_normalized_absolute_path] + *) + else + go dir (new_path :: acc) + + in go p [] + + + + + +(** + TODO: optimization + if [from] and [to] resolve to the same path, a zero-length string is returned + + This function is useed in [es6-global] and + [amdjs-global] format and tailored for `rollup` +*) +let rel_normalized_absolute_path ~from to_ = + let root1, paths1 = split_aux from in + let root2, paths2 = split_aux to_ in + if root1 <> root2 then root2 + else + let rec go xss yss = + match xss, yss with + | x::xs, y::ys -> + if Ext_string.equal x y then go xs ys + else if x = Filename.current_dir_name then go xs yss + else if y = Filename.current_dir_name then go xss ys + else + let start = + Ext_list.fold_left xs Ext_string.parent_dir_lit (fun acc _ -> acc // Ext_string.parent_dir_lit ) + in + Ext_list.fold_left yss start (fun acc v -> acc // v) + | [], [] -> Ext_string.empty + | [], y::ys -> Ext_list.fold_left ys y (fun acc x -> acc // x) + | _::xs, [] -> + Ext_list.fold_left xs Ext_string.parent_dir_lit (fun acc _ -> acc // Ext_string.parent_dir_lit ) + in + let v = go paths1 paths2 in + + if Ext_string.is_empty v then Literals.node_current + else + if + v = "." + || v = ".." + || Ext_string.starts_with v "./" + || Ext_string.starts_with v "../" + then v + else "./" ^ v + +(*TODO: could be hgighly optimized later + {[ + normalize_absolute_path "/gsho/./..";; + + normalize_absolute_path "/a/b/../c../d/e/f";; + + normalize_absolute_path "/gsho/./..";; + + normalize_absolute_path "/gsho/./../..";; + + normalize_absolute_path "/a/b/c/d";; + + normalize_absolute_path "/a/b/c/d/";; + + normalize_absolute_path "/a/";; + + normalize_absolute_path "/a";; + ]} +*) +(** See tests in {!Ounit_path_tests} *) +let normalize_absolute_path x = + let drop_if_exist xs = + match xs with + | [] -> [] + | _ :: xs -> xs in + let rec normalize_list acc paths = + match paths with + | [] -> acc + | x :: xs -> + if Ext_string.equal x Ext_string.current_dir_lit then + normalize_list acc xs + else if Ext_string.equal x Ext_string.parent_dir_lit then + normalize_list (drop_if_exist acc ) xs + else + normalize_list (x::acc) xs + in + let root, paths = split_aux x in + let rev_paths = normalize_list [] paths in + let rec go acc rev_paths = + match rev_paths with + | [] -> Filename.concat root acc + | last::rest -> go (Filename.concat last acc ) rest in + match rev_paths with + | [] -> root + | last :: rest -> go last rest + + + + +let absolute_path cwd s = + let process s = + let s = + if Filename.is_relative s then + Lazy.force cwd // s + else s in + (* Now simplify . and .. components *) + let rec aux s = + let base,dir = Filename.basename s, Filename.dirname s in + if dir = s then dir + else if base = Filename.current_dir_name then aux dir + else if base = Filename.parent_dir_name then Filename.dirname (aux dir) + else aux dir // base + in aux s in + process s + +let absolute_cwd_path s = + absolute_path cwd s + +(* let absolute cwd s = + match s with + | File x -> File (absolute_path cwd x ) + | Dir x -> Dir (absolute_path cwd x) *) + +let concat dirname filename = + if filename = Filename.current_dir_name then dirname + else if dirname = Filename.current_dir_name then filename + else Filename.concat dirname filename + + +let check_suffix_case = + Ext_string.ends_with + +(* Input must be absolute directory *) +let rec find_root_filename ~cwd filename = + if Sys.file_exists ( Filename.concat cwd filename) then cwd + else + let cwd' = Filename.dirname cwd in + if String.length cwd' < String.length cwd then + find_root_filename ~cwd:cwd' filename + else + Ext_fmt.failwithf + ~loc:__LOC__ + "%s not found from %s" filename cwd + + +let find_package_json_dir cwd = + find_root_filename ~cwd Literals.bsconfig_json + +let package_dir = lazy (find_package_json_dir (Lazy.force cwd)) + end module Depend : sig #1 "depend.mli" @@ -374565,697 +375110,172 @@ end = struct -type env_value = - | Ml of Js_cmj_format.cmj_load_info - | External -(** Also a js file, but this belong to third party - we never load runtime/*.cmj -*) - - - - -type ident_info = Js_cmj_format.keyed_cmj_value = { - name : string; - arity : Js_cmj_format.arity; - persistent_closed_lambda : Lam.t option -} - -(* - refer: [Env.find_pers_struct] - [ find_in_path_uncap !load_path (name ^ ".cmi")] -*) - - -(** It stores module => env_value mapping -*) -let cached_tbl : env_value Lam_module_ident.Hash.t - = Lam_module_ident.Hash.create 31 - -let (+>) = Lam_module_ident.Hash.add cached_tbl - - -(* For each compilation we need reset to make it re-entrant *) -let reset () = - Translmod.reset (); - Js_config.no_export := false; - (* This is needed in the playground since one no_export can make it true - In the payground, it seems we need reset more states - *) - Lam_module_ident.Hash.clear cached_tbl - - - - - -(** We should not provide "#moduleid" as output - since when we print it in the end, it will - be escaped quite ugly -*) -let add_js_module - (hint_name : External_ffi_types.module_bind_name) - (module_name : string) default : Ident.t - = - let id = - Ident.create - (match hint_name with - | Phint_name hint_name -> - Ext_string.capitalize_ascii hint_name - (* make sure the module name is capitalized - TODO: maybe a warning if the user hint is not good - *) - | Phint_nothing -> - Ext_modulename.js_id_name_of_hint_name module_name - ) - in - let lam_module_ident : J.module_id = - {id ; kind = External {name = module_name; default}} in - match Lam_module_ident.Hash.find_key_opt cached_tbl lam_module_ident with - | None -> - lam_module_ident +> External; - id - | Some old_key -> - old_key.id - - - - - - -let query_external_id_info (module_id : Ident.t) (name : string) : ident_info = - let oid = Lam_module_ident.of_ml module_id in - let cmj_table = - match Lam_module_ident.Hash.find_opt cached_tbl oid with - | None -> - let cmj_load_info = - !Js_cmj_load.load_unit module_id.name in - oid +> Ml cmj_load_info ; - cmj_load_info.cmj_table - | Some (Ml { cmj_table } ) - -> cmj_table - | Some External -> assert false in - Js_cmj_format.query_by_name cmj_table name - - - - - - - - - - -let get_package_path_from_cmj - ( id : Lam_module_ident.t) : - string * Js_packages_info.t * Ext_js_file_kind.case - = - let cmj_load_info = - match Lam_module_ident.Hash.find_opt cached_tbl id with - | Some (Ml cmj_load_info) -> cmj_load_info - | Some External -> - assert false - (* called by {!Js_name_of_module_id.string_of_module_id} - can not be External - *) - | None -> - begin match id.kind with - | Runtime - | External _ -> assert false - | Ml -> - let cmj_load_info = - !Js_cmj_load.load_unit (Lam_module_ident.name id) in - id +> Ml cmj_load_info; - cmj_load_info - - end in - let cmj_table = cmj_load_info.cmj_table in - (cmj_load_info.package_path, - cmj_table.package_spec, - cmj_table.case - ) - -let add = Lam_module_ident.Hash_set.add - - - -(* Conservative interface *) -let is_pure_module (oid : Lam_module_ident.t) = - match oid.kind with - | Runtime -> true - | External _ -> false - | Ml -> - begin match Lam_module_ident.Hash.find_opt cached_tbl oid with - | None -> - begin - match !Js_cmj_load.load_unit (Lam_module_ident.name oid) with - | cmj_load_info -> - oid +> Ml cmj_load_info ; - cmj_load_info.cmj_table.pure - | exception _ -> false - end - | Some (Ml{cmj_table}) -> - cmj_table.pure - | Some External -> false - end - - -let populate_required_modules - extras - (hard_dependencies - : Lam_module_ident.Hash_set.t) = - Lam_module_ident.Hash.iter cached_tbl (fun id _ -> - if not (is_pure_module id) - then add hard_dependencies id); - Lam_module_ident.Hash_set.iter extras (fun id -> - (if not (is_pure_module id) - then add hard_dependencies id : unit) - ) - (* Lam_module_ident.Hash_set.elements hard_dependencies *) - -end -module Ext_fmt -= struct -#1 "ext_fmt.ml" - - -let with_file_as_pp filename f = - Ext_pervasives.finally (open_out_bin filename) ~clean:close_out - (fun chan -> - let fmt = Format.formatter_of_out_channel chan in - let v = f fmt in - Format.pp_print_flush fmt (); - v - ) - - - -let failwithf ~loc fmt = Format.ksprintf (fun s -> failwith (loc ^ s)) - fmt - -let invalid_argf fmt = Format.ksprintf invalid_arg fmt - - -end -module Ext_sys : sig -#1 "ext_sys.mli" -(* 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 - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * 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 is_directory_no_exn : string -> bool - - -val is_windows_or_cygwin : bool - - -end = struct -#1 "ext_sys.ml" -(* 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 - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * 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. *) - -(** TODO: not exported yet, wait for Windows Fix*) -let is_directory_no_exn f = - try Sys.is_directory f with _ -> false - - -let is_windows_or_cygwin = Sys.win32 || Sys.cygwin - - - -end -module Ext_path : sig -#1 "ext_path.mli" -(* Copyright (C) 2017 Authors of BuckleScript - * - * 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 - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * 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. *) - -type t - - -(** Js_output is node style, which means - separator is only '/' - - if the path contains 'node_modules', - [node_relative_path] will discard its prefix and - just treat it as a library instead -*) -val simple_convert_node_path_to_os_path : string -> string - - - -(** - [combine path1 path2] - 1. add some simplifications when concatenating - 2. when [path2] is absolute, return [path2] -*) -val combine : - string -> - string -> - string - - - -(** - {[ - get_extension "a.txt" = ".txt" - get_extension "a" = "" - ]} -*) - - - - - -val node_rebase_file : - from:string -> - to_:string -> - string -> - string - -(** - TODO: could be highly optimized - if [from] and [to] resolve to the same path, a zero-length string is returned - Given that two paths are directory - - A typical use case is - {[ - Filename.concat - (rel_normalized_absolute_path cwd (Filename.dirname a)) - (Filename.basename a) - ]} -*) -val rel_normalized_absolute_path : from:string -> string -> string - - -val normalize_absolute_path : string -> string - - -val absolute_cwd_path : string -> string - -(** [concat dirname filename] - The same as {!Filename.concat} except a tiny optimization - for current directory simplification -*) -val concat : string -> string -> string - -val check_suffix_case : - string -> string -> bool - - - -(* It is lazy so that it will not hit errors when in script mode *) -val package_dir : string Lazy.t - -end = struct -#1 "ext_path.ml" -(* Copyright (C) 2017 Authors of BuckleScript - * - * 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 - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * 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. *) - -(* [@@@warning "-37"] *) -type t = - (* | File of string *) - | Dir of string -[@@unboxed] - -let simple_convert_node_path_to_os_path = - if Sys.unix then fun x -> x - else if Sys.win32 || Sys.cygwin then - Ext_string.replace_slash_backward - else failwith ("Unknown OS : " ^ Sys.os_type) - - -let cwd = lazy (Sys.getcwd()) - -let split_by_sep_per_os : string -> string list = - if Ext_sys.is_windows_or_cygwin then - fun x -> - (* on Windows, we can still accept -bs-package-output lib/js *) - Ext_string.split_by - (fun x -> match x with |'/' |'\\' -> true | _ -> false) x - else - fun x -> Ext_string.split x '/' - -(** example - {[ - "/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib/external/pervasives.cmj" - "/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib/ocaml_array.ml" - ]} - - The other way - {[ - - "/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib/ocaml_array.ml" - "/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib/external/pervasives.cmj" - ]} - {[ - "/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib//ocaml_array.ml" - ]} - {[ - /a/b - /c/d - ]} -*) -let node_relative_path - ~from:(file_or_dir_2 : t ) - (file_or_dir_1 : t) - = - let relevant_dir1 = - match file_or_dir_1 with - | Dir x -> x - (* | File file1 -> Filename.dirname file1 *) in - let relevant_dir2 = - match file_or_dir_2 with - | Dir x -> x - (* | File file2 -> Filename.dirname file2 *) in - let dir1 = split_by_sep_per_os relevant_dir1 in - let dir2 = split_by_sep_per_os relevant_dir2 in - let rec go (dir1 : string list) (dir2 : string list) = - match dir1, dir2 with - | "." :: xs, ys -> go xs ys - | xs , "." :: ys -> go xs ys - | x::xs , y :: ys when x = y - -> go xs ys - | _, _ -> - Ext_list.map_append dir2 dir1 (fun _ -> Literals.node_parent) - in - match go dir1 dir2 with - | (x :: _ ) as ys when x = Literals.node_parent -> - String.concat Literals.node_sep ys - | ys -> - String.concat Literals.node_sep - @@ Literals.node_current :: ys - - -let node_concat ~dir base = - dir ^ Literals.node_sep ^ base - -let node_rebase_file ~from ~to_ file = - - node_concat - ~dir:( - if from = to_ then Literals.node_current - else node_relative_path ~from:(Dir from) (Dir to_)) - file - - -(*** - {[ - Filename.concat "." "";; - "./" - ]} +type env_value = + | Ml of Js_cmj_format.cmj_load_info + | External +(** Also a js file, but this belong to third party + we never load runtime/*.cmj *) -let combine path1 path2 = - if Filename.is_relative path2 then - if Ext_string.is_empty path2 then - path1 - else - if path1 = Filename.current_dir_name then - path2 - else - if path2 = Filename.current_dir_name - then path1 - else - Filename.concat path1 path2 - else - path2 - +type ident_info = Js_cmj_format.keyed_cmj_value = { + name : string; + arity : Js_cmj_format.arity; + persistent_closed_lambda : Lam.t option +} +(* + refer: [Env.find_pers_struct] + [ find_in_path_uncap !load_path (name ^ ".cmi")] +*) -let (//) x y = - if x = Filename.current_dir_name then y - else if y = Filename.current_dir_name then x - else Filename.concat x y - -(** - {[ - split_aux "//ghosg//ghsogh/";; - - : string * string list = ("/", ["ghosg"; "ghsogh"]) - ]} - Note that - {[ - Filename.dirname "/a/" = "/" - Filename.dirname "/a/b/" = Filename.dirname "/a/b" = "/a" - ]} - Special case: - {[ - basename "//" = "/" - basename "///" = "/" - ]} - {[ - basename "" = "." - basename "" = "." - dirname "" = "." - dirname "" = "." - ]} +(** It stores module => env_value mapping *) -let split_aux p = - let rec go p acc = - let dir = Filename.dirname p in - if dir = p then dir, acc - else - let new_path = Filename.basename p in - if Ext_string.equal new_path Filename.dir_sep then - go dir acc - (* We could do more path simplification here - leave to [rel_normalized_absolute_path] - *) - else - go dir (new_path :: acc) +let cached_tbl : env_value Lam_module_ident.Hash.t + = Lam_module_ident.Hash.create 31 - in go p [] +let (+>) = Lam_module_ident.Hash.add cached_tbl +(* For each compilation we need reset to make it re-entrant *) +let reset () = + Translmod.reset (); + Js_config.no_export := false; + (* This is needed in the playground since one no_export can make it true + In the payground, it seems we need reset more states + *) + Lam_module_ident.Hash.clear cached_tbl -(** - TODO: optimization - if [from] and [to] resolve to the same path, a zero-length string is returned - This function is useed in [es6-global] and - [amdjs-global] format and tailored for `rollup` + +(** We should not provide "#moduleid" as output + since when we print it in the end, it will + be escaped quite ugly *) -let rel_normalized_absolute_path ~from to_ = - let root1, paths1 = split_aux from in - let root2, paths2 = split_aux to_ in - if root1 <> root2 then root2 - else - let rec go xss yss = - match xss, yss with - | x::xs, y::ys -> - if Ext_string.equal x y then go xs ys - else if x = Filename.current_dir_name then go xs yss - else if y = Filename.current_dir_name then go xss ys - else - let start = - Ext_list.fold_left xs Ext_string.parent_dir_lit (fun acc _ -> acc // Ext_string.parent_dir_lit ) - in - Ext_list.fold_left yss start (fun acc v -> acc // v) - | [], [] -> Ext_string.empty - | [], y::ys -> Ext_list.fold_left ys y (fun acc x -> acc // x) - | _::xs, [] -> - Ext_list.fold_left xs Ext_string.parent_dir_lit (fun acc _ -> acc // Ext_string.parent_dir_lit ) - in - let v = go paths1 paths2 in +let add_js_module + (hint_name : External_ffi_types.module_bind_name) + (module_name : string) default : Ident.t + = + let id = + Ident.create + (match hint_name with + | Phint_name hint_name -> + Ext_string.capitalize_ascii hint_name + (* make sure the module name is capitalized + TODO: maybe a warning if the user hint is not good + *) + | Phint_nothing -> + Ext_modulename.js_id_name_of_hint_name module_name + ) + in + let lam_module_ident : J.module_id = + {id ; kind = External {name = module_name; default}} in + match Lam_module_ident.Hash.find_key_opt cached_tbl lam_module_ident with + | None -> + lam_module_ident +> External; + id + | Some old_key -> + old_key.id - if Ext_string.is_empty v then Literals.node_current - else - if - v = "." - || v = ".." - || Ext_string.starts_with v "./" - || Ext_string.starts_with v "../" - then v - else "./" ^ v -(*TODO: could be hgighly optimized later - {[ - normalize_absolute_path "/gsho/./..";; - normalize_absolute_path "/a/b/../c../d/e/f";; - normalize_absolute_path "/gsho/./..";; - normalize_absolute_path "/gsho/./../..";; - normalize_absolute_path "/a/b/c/d";; +let query_external_id_info (module_id : Ident.t) (name : string) : ident_info = + let oid = Lam_module_ident.of_ml module_id in + let cmj_table = + match Lam_module_ident.Hash.find_opt cached_tbl oid with + | None -> + let cmj_load_info = + !Js_cmj_load.load_unit module_id.name in + oid +> Ml cmj_load_info ; + cmj_load_info.cmj_table + | Some (Ml { cmj_table } ) + -> cmj_table + | Some External -> assert false in + Js_cmj_format.query_by_name cmj_table name - normalize_absolute_path "/a/b/c/d/";; - normalize_absolute_path "/a/";; - normalize_absolute_path "/a";; - ]} -*) -(** See tests in {!Ounit_path_tests} *) -let normalize_absolute_path x = - let drop_if_exist xs = - match xs with - | [] -> [] - | _ :: xs -> xs in - let rec normalize_list acc paths = - match paths with - | [] -> acc - | x :: xs -> - if Ext_string.equal x Ext_string.current_dir_lit then - normalize_list acc xs - else if Ext_string.equal x Ext_string.parent_dir_lit then - normalize_list (drop_if_exist acc ) xs - else - normalize_list (x::acc) xs - in - let root, paths = split_aux x in - let rev_paths = normalize_list [] paths in - let rec go acc rev_paths = - match rev_paths with - | [] -> Filename.concat root acc - | last::rest -> go (Filename.concat last acc ) rest in - match rev_paths with - | [] -> root - | last :: rest -> go last rest -let absolute_path cwd s = - let process s = - let s = - if Filename.is_relative s then - Lazy.force cwd // s - else s in - (* Now simplify . and .. components *) - let rec aux s = - let base,dir = Filename.basename s, Filename.dirname s in - if dir = s then dir - else if base = Filename.current_dir_name then aux dir - else if base = Filename.parent_dir_name then Filename.dirname (aux dir) - else aux dir // base - in aux s in - process s -let absolute_cwd_path s = - absolute_path cwd s -(* let absolute cwd s = - match s with - | File x -> File (absolute_path cwd x ) - | Dir x -> Dir (absolute_path cwd x) *) -let concat dirname filename = - if filename = Filename.current_dir_name then dirname - else if dirname = Filename.current_dir_name then filename - else Filename.concat dirname filename - +let get_package_path_from_cmj + ( id : Lam_module_ident.t) : + string * Js_packages_info.t * Ext_js_file_kind.case + = + let cmj_load_info = + match Lam_module_ident.Hash.find_opt cached_tbl id with + | Some (Ml cmj_load_info) -> cmj_load_info + | Some External -> + assert false + (* called by {!Js_name_of_module_id.string_of_module_id} + can not be External + *) + | None -> + begin match id.kind with + | Runtime + | External _ -> assert false + | Ml -> + let cmj_load_info = + !Js_cmj_load.load_unit (Lam_module_ident.name id) in + id +> Ml cmj_load_info; + cmj_load_info -let check_suffix_case = - Ext_string.ends_with + end in + let cmj_table = cmj_load_info.cmj_table in + (cmj_load_info.package_path, + cmj_table.package_spec, + cmj_table.case + ) -(* Input must be absolute directory *) -let rec find_root_filename ~cwd filename = - if Sys.file_exists ( Filename.concat cwd filename) then cwd - else - let cwd' = Filename.dirname cwd in - if String.length cwd' < String.length cwd then - find_root_filename ~cwd:cwd' filename - else - Ext_fmt.failwithf - ~loc:__LOC__ - "%s not found from %s" filename cwd +let add = Lam_module_ident.Hash_set.add -let find_package_json_dir cwd = - find_root_filename ~cwd Literals.bsconfig_json -let package_dir = lazy (find_package_json_dir (Lazy.force cwd)) +(* Conservative interface *) +let is_pure_module (oid : Lam_module_ident.t) = + match oid.kind with + | Runtime -> true + | External _ -> false + | Ml -> + begin match Lam_module_ident.Hash.find_opt cached_tbl oid with + | None -> + begin + match !Js_cmj_load.load_unit (Lam_module_ident.name oid) with + | cmj_load_info -> + oid +> Ml cmj_load_info ; + cmj_load_info.cmj_table.pure + | exception _ -> false + end + | Some (Ml{cmj_table}) -> + cmj_table.pure + | Some External -> false + end + + +let populate_required_modules + extras + (hard_dependencies + : Lam_module_ident.Hash_set.t) = + Lam_module_ident.Hash.iter cached_tbl (fun id _ -> + if not (is_pure_module id) + then add hard_dependencies id); + Lam_module_ident.Hash_set.iter extras (fun id -> + (if not (is_pure_module id) + then add hard_dependencies id : unit) + ) + (* Lam_module_ident.Hash_set.elements hard_dependencies *) end module Ext_pp : sig @@ -409795,7 +409815,7 @@ let handle_extension record_as_js_object e (self : Bs_ast_mapper.mapper) let loc_start = loc.loc_start in let (file, lnum, __) = Location.get_pos_info loc_start in Printf.sprintf "%s %d" - file lnum in + (Filename.basename file) lnum in let e = self.expr self e in Exp.sequence ~loc (Ast_compatible.app1 ~loc @@ -414191,13 +414211,12 @@ module Js_implementation : sig val interface : parser:(string -> Parsetree.signature) -> Format.formatter -> - string -> + ?outputprefix:string -> string -> unit val interface_mliast : Format.formatter -> - string -> string -> ([`ml | `rescript | `reason ] -> unit) -> unit @@ -414217,7 +414236,7 @@ val interface_mliast : val implementation : parser:(string -> Parsetree.structure) -> Format.formatter -> - string -> + ?outputprefix:string -> string -> unit (** [implementation ppf sourcefile outprefix] compiles to JS directly *) @@ -414225,11 +414244,11 @@ val implementation : val implementation_mlast : Format.formatter -> string -> - string -> ([`ml | `rescript | `reason ] -> unit) -> unit -val implementation_map : Format.formatter -> string -> string -> unit +val implementation_map : + Format.formatter -> string -> unit end = struct #1 "js_implementation.ml" (***********************************************************************) @@ -414336,7 +414355,11 @@ let after_parsing_sig ppf outputprefix ast = -let interface ~parser ppf fname outputprefix = +let interface ~parser ppf ?outputprefix fname = + let outputprefix = + match outputprefix with + | None -> Config_util.output_prefix fname + | Some x -> x in Res_compmisc.init_path (); parser fname |> Cmd_ppx_apply.apply_rewriters ~restore:false ~tool_name:Js_config.tool_name Mli @@ -414345,12 +414368,12 @@ let interface ~parser ppf fname outputprefix = |> print_if_pipe ppf Clflags.dump_source Pprintast.signature |> after_parsing_sig ppf outputprefix -let interface_mliast ppf fname outputprefix setup = +let interface_mliast ppf fname setup = Res_compmisc.init_path (); Binary_ast.read_ast_exn ~fname Mli setup |> print_if_pipe ppf Clflags.dump_parsetree Printast.interface |> print_if_pipe ppf Clflags.dump_source Pprintast.signature - |> after_parsing_sig ppf outputprefix + |> after_parsing_sig ppf (Config_util.output_prefix fname) let all_module_alias (ast : Parsetree.structure)= Ext_list.for_all ast (fun {pstr_desc} -> @@ -414430,7 +414453,11 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) = end; process_with_gentype (outputprefix ^ ".cmt") end -let implementation ~parser ppf fname outputprefix = +let implementation ~parser ppf ?outputprefix fname = + let outputprefix = + match outputprefix with + | None -> Config_util.output_prefix fname + | Some x -> x in Res_compmisc.init_path (); parser fname |> Cmd_ppx_apply.apply_rewriters ~restore:false ~tool_name:Js_config.tool_name Ml @@ -414439,12 +414466,13 @@ let implementation ~parser ppf fname outputprefix = |> print_if_pipe ppf Clflags.dump_source Pprintast.structure |> after_parsing_impl ppf outputprefix -let implementation_mlast ppf fname outputprefix setup = +let implementation_mlast ppf fname setup = + Res_compmisc.init_path (); Binary_ast.read_ast_exn ~fname Ml setup |> print_if_pipe ppf Clflags.dump_parsetree Printast.implementation |> print_if_pipe ppf Clflags.dump_source Pprintast.structure - |> after_parsing_impl ppf outputprefix + |> after_parsing_impl ppf (Config_util.output_prefix fname ) @@ -414466,7 +414494,7 @@ let make_structure_item ~ns cunit : Parsetree.structure_item = (** decoding [.mlmap] keep in sync {!Bsb_namespace_map_gen.output} *) -let implementation_map ppf sourcefile outputprefix = +let implementation_map ppf sourcefile = let () = Js_config.cmj_only := true in let ichan = open_in_bin sourcefile in seek_in ichan (Ext_digest.length +1); @@ -414481,7 +414509,7 @@ let implementation_map ppf sourcefile outputprefix = ml_ast |> print_if_pipe ppf Clflags.dump_parsetree Printast.implementation |> print_if_pipe ppf Clflags.dump_source Pprintast.structure - |> after_parsing_impl ppf outputprefix + |> after_parsing_impl ppf (Config_util.output_prefix sourcefile) end @@ -436137,16 +436165,14 @@ end = struct (* *) (***********************************************************************) -let output_prefix name = - match !Clflags.output_name with - | None -> - Ext_namespace_encode.make - (Filename.remove_extension name) - ?ns:!Clflags.dont_record_crc_unit - | Some oname -> - Filename.remove_extension oname - +let set_abs_input_name sourcefile = + let sourcefile = + if !Location.absname && Filename.is_relative sourcefile then + Ext_path.absolute_cwd_path sourcefile + else sourcefile in + Location.set_input_name sourcefile; + sourcefile let setup_error_printer (syntax_kind : [ `ml | `reason | `rescript ])= @@ -436163,9 +436189,10 @@ let setup_error_printer (syntax_kind : [ `ml | `reason | `rescript ])= -let handle_reason (type a) (kind : a Ml_binary.kind) sourcefile ppf opref = +let handle_reason (type a) (kind : a Ml_binary.kind) sourcefile ppf = setup_error_printer `reason; let tmpfile = Ast_reason_pp.pp sourcefile in + let outputprefix = Config_util.output_prefix sourcefile in (match kind with | Ml_binary.Ml -> Js_implementation.implementation @@ -436174,7 +436201,7 @@ let handle_reason (type a) (kind : a Ml_binary.kind) sourcefile ppf opref = let ast = Ml_binary.read_ast Ml in_chan in close_in in_chan; ast ) - ppf tmpfile opref + ppf tmpfile ~outputprefix | Ml_binary.Mli -> Js_implementation.interface @@ -436183,10 +436210,9 @@ let handle_reason (type a) (kind : a Ml_binary.kind) sourcefile ppf opref = let ast = Ml_binary.read_ast Mli in_chan in close_in in_chan; ast ) - ppf tmpfile opref ; ); + ppf tmpfile ~outputprefix ); Ast_reason_pp.clean tmpfile - let process_file sourcefile ?(kind ) ppf = @@ -436194,44 +436220,51 @@ let process_file sourcefile The {!Location.input_name} relies on that we write the binary ast properly *) - Location.set_input_name sourcefile; - let opref = output_prefix sourcefile in let kind = match kind with | None -> Ext_file_extensions.classify_input (Ext_filename.get_extension_maybe sourcefile) | Some kind -> kind in match kind with - | Re -> handle_reason Ml sourcefile ppf opref + | Re -> + let sourcefile = set_abs_input_name sourcefile in + handle_reason Ml sourcefile ppf | Rei -> - handle_reason Mli sourcefile ppf opref + let sourcefile = set_abs_input_name sourcefile in + handle_reason Mli sourcefile ppf | Ml -> + let sourcefile = set_abs_input_name sourcefile in Js_implementation.implementation ~parser:Pparse_driver.parse_implementation - ppf sourcefile opref + ppf sourcefile | Mli -> + let sourcefile = set_abs_input_name sourcefile in Js_implementation.interface ~parser:Pparse_driver.parse_interface - ppf sourcefile opref + ppf sourcefile | Res -> + let sourcefile = set_abs_input_name sourcefile in setup_error_printer `rescript; Js_implementation.implementation ~parser:Res_driver.parse_implementation - ppf sourcefile opref + ppf sourcefile | Resi -> + let sourcefile = set_abs_input_name sourcefile in setup_error_printer `rescript; Js_implementation.interface ~parser:Res_driver.parse_interface - ppf sourcefile opref + ppf sourcefile | Intf_ast -> - Js_implementation.interface_mliast ppf sourcefile opref + Js_implementation.interface_mliast ppf sourcefile setup_error_printer ; | Impl_ast -> - Js_implementation.implementation_mlast ppf sourcefile opref + Js_implementation.implementation_mlast ppf sourcefile setup_error_printer; | Mlmap - -> Js_implementation.implementation_map ppf sourcefile opref + -> + Location.set_input_name sourcefile; + Js_implementation.implementation_map ppf sourcefile | Cmi -> let cmi_sign = (Cmi_format.read_cmi sourcefile).cmi_sign in diff --git a/scripts/buckle_lto.js b/scripts/buckle_lto.js index 0e3ae12275..609ab3ca2e 100644 --- a/scripts/buckle_lto.js +++ b/scripts/buckle_lto.js @@ -12,7 +12,6 @@ var pairs = [ ["Clflags.no_implicit_current_dir", "true"], ["Clflags.strict_sequence", "true"], ["Clflags.strict_formats", "true"], - ["Location.absname", "true"], ["Clflags.compile_only", "true"], ["Clflags.recursive_types","false"] ]; diff --git a/scripts/ninja.js b/scripts/ninja.js index 2ff66d202a..cecfe7da46 100755 --- a/scripts/ninja.js +++ b/scripts/ninja.js @@ -22,7 +22,7 @@ var runtimeMliFiles = runtimeFiles.filter( var runtimeSourceFiles = runtimeMlFiles.concat(runtimeMliFiles); var runtimeJsFiles = [...new Set(runtimeSourceFiles.map(baseName))]; -var commonBsFlags = `-no-keep-locs -absname -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib `; +var commonBsFlags = `-no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib `; var js_package = pseudoTarget("js_pkg"); var runtimeTarget = pseudoTarget("runtime"); var othersTarget = pseudoTarget("others");