Skip to content

Commit 0af8c74

Browse files
committed
make stdlib configurable < part 1>
1 parent 0a3f4bb commit 0af8c74

21 files changed

+173
-95
lines changed

jscomp/bsb/bsb_config_parse.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
(* let get_list_string = Bsb_build_util.get_list_string *)
2727
let (//) = Ext_path.combine
28-
let current_package : Bsb_pkg_types.t = Global Bs_version.package_name
28+
2929
let resolve_package cwd package_name =
3030
let x = Bsb_pkg.resolve_bs_package ~cwd package_name in
3131
{
@@ -113,6 +113,7 @@ let check_stdlib (map : json_map) cwd (*built_in_package*) =
113113
| None
114114
| Some _ ->
115115
begin
116+
let current_package : Bsb_pkg_types.t = Global !Bs_version.package_name in
116117
if Sys.getenv_opt "RES_SKIP_STDLIB_CHECK" = None then begin
117118
let stdlib_path =
118119
Bsb_pkg.resolve_bs_package ~cwd current_package in

jscomp/bsb/bsb_exception.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ let print (fmt : Format.formatter) (x : error) =
5757
| None -> Ext_string.empty
5858
| Some x -> " in " ^ x in
5959
let name = Bsb_pkg_types.to_string name in
60-
if Ext_string.equal name Bs_version.package_name then
60+
if Ext_string.equal name !Bs_version.package_name then
6161
Format.fprintf fmt
6262
"File \"bsconfig.json\", line 1\n\
63-
@{<error>Error:@} package @{<error>bs-platform@} is not found %s\n\
63+
@{<error>Error:@} package @{<error>%s@} is not found %s\n\
6464
It's the basic, required package. If you have it installed globally,\n\
65-
Please run `npm link bs-platform` to make it available" in_json
65+
Please run `npm link bs-platform` to make it available" name in_json
6666
else
6767
Format.fprintf fmt
6868
"File \"bsconfig.json\", line 1\n\

jscomp/build_version.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fs.writeFileSync(
4242
let version = "${version}"
4343
let header =
4444
"// Generated by ReScript, PLEASE EDIT WITH CARE"
45-
let package_name = "${name}"
45+
let package_name = ref "${name}"
4646
`,
4747
"utf8"
4848
);

jscomp/common/bs_version.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
* You should have received a copy of the GNU Lesser General Public License
2323
* along with this program; if not, write to the Free Software
2424
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
25-
let version = "8.4.0"
25+
let version = "8.5.0"
2626
let header =
2727
"// Generated by ReScript, PLEASE EDIT WITH CARE"
28-
let package_name = "bs-platform"
28+
let package_name = ref "bs-platform"
2929

jscomp/common/bs_version.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ val version : string
2626

2727
val header : string
2828

29-
val package_name : string
29+
val package_name : string ref

jscomp/core/js_name_of_module_id.ml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ let fix_path_for_windows : string -> string =
3434
else fun s -> s
3535

3636

37+
(* dependency is runtime module *)
3738
let get_runtime_module_path
3839
(dep_module_id : Lam_module_ident.t)
3940
(current_package_info : Js_packages_info.t)

jscomp/core/js_packages_info.ml

+18-15
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type package_name =
5656

5757

5858

59-
let runtime_package_name = "bs-platform"
59+
6060

6161

6262
let (//) = Filename.concat
@@ -70,7 +70,7 @@ let runtime_dir_of_module_system (ms : module_system ) =
7070
let runtime_package_path
7171
(ms : module_system)
7272
js_file =
73-
runtime_package_name // "lib" // runtime_dir_of_module_system ms // js_file
73+
!Bs_version.package_name // "lib" // runtime_dir_of_module_system ms // js_file
7474

7575

7676
type t =
@@ -86,6 +86,14 @@ let runtime_package_specs : t = {
8686
{module_system = NodeJS; path = "lib/js"; suffix = Js};
8787
]
8888
}
89+
90+
(**
91+
populated by the command line
92+
*)
93+
let runtime_test_package_specs : t = {
94+
name = Pkg_runtime;
95+
module_systems = []
96+
}
8997
let same_package_by_name (x : t) (y : t) = x.name = y.name
9098

9199
let is_runtime_package (x : t) =
@@ -112,16 +120,10 @@ let empty : t =
112120
module_systems = []
113121
}
114122

115-
let from_name (name : string) =
116-
if name = runtime_package_name then
117-
{
118-
name = Pkg_runtime ; module_systems = []
119-
}
120-
else
121-
{
122-
name = Pkg_normal name ;
123-
module_systems = []
124-
}
123+
let from_name (name : string) : t = {
124+
name = Pkg_normal name ;
125+
module_systems = []
126+
}
125127

126128
let is_empty (x : t) =
127129
x.name = Pkg_empty
@@ -156,7 +158,7 @@ let dump_package_name fmt (x : package_name) =
156158
match x with
157159
| Pkg_empty -> Format.fprintf fmt "@empty_pkg@"
158160
| Pkg_normal s -> Format.pp_print_string fmt s
159-
| Pkg_runtime -> Format.pp_print_string fmt runtime_package_name
161+
| Pkg_runtime -> Format.pp_print_string fmt "@runtime"
160162

161163
let dump_packages_info
162164
(fmt : Format.formatter)
@@ -208,7 +210,7 @@ let query_package_infos
208210
compatible k.module_system module_system) with
209211
| Some k ->
210212
let rel_path = k.path in
211-
let pkg_rel_path = runtime_package_name // rel_path in
213+
let pkg_rel_path = !Bs_version.package_name // rel_path in
212214
Package_found
213215
{
214216
rel_path ;
@@ -221,7 +223,8 @@ let query_package_infos
221223

222224
let get_js_path
223225
(x : t )
224-
module_system
226+
(module_system : module_system)
227+
: string
225228
=
226229
match Ext_list.find_first x.module_systems (fun k ->
227230
compatible k.module_system module_system) with

jscomp/core/js_packages_info.mli

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ type package_info = {
4747
type t
4848

4949
val runtime_package_specs : t
50+
51+
val runtime_test_package_specs : t
52+
5053
val is_runtime_package:
5154
t ->
5255
bool

jscomp/core/js_packages_state.ml

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ let set_package_name name =
3333
else
3434
Bsc_args.bad_arg "duplicated flag for -bs-package-name"
3535

36+
let make_runtime () : unit =
37+
packages_info := Js_packages_info.runtime_package_specs
38+
39+
let make_runtime_test () : unit =
40+
packages_info := Js_packages_info.runtime_test_package_specs
3641
let set_package_map module_name =
3742
(* set_package_name name ;
3843
let module_name = Ext_namespace.namespace_of_package_name name in *)

jscomp/core/js_packages_state.mli

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626

2727
val set_package_name : string -> unit
2828

29+
val make_runtime:
30+
unit -> unit
31+
32+
val make_runtime_test:
33+
unit -> unit
2934
val set_package_map : string -> unit
3035

3136
val get_packages_info :

jscomp/main/js_main.ml

+5-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,11 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
443443
"<list> Enable or disable error status for warnings according\n\
444444
to <list>. See option -w for the syntax of <list>.\n\
445445
Default setting is " ^ Bsc_warnings.defaults_warn_error;
446-
446+
"-make-runtime", unit_call Js_packages_state.make_runtime,
447+
"*internal* make runtime library";
448+
"-make-runtime-test", unit_call Js_packages_state.make_runtime_test,
449+
"*internal* make runtime test library";
450+
447451
|]
448452

449453

jscomp/others/release.ninja

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
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:.mjs -nopervasives -unsafe -w +50 -warn-error A -open Bs_stdlib_mini -I ./runtime
2+
bsc_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -nopervasives -unsafe -w +50 -warn-error A -open Bs_stdlib_mini -I ./runtime
33

44
rule cc
55
command = $bsc -bs-cmi -bs-cmj $bsc_flags -I others $in

jscomp/runtime/release.ninja

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
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:.mjs -nopervasives -unsafe -w +50 -warn-error A
2+
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 -make-runtime -nopervasives -unsafe -w +50 -warn-error A
33
bsc_flags = $bsc_no_open_flags -open Bs_stdlib_mini
44

55
rule cc

jscomp/stdlib-406/release.ninja

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
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:.mjs -w -9-3-106 -warn-error A -I runtime -I others
2+
bsc_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -w -9-3-106 -warn-error A -I runtime -I others
33

44
rule cc
55
command = $bsc -bs-cmi -bs-cmj $bsc_flags -I stdlib-406 $in

jscomp/test/build.ninja

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
bsc_flags = -bs-no-version-header -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:jscomp/test -w -3-6-26-27-29-30-32..40-44-45-52-60-9-106+104 -warn-error A -I runtime -I $stdlib -I others
2+
bsc_flags = -bs-no-version-header -bs-cross-module-opt -make-runtime-test -bs-package-output commonjs:jscomp/test -w -3-6-26-27-29-30-32..40-44-45-52-60-9-106+104 -warn-error A -I runtime -I $stdlib -I others
33

44
rule cc
55
command = $bsc -bs-cmi -bs-cmj $bsc_flags -I test $in

lib/4.06.1/bsb.ml

+8-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ val version : string
2828

2929
val header : string
3030

31-
val package_name : string
31+
val package_name : string ref
3232
end = struct
3333
#1 "bs_version.ml"
3434

@@ -55,10 +55,10 @@ end = struct
5555
* You should have received a copy of the GNU Lesser General Public License
5656
* along with this program; if not, write to the Free Software
5757
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
58-
let version = "8.4.0"
58+
let version = "8.5.0"
5959
let header =
6060
"// Generated by ReScript, PLEASE EDIT WITH CARE"
61-
let package_name = "bs-platform"
61+
let package_name = ref "bs-platform"
6262

6363
end
6464
module Ext_array : sig
@@ -6500,12 +6500,12 @@ let print (fmt : Format.formatter) (x : error) =
65006500
| None -> Ext_string.empty
65016501
| Some x -> " in " ^ x in
65026502
let name = Bsb_pkg_types.to_string name in
6503-
if Ext_string.equal name Bs_version.package_name then
6503+
if Ext_string.equal name !Bs_version.package_name then
65046504
Format.fprintf fmt
65056505
"File \"bsconfig.json\", line 1\n\
6506-
@{<error>Error:@} package @{<error>bs-platform@} is not found %s\n\
6506+
@{<error>Error:@} package @{<error>%s@} is not found %s\n\
65076507
It's the basic, required package. If you have it installed globally,\n\
6508-
Please run `npm link bs-platform` to make it available" in_json
6508+
Please run `npm link bs-platform` to make it available" name in_json
65096509
else
65106510
Format.fprintf fmt
65116511
"File \"bsconfig.json\", line 1\n\
@@ -11054,7 +11054,7 @@ end = struct
1105411054

1105511055
(* let get_list_string = Bsb_build_util.get_list_string *)
1105611056
let (//) = Ext_path.combine
11057-
let current_package : Bsb_pkg_types.t = Global Bs_version.package_name
11057+
1105811058
let resolve_package cwd package_name =
1105911059
let x = Bsb_pkg.resolve_bs_package ~cwd package_name in
1106011060
{
@@ -11142,6 +11142,7 @@ let check_stdlib (map : json_map) cwd (*built_in_package*) =
1114211142
| None
1114311143
| Some _ ->
1114411144
begin
11145+
let current_package : Bsb_pkg_types.t = Global !Bs_version.package_name in
1114511146
if Sys.getenv_opt "RES_SKIP_STDLIB_CHECK" = None then begin
1114611147
let stdlib_path =
1114711148
Bsb_pkg.resolve_bs_package ~cwd current_package in

0 commit comments

Comments
 (0)