Skip to content

Commit 19ac7d4

Browse files
committed
fix #5154
1 parent bbfe82f commit 19ac7d4

File tree

6 files changed

+173
-35
lines changed

6 files changed

+173
-35
lines changed

jscomp/bsb/bsb_ninja_check.ml

+2-11
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,7 @@ let record
106106
let buf = Ext_buffer.create 1_000 in
107107
Ext_buffer.add_string_char buf Bs_version.version '\n';
108108
Ext_buffer.add_string_char buf per_proj_dir '\n';
109-
(match package_kind with
110-
| Toplevel -> Ext_buffer.add_string buf "0\n"
111-
| Dependency _ -> Ext_buffer.add_string buf "1\n"
112-
| Pinned_dependency _ -> Ext_buffer.add_string buf "2\n"
113-
);
109+
Ext_buffer.add_string_char buf (Bsb_package_kind.encode_no_nl package_kind) '\n';
114110
Ext_list.iter file_or_dirs (fun f ->
115111
Ext_buffer.add_string_char buf f '\t';
116112
Ext_buffer.add_string_char buf
@@ -147,12 +143,7 @@ let check
147143
if per_proj_dir <> source_directory then Bsb_source_directory_changed else
148144
if forced then Bsb_forced (* No need walk through *)
149145
else if
150-
151-
not (match package_kind, package_kind_str with
152-
| Toplevel, "0"
153-
| Dependency _, "1"
154-
| Pinned_dependency _, "2" -> true
155-
| _ -> false ) then
146+
(Bsb_package_kind.encode_no_nl package_kind <> package_kind_str) then
156147
Bsb_package_kind_inconsistent
157148
else
158149
begin

jscomp/bsb/bsb_package_kind.ml

+13
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,16 @@ type t =
2929
(* This package specs comes from the toplevel to
3030
override the current settings
3131
*)
32+
33+
34+
let encode_no_nl ( x : t) =
35+
match x with
36+
| Toplevel -> "0"
37+
| Dependency x ->
38+
"1" ^
39+
Bsb_package_specs.package_flag_of_package_specs x
40+
~dirname:"."
41+
| Pinned_dependency x ->
42+
"2" ^
43+
Bsb_package_specs.package_flag_of_package_specs x
44+
~dirname:"."

jscomp/bsb/bsb_package_specs.ml

+29-22
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,10 @@ let (//) = Ext_path.combine
2727

2828

2929

30-
(* TODO: sync up with {!Js_packages_info.module_system} *)
31-
type format = Ext_module_system.t =
32-
| NodeJS | Es6 | Es6_global
33-
34-
type spec = {
35-
format : format;
36-
in_source : bool;
37-
suffix : Ext_js_suffix.t
38-
}
30+
3931

4032
(*FIXME: use assoc list instead *)
41-
module Spec_set = Set.Make( struct type t = spec
42-
let compare = Pervasives.compare
43-
end)
33+
module Spec_set = Bsb_spec_set
4434

4535
type t = {
4636
modules : Spec_set.t;
@@ -59,13 +49,13 @@ let bad_module_format_message_exn ~loc format =
5949
Literals.es6
6050
Literals.es6_global
6151

62-
let supported_format (x : string) loc =
52+
let supported_format (x : string) loc : Ext_module_system.t =
6353
if x = Literals.commonjs then NodeJS
6454
else if x = Literals.es6 then Es6
6555
else if x = Literals.es6_global then Es6_global
6656
else bad_module_format_message_exn ~loc x
6757

68-
let string_of_format (x : format) =
58+
let string_of_format (x : Ext_module_system.t) =
6959
match x with
7060
| NodeJS -> Literals.commonjs
7161
| Es6 -> Literals.es6
@@ -91,7 +81,7 @@ let rec from_array suffix (arr : Ext_json_types.t array) : Spec_set.t =
9181
!spec
9282

9383
(* TODO: FIXME: better API without mutating *)
94-
and from_json_single suffix (x : Ext_json_types.t) : spec =
84+
and from_json_single suffix (x : Ext_json_types.t) : Bsb_spec_set.spec =
9585
match x with
9686
| Str {str = format; loc } ->
9787
{format = supported_format format loc ; in_source = false ; suffix }
@@ -136,7 +126,7 @@ let bs_package_output = "-bs-package-output"
136126
coordinate with command line flag
137127
{[ -bs-package-output commonjs:lib/js/jscomp/test:.js ]}
138128
*)
139-
let package_flag ({format; in_source; suffix } : spec) dir =
129+
let package_flag ({format; in_source; suffix } : Bsb_spec_set.spec) dir =
140130
Ext_string.inter2
141131
bs_package_output
142132
(Ext_string.concat5
@@ -151,13 +141,30 @@ let package_flag ({format; in_source; suffix } : spec) dir =
151141
(* FIXME: we should adapt it *)
152142
let package_flag_of_package_specs (package_specs : t)
153143
~(dirname : string ) : string =
154-
let res = Spec_set.fold (fun format acc ->
155-
Ext_string.inter2 acc (package_flag format dirname )
156-
) package_specs.modules Ext_string.empty in
144+
let res =
145+
match (package_specs.modules :> Bsb_spec_set.spec list) with
146+
| [] -> Ext_string.empty
147+
| [format] ->
148+
Ext_string.inter2 Ext_string.empty (package_flag format dirname)
149+
| [a;b] ->
150+
Ext_string.inter3 Ext_string.empty
151+
(package_flag a dirname)
152+
(package_flag b dirname)
153+
| [a;b;c] ->
154+
Ext_string.inter4
155+
Ext_string.empty
156+
(package_flag a dirname)
157+
(package_flag b dirname)
158+
(package_flag c dirname)
159+
| _ ->
160+
Spec_set.fold (fun format acc ->
161+
Ext_string.inter2 acc (package_flag format dirname )
162+
) package_specs.modules Ext_string.empty in
157163
match package_specs.runtime with
158164
| None -> res
159165
| Some x ->
160-
res ^ " -runtime " ^ x
166+
Ext_string.inter3 res "-runtime" x
167+
161168
let default_package_specs suffix =
162169
Spec_set.singleton
163170
{ format = NodeJS ; in_source = false; suffix }
@@ -173,7 +180,7 @@ let get_list_of_output_js
173180
(output_file_sans_extension : string)
174181
=
175182
Spec_set.fold
176-
(fun (spec : spec) acc ->
183+
(fun (spec : Bsb_spec_set.spec) acc ->
177184
let basename =
178185
Ext_namespace.change_ext_ns_suffix
179186
output_file_sans_extension
@@ -189,7 +196,7 @@ let list_dirs_by
189196
(package_specs : t)
190197
(f : string -> unit)
191198
=
192-
Spec_set.iter (fun (spec : spec) ->
199+
Spec_set.iter (fun (spec : Bsb_spec_set.spec) ->
193200
if not spec.in_source then
194201
f (Bsb_config.top_prefix_of_format spec.format)
195202
) package_specs.modules

jscomp/bsb/bsb_spec_set.ml

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
(* Copyright (C) 2017 Hongbo Zhang, Authors of ReScript
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
[@@@warning "+9"]
26+
(* TODO: sync up with {!Js_packages_info.module_system} *)
27+
type format = Ext_module_system.t =
28+
| NodeJS | Es6 | Es6_global
29+
30+
type spec = {
31+
format : format;
32+
in_source : bool;
33+
suffix : Ext_js_suffix.t
34+
}
35+
type t = spec list
36+
37+
let cmp (s1 : spec) ({format;in_source;suffix} : spec) =
38+
let v = compare s1.format format in
39+
if v <> 0 then v
40+
else
41+
let v = compare s1.in_source in_source in
42+
if v <> 0 then v
43+
else
44+
compare s1.suffix suffix
45+
46+
let empty = []
47+
48+
let rec insert lst piviot =
49+
match lst with
50+
| [] -> [piviot]
51+
| x::xs ->
52+
let v = cmp piviot x in
53+
if v = 0 then lst
54+
else if v < 0 then piviot :: lst
55+
else
56+
x :: insert xs piviot
57+
58+
let add spec specs =
59+
match specs with
60+
| [] -> [spec]
61+
| [a] ->
62+
let v = cmp spec a in
63+
if v < 0 then spec :: specs
64+
else if v = 0 then specs
65+
else [a; spec]
66+
| [a;b] ->
67+
let v = cmp spec a in
68+
if v < 0 then spec :: specs
69+
else if v = 0 then specs
70+
else
71+
let v1 = cmp spec b in
72+
if v < 0 then [a;spec;b]
73+
else if v1 = 0 then specs
74+
else
75+
[a;b;spec]
76+
| _::_::_::_ -> (* unlikely to happen *)
77+
insert specs spec
78+
79+
let singleton x = [x]
80+
81+
let rec fold f t acc =
82+
match t with
83+
| [] -> acc
84+
| x::xs -> fold f xs (f x acc)
85+
86+
let rec iter f t =
87+
match t with
88+
| [] -> ()
89+
| x::xs -> f x ; iter f xs

jscomp/bsb/bsb_spec_set.mli

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
(* Copyright (C) 2017 Hongbo Zhang, Authors of ReScript
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
type format = Ext_module_system.t
25+
type spec = {
26+
format : format;
27+
in_source : bool;
28+
suffix : Ext_js_suffix.t
29+
}
30+
31+
type t = private spec list
32+
val empty : t
33+
val add : spec -> t -> t
34+
val singleton : spec -> t
35+
val fold : (spec -> 'a -> 'a) -> t -> 'a -> 'a
36+
val iter : (spec -> unit) ->t -> unit

jscomp/main/rescript_main.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ let build_subcommand ~start argv argv_len =
141141
"-install", unit_set_spec do_install,
142142
"*internal* Install public interface files for dependencies ";
143143
(* This should be put in a subcommand
144-
previously it works with the implication `bsb && bsb -install`
144+
previously it works with the implication `bsb && bsb -install`
145145
*)
146146
"-ws", string_set_spec (ref ""),
147147
"[host]:port set up host & port for WebSocket build notifications";
@@ -183,7 +183,9 @@ let clean_subcommand ~start argv =
183183
Bsb_arg.parse_exn
184184
~usage:clean_usage ~start ~argv [|
185185
"-with-deps", unit_set_spec make_world,
186-
"Clean dependencies too"
186+
"Clean dependencies too";
187+
"-verbose", call_spec Bsb_log.verbose,
188+
"Set the output to be verbose";
187189
|] failed_annon;
188190
if !make_world then
189191
Bsb_clean.clean_bs_deps Bsb_global_paths.cwd ;

0 commit comments

Comments
 (0)