Skip to content

Commit d6e6256

Browse files
committed
Add install flag to bsb
call install_targets for root project when install flag is set Signed-Off-By: Jan Lindemann <[email protected]>
1 parent 27fb7e6 commit d6e6256

File tree

4 files changed

+90
-15
lines changed

4 files changed

+90
-15
lines changed

jscomp/bsb/bsb_world.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525

26-
(*val install_targets:
26+
val install_targets:
2727
string ->
2828
Bsb_config_types.t option ->
29-
unit*)
29+
unit
3030

3131
val make_world_deps:
3232
string ->

jscomp/main/bsb_main.ml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ let regen = "-regen"
3636
let separator = "--"
3737
let watch_mode = ref false
3838
let make_world = ref false
39+
let do_install = ref false
3940
let set_make_world () = make_world := true
4041
let bs_version_string = Bs_version.version
4142

@@ -62,6 +63,8 @@ let bsb_main_flags : (string * Arg.spec * string) list=
6263
" Clean only current project";
6364
"-make-world", Arg.Unit set_make_world,
6465
" Build all dependencies and itself ";
66+
"-install", Arg.Set do_install,
67+
" Install public interface files into lib/ocaml";
6568
"-init", Arg.String (fun path -> generate_theme_with_path := Some path),
6669
" Init sample project to get started. Note (`bsb -init sample` will create a sample project while `bsb -init .` will reuse current directory)";
6770
"-theme", Arg.String set_theme,
@@ -131,6 +134,23 @@ let handle_anonymous_arg arg =
131134
let program_exit () =
132135
exit 0
133136

137+
let install_target config_opt =
138+
let config =
139+
match config_opt with
140+
| None ->
141+
let config = Bsb_config_parse.interpret_json ~toplevel_package_specs:None ~per_proj_dir:Bsb_global_paths.cwd in
142+
let _ = Ext_list.iter config.file_groups.files (fun group ->
143+
let check_file = match group.public with
144+
| Export_all -> fun _ -> true
145+
| Export_none -> fun _ -> false
146+
| Export_set set ->
147+
fun module_name ->
148+
String_set.mem set module_name in
149+
String_map.iter group.sources (fun module_name module_info -> if check_file module_name then begin String_hash_set.add config.files_to_install module_info.name_sans_extension end)) in
150+
config
151+
| Some config -> config in
152+
Bsb_world.install_targets Bsb_global_paths.cwd (Some config)
153+
134154
(* see discussion #929, if we catch the exception, we don't have stacktrace... *)
135155
let () =
136156
try begin
@@ -155,8 +175,9 @@ let () =
155175
| None ->
156176
(* [-make-world] should never be combined with [-package-specs] *)
157177
let make_world = !make_world in
158-
let force_regenerate = !force_regenerate in
159-
if not make_world && not force_regenerate then
178+
let force_regenerate = !force_regenerate in
179+
let do_install = !do_install in
180+
if not make_world && not force_regenerate && not do_install then
160181
(* [regenerate_ninja] is not triggered in this case
161182
There are several cases we wish ninja will not be triggered.
162183
[bsb -clean-world]
@@ -180,7 +201,9 @@ let () =
180201
[bsb -regen ]
181202
*)
182203
end else if make_world then begin
183-
ninja_command_exit [||]
204+
ninja_command_exit [||]
205+
end else if do_install then begin
206+
install_target config_opt
184207
end)
185208
end
186209
| `Split (bsb_args,ninja_args)
@@ -195,6 +218,8 @@ let () =
195218
(* [-make-world] should never be combined with [-package-specs] *)
196219
if !make_world then
197220
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args;
221+
if !do_install then
222+
install_target config_opt;
198223
if !watch_mode then program_exit ()
199224
else ninja_command_exit ninja_args
200225
end

lib/4.02.3/bsb.ml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16742,10 +16742,10 @@ module Bsb_world : sig
1674216742
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
1674316743

1674416744

16745-
(*val install_targets:
16745+
val install_targets:
1674616746
string ->
1674716747
Bsb_config_types.t option ->
16748-
unit*)
16748+
unit
1674916749

1675016750
val make_world_deps:
1675116751
string ->
@@ -16909,6 +16909,7 @@ let regen = "-regen"
1690916909
let separator = "--"
1691016910
let watch_mode = ref false
1691116911
let make_world = ref false
16912+
let do_install = ref false
1691216913
let set_make_world () = make_world := true
1691316914
let bs_version_string = Bs_version.version
1691416915

@@ -16935,6 +16936,8 @@ let bsb_main_flags : (string * Arg.spec * string) list=
1693516936
" Clean only current project";
1693616937
"-make-world", Arg.Unit set_make_world,
1693716938
" Build all dependencies and itself ";
16939+
"-install", Arg.Set do_install,
16940+
" Install public interface files into lib/ocaml";
1693816941
"-init", Arg.String (fun path -> generate_theme_with_path := Some path),
1693916942
" Init sample project to get started. Note (`bsb -init sample` will create a sample project while `bsb -init .` will reuse current directory)";
1694016943
"-theme", Arg.String set_theme,
@@ -17004,6 +17007,23 @@ let handle_anonymous_arg arg =
1700417007
let program_exit () =
1700517008
exit 0
1700617009

17010+
let install_target config_opt =
17011+
let config =
17012+
match config_opt with
17013+
| None ->
17014+
let config = Bsb_config_parse.interpret_json ~toplevel_package_specs:None ~per_proj_dir:Bsb_global_paths.cwd in
17015+
let _ = Ext_list.iter config.file_groups.files (fun group ->
17016+
let check_file = match group.public with
17017+
| Export_all -> fun _ -> true
17018+
| Export_none -> fun _ -> false
17019+
| Export_set set ->
17020+
fun module_name ->
17021+
String_set.mem set module_name in
17022+
String_map.iter group.sources (fun module_name module_info -> if check_file module_name then begin String_hash_set.add config.files_to_install module_info.name_sans_extension end)) in
17023+
config
17024+
| Some config -> config in
17025+
Bsb_world.install_targets Bsb_global_paths.cwd (Some config)
17026+
1700717027
(* see discussion #929, if we catch the exception, we don't have stacktrace... *)
1700817028
let () =
1700917029
try begin
@@ -17028,8 +17048,9 @@ let () =
1702817048
| None ->
1702917049
(* [-make-world] should never be combined with [-package-specs] *)
1703017050
let make_world = !make_world in
17031-
let force_regenerate = !force_regenerate in
17032-
if not make_world && not force_regenerate then
17051+
let force_regenerate = !force_regenerate in
17052+
let do_install = !do_install in
17053+
if not make_world && not force_regenerate && not do_install then
1703317054
(* [regenerate_ninja] is not triggered in this case
1703417055
There are several cases we wish ninja will not be triggered.
1703517056
[bsb -clean-world]
@@ -17053,7 +17074,9 @@ let () =
1705317074
[bsb -regen ]
1705417075
*)
1705517076
end else if make_world then begin
17056-
ninja_command_exit [||]
17077+
ninja_command_exit [||]
17078+
end else if do_install then begin
17079+
install_target config_opt
1705717080
end)
1705817081
end
1705917082
| `Split (bsb_args,ninja_args)
@@ -17068,6 +17091,8 @@ let () =
1706817091
(* [-make-world] should never be combined with [-package-specs] *)
1706917092
if !make_world then
1707017093
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args;
17094+
if !do_install then
17095+
install_target config_opt;
1707117096
if !watch_mode then program_exit ()
1707217097
else ninja_command_exit ninja_args
1707317098
end

lib/4.02.3/unstable/bsb_native.ml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16841,10 +16841,10 @@ module Bsb_world : sig
1684116841
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
1684216842

1684316843

16844-
(*val install_targets:
16844+
val install_targets:
1684516845
string ->
1684616846
Bsb_config_types.t option ->
16847-
unit*)
16847+
unit
1684816848

1684916849
val make_world_deps:
1685016850
string ->
@@ -17008,6 +17008,7 @@ let regen = "-regen"
1700817008
let separator = "--"
1700917009
let watch_mode = ref false
1701017010
let make_world = ref false
17011+
let do_install = ref false
1701117012
let set_make_world () = make_world := true
1701217013
let bs_version_string = Bs_version.version
1701317014

@@ -17034,6 +17035,8 @@ let bsb_main_flags : (string * Arg.spec * string) list=
1703417035
" Clean only current project";
1703517036
"-make-world", Arg.Unit set_make_world,
1703617037
" Build all dependencies and itself ";
17038+
"-install", Arg.Set do_install,
17039+
" Install public interface files into lib/ocaml";
1703717040
"-init", Arg.String (fun path -> generate_theme_with_path := Some path),
1703817041
" Init sample project to get started. Note (`bsb -init sample` will create a sample project while `bsb -init .` will reuse current directory)";
1703917042
"-theme", Arg.String set_theme,
@@ -17103,6 +17106,23 @@ let handle_anonymous_arg arg =
1710317106
let program_exit () =
1710417107
exit 0
1710517108

17109+
let install_target config_opt =
17110+
let config =
17111+
match config_opt with
17112+
| None ->
17113+
let config = Bsb_config_parse.interpret_json ~toplevel_package_specs:None ~per_proj_dir:Bsb_global_paths.cwd in
17114+
let _ = Ext_list.iter config.file_groups.files (fun group ->
17115+
let check_file = match group.public with
17116+
| Export_all -> fun _ -> true
17117+
| Export_none -> fun _ -> false
17118+
| Export_set set ->
17119+
fun module_name ->
17120+
String_set.mem set module_name in
17121+
String_map.iter group.sources (fun module_name module_info -> if check_file module_name then begin String_hash_set.add config.files_to_install module_info.name_sans_extension end)) in
17122+
config
17123+
| Some config -> config in
17124+
Bsb_world.install_targets Bsb_global_paths.cwd (Some config)
17125+
1710617126
(* see discussion #929, if we catch the exception, we don't have stacktrace... *)
1710717127
let () =
1710817128
try begin
@@ -17127,8 +17147,9 @@ let () =
1712717147
| None ->
1712817148
(* [-make-world] should never be combined with [-package-specs] *)
1712917149
let make_world = !make_world in
17130-
let force_regenerate = !force_regenerate in
17131-
if not make_world && not force_regenerate then
17150+
let force_regenerate = !force_regenerate in
17151+
let do_install = !do_install in
17152+
if not make_world && not force_regenerate && not do_install then
1713217153
(* [regenerate_ninja] is not triggered in this case
1713317154
There are several cases we wish ninja will not be triggered.
1713417155
[bsb -clean-world]
@@ -17152,7 +17173,9 @@ let () =
1715217173
[bsb -regen ]
1715317174
*)
1715417175
end else if make_world then begin
17155-
ninja_command_exit [||]
17176+
ninja_command_exit [||]
17177+
end else if do_install then begin
17178+
install_target config_opt
1715617179
end)
1715717180
end
1715817181
| `Split (bsb_args,ninja_args)
@@ -17167,6 +17190,8 @@ let () =
1716717190
(* [-make-world] should never be combined with [-package-specs] *)
1716817191
if !make_world then
1716917192
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args;
17193+
if !do_install then
17194+
install_target config_opt;
1717017195
if !watch_mode then program_exit ()
1717117196
else ninja_command_exit ninja_args
1717217197
end

0 commit comments

Comments
 (0)