Skip to content

Commit a4b64b5

Browse files
committed
Not passing bsc_dir as an argument
1 parent 5e8ee3f commit a4b64b5

18 files changed

+383
-194
lines changed

jscomp/bsb/bsb_build_util.ml

-15
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,6 @@ let resolve_bsb_magic_file ~cwd ~desc p : result =
116116

117117
(** converting a file from Linux path format to Windows *)
118118

119-
(**
120-
If [Sys.executable_name] gives an absolute path,
121-
nothing needs to be done.
122-
123-
If [Sys.executable_name] is not an absolute path, for example
124-
(rlwrap ./ocaml)
125-
it is a relative path,
126-
it needs be adapted based on cwd
127-
*)
128-
129-
let get_bsc_dir ~cwd =
130-
Filename.dirname
131-
(Ext_path.normalize_absolute_path
132-
(Ext_path.combine cwd Sys.executable_name))
133-
134119

135120

136121
(**

jscomp/bsb/bsb_build_util.mli

-12
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,6 @@ val mkp : string -> unit
6767

6868

6969

70-
(**
71-
if [Sys.executable_name] gives an absolute path,
72-
nothing needs to be done
73-
if it is a relative path
74-
75-
there are two cases:
76-
- bsb.exe
77-
- ./bsb.exe
78-
The first should also not be touched
79-
Only the latter need be adapted based on project root
80-
*)
81-
val get_bsc_dir : cwd:string -> string
8270

8371

8472
val get_list_string_acc :

jscomp/bsb/bsb_clean.ml

+8-7
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
let (//) = Ext_path.combine
2727

2828

29-
let ninja_clean bsc_dir proj_dir =
29+
let ninja_clean proj_dir =
3030
try
31-
let cmd = bsc_dir // "ninja.exe" in
31+
let cmd = Bsb_global_paths.vendor_ninja in
3232
let cwd = proj_dir // Bsb_config.lib_bs in
3333
if Sys.file_exists cwd then
3434
let eid =
@@ -38,25 +38,26 @@ let ninja_clean bsc_dir proj_dir =
3838
with e ->
3939
Bsb_log.warn "@{<warning>ninja clean failed@} : %s @." (Printexc.to_string e)
4040

41-
let clean_bs_garbage bsc_dir proj_dir =
41+
let clean_bs_garbage proj_dir =
4242
Bsb_log.info "@{<info>Cleaning:@} in %s@." proj_dir ;
4343
let try_remove x =
4444
let x = proj_dir // x in
4545
if Sys.file_exists x then
4646
Bsb_unix.remove_dir_recursive x in
4747
try
4848
Bsb_parse_sources.clean_re_js proj_dir; (* clean re.js files*)
49-
ninja_clean bsc_dir proj_dir ;
49+
ninja_clean proj_dir ;
5050
Ext_list.iter Bsb_config.all_lib_artifacts try_remove ;
5151
with
5252
e ->
5353
Bsb_log.warn "@{<warning>Failed@} to clean due to %s" (Printexc.to_string e)
5454

5555

56-
let clean_bs_deps bsc_dir proj_dir =
56+
let clean_bs_deps proj_dir =
5757
Bsb_build_util.walk_all_deps proj_dir (fun pkg_cxt ->
5858
(* whether top or not always do the cleaning *)
59-
clean_bs_garbage bsc_dir pkg_cxt.cwd
59+
clean_bs_garbage pkg_cxt.cwd
6060
)
6161

62-
let clean_self bsc_dir proj_dir = clean_bs_garbage bsc_dir proj_dir
62+
let clean_self proj_dir =
63+
clean_bs_garbage proj_dir

jscomp/bsb/bsb_clean.mli

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
TODO: clean staled in source js artifacts
2727
*)
2828

29-
val clean_bs_deps : string -> string -> unit
29+
val clean_bs_deps :
30+
string ->
31+
unit
3032

31-
val clean_self : string -> string -> unit
33+
val clean_self :
34+
string ->
35+
unit

jscomp/bsb/bsb_config_parse.ml

-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ let extract_js_post_build (map : json_map) cwd : string option =
375375
With a given [cwd] it works anywhere*)
376376
let interpret_json
377377
~toplevel_package_specs
378-
~bsc_dir
379378
~per_proj_dir:(cwd:string)
380379

381380
: Bsb_config_types.t =

jscomp/bsb/bsb_config_parse.mli

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ val package_specs_from_bsconfig :
3030

3131
val interpret_json :
3232
toplevel_package_specs:Bsb_package_specs.t option ->
33-
bsc_dir:string ->
3433
per_proj_dir:string ->
3534
Bsb_config_types.t
3635

jscomp/bsb/bsb_global_paths.ml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
(* Copyright (C) 2019 - Authors of BuckleScript
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+
let cwd = Sys.getcwd ()
26+
27+
28+
(**
29+
If [Sys.executable_name] gives an absolute path,
30+
nothing needs to be done.
31+
32+
If [Sys.executable_name] is not an absolute path, for example
33+
(rlwrap ./ocaml)
34+
it is a relative path,
35+
it needs be adapted based on cwd
36+
37+
if [Sys.executable_name] gives an absolute path,
38+
nothing needs to be done
39+
if it is a relative path
40+
41+
there are two cases:
42+
- bsb.exe
43+
- ./bsb.exe
44+
The first should also not be touched
45+
Only the latter need be adapted based on project root
46+
*)
47+
48+
let bsc_dir =
49+
Filename.dirname
50+
(Ext_path.normalize_absolute_path
51+
(Ext_path.combine cwd Sys.executable_name))
52+
53+
let vendor_ninja =
54+
Filename.concat bsc_dir "ninja.exe"
55+
56+
57+
;; assert (Sys.file_exists bsc_dir)
58+
59+

jscomp/bsb/bsb_global_paths.mli

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
(* Copyright (C) 2019 - Authors of BuckleScript
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+
26+
val cwd : string
27+
28+
val bsc_dir : string
29+
30+
val vendor_ninja : string
31+

jscomp/bsb/bsb_ninja_gen.ml

+2-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ let output_static_resources
9797

9898
let output_ninja_and_namespace_map
9999
~cwd
100-
~bsc_dir
101100
~toplevel
102101
({
103102
bs_suffix;
@@ -159,9 +158,9 @@ let output_ninja_and_namespace_map
159158
Bsb_ninja_global_vars.g_pkg_flg, g_pkg_flg ;
160159
Bsb_ninja_global_vars.src_root_dir, cwd (* TODO: need check its integrity -- allow relocate or not? *);
161160
(* The path to [bsc.exe] independent of config *)
162-
Bsb_ninja_global_vars.bsc, (Ext_filename.maybe_quote (bsc_dir // bsc_exe));
161+
Bsb_ninja_global_vars.bsc, (Ext_filename.maybe_quote (Bsb_global_paths.bsc_dir // bsc_exe));
163162
(* The path to [bsb_heler.exe] *)
164-
Bsb_ninja_global_vars.bsdep, (Ext_filename.maybe_quote (bsc_dir // bsb_helper_exe)) ;
163+
Bsb_ninja_global_vars.bsdep, (Ext_filename.maybe_quote (Bsb_global_paths.bsc_dir // bsb_helper_exe)) ;
165164
Bsb_ninja_global_vars.warnings, Bsb_warning.opt_warning_to_string ~toplevel warning ;
166165
Bsb_ninja_global_vars.bsc_flags, (get_bsc_flags ~toplevel bsc_flags) ;
167166
Bsb_ninja_global_vars.ppx_flags, ppx_flags;

jscomp/bsb/bsb_ninja_gen.mli

-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,5 @@
2727
*)
2828
val output_ninja_and_namespace_map :
2929
cwd:string ->
30-
bsc_dir:string ->
3130
toplevel:bool ->
3231
Bsb_config_types.t -> unit

jscomp/bsb/bsb_ninja_regen.ml

+4-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ let (//) = Ext_path.combine
3434
*)
3535
let regenerate_ninja
3636
~(toplevel_package_specs : Bsb_package_specs.t option)
37-
~forced ~cwd ~bsc_dir
37+
~forced ~cwd
3838
: Bsb_config_types.t option =
3939
let toplevel = toplevel_package_specs = None in
4040
let lib_bs_dir = cwd // Bsb_config.lib_bs in
@@ -55,13 +55,12 @@ let regenerate_ninja
5555
| Other _ ->
5656
if check_result = Bsb_bsc_version_mismatch then begin
5757
Bsb_log.warn "@{<info>Different compiler version@}: clean current repo@.";
58-
Bsb_clean.clean_self bsc_dir cwd;
58+
Bsb_clean.clean_self cwd;
5959
end ;
6060

6161
let config =
6262
Bsb_config_parse.interpret_json
6363
~toplevel_package_specs
64-
~bsc_dir
6564
~per_proj_dir:cwd in
6665
(* create directory, lib/bs, lib/js, lib/es6 etc *)
6766
Bsb_build_util.mkp lib_bs_dir;
@@ -75,9 +74,9 @@ let regenerate_ninja
7574
config.file_groups
7675
;
7776
Bsb_merlin_gen.merlin_file_gen ~cwd
78-
(bsc_dir // bsppx_exe) config;
77+
(Bsb_global_paths.bsc_dir // bsppx_exe) config;
7978
Bsb_ninja_gen.output_ninja_and_namespace_map
80-
~cwd ~bsc_dir ~toplevel config ;
79+
~cwd ~toplevel config ;
8180

8281
(* PR2184: we still need record empty dir
8382
since it may add files in the future *)

jscomp/bsb/bsb_ninja_regen.mli

-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,4 @@ val regenerate_ninja :
3333
toplevel_package_specs:Bsb_package_specs.t option ->
3434
forced: bool ->
3535
cwd:string ->
36-
bsc_dir:string ->
3736
Bsb_config_types.t option

jscomp/bsb/bsb_world.ml

+2-3
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ let install_targets cwd (config : Bsb_config_types.t option) =
6363

6464
let build_bs_deps cwd (deps : Bsb_package_specs.t) (ninja_args : string array) =
6565

66-
let bsc_dir = Bsb_build_util.get_bsc_dir ~cwd in
67-
let vendor_ninja = bsc_dir // "ninja.exe" in
66+
let vendor_ninja = Bsb_global_paths.vendor_ninja in
6867
let args =
6968
if Ext_array.is_empty ninja_args then [|vendor_ninja|]
7069
else Array.append [|vendor_ninja|] ninja_args
@@ -76,7 +75,7 @@ let build_bs_deps cwd (deps : Bsb_package_specs.t) (ninja_args : string array) =
7675
Bsb_ninja_regen.regenerate_ninja
7776
~toplevel_package_specs:(Some deps)
7877
~forced:true
79-
~cwd ~bsc_dir in (* set true to force regenrate ninja file so we have [config_opt]*)
78+
~cwd in (* set true to force regenrate ninja file so we have [config_opt]*)
8079
let command =
8180
{Bsb_unix.cmd = vendor_ninja;
8281
cwd = cwd // Bsb_config.lib_bs;

jscomp/main/bsb_main.ml

+9-11
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525

2626

27-
let cwd = Sys.getcwd ()
28-
let bsc_dir = Bsb_build_util.get_bsc_dir ~cwd
2927
let () = Bsb_log.setup ()
3028
let (//) = Ext_path.combine
3129
let force_regenerate = ref false
@@ -57,10 +55,10 @@ let bsb_main_flags : (string * Arg.spec * string) list=
5755
"-w", Arg.Set watch_mode,
5856
" Watch mode" ;
5957
"-clean-world", Arg.Unit (fun _ ->
60-
Bsb_clean.clean_bs_deps bsc_dir cwd),
58+
Bsb_clean.clean_bs_deps Bsb_global_paths.cwd),
6159
" Clean all bs dependencies";
6260
"-clean", Arg.Unit (fun _ ->
63-
Bsb_clean.clean_self bsc_dir cwd),
61+
Bsb_clean.clean_self Bsb_global_paths.cwd),
6462
" Clean only current project";
6563
"-make-world", Arg.Unit set_make_world,
6664
" Build all dependencies and itself ";
@@ -136,14 +134,14 @@ let program_exit () =
136134
(* see discussion #929, if we catch the exception, we don't have stacktrace... *)
137135
let () =
138136

139-
let vendor_ninja = bsc_dir // "ninja.exe" in
137+
let vendor_ninja = Bsb_global_paths.vendor_ninja in
140138
try begin
141139
match Sys.argv with
142140
| [| _ |] -> (* specialize this path [bsb.exe] which is used in watcher *)
143141
Bsb_ninja_regen.regenerate_ninja
144142
~toplevel_package_specs:None
145143
~forced:false
146-
~cwd ~bsc_dir |> ignore;
144+
~cwd:Bsb_global_paths.cwd |> ignore;
147145
ninja_command_exit vendor_ninja [||]
148146

149147
| argv ->
@@ -155,7 +153,7 @@ let () =
155153
Arg.parse bsb_main_flags handle_anonymous_arg usage;
156154
(* first, check whether we're in boilerplate generation mode, aka -init foo -theme bar *)
157155
match !generate_theme_with_path with
158-
| Some path -> Bsb_theme_init.init_sample_project ~cwd ~theme:!current_theme path
156+
| Some path -> Bsb_theme_init.init_sample_project ~cwd:Bsb_global_paths.cwd ~theme:!current_theme path
159157
| None ->
160158
(* [-make-world] should never be combined with [-package-specs] *)
161159
let make_world = !make_world in
@@ -172,9 +170,9 @@ let () =
172170
(let config_opt =
173171
Bsb_ninja_regen.regenerate_ninja
174172
~toplevel_package_specs:None
175-
~forced:force_regenerate ~cwd ~bsc_dir in
173+
~forced:force_regenerate ~cwd:Bsb_global_paths.cwd in
176174
if make_world then begin
177-
Bsb_world.make_world_deps cwd config_opt [||]
175+
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt [||]
178176
end;
179177
if !watch_mode then begin
180178
program_exit ()
@@ -194,11 +192,11 @@ let () =
194192
let config_opt =
195193
Bsb_ninja_regen.regenerate_ninja
196194
~toplevel_package_specs:None
197-
~cwd ~bsc_dir
195+
~cwd:Bsb_global_paths.cwd
198196
~forced:!force_regenerate in
199197
(* [-make-world] should never be combined with [-package-specs] *)
200198
if !make_world then
201-
Bsb_world.make_world_deps cwd config_opt ninja_args;
199+
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args;
202200
if !watch_mode then program_exit ()
203201
else ninja_command_exit vendor_ninja ninja_args
204202
end

0 commit comments

Comments
 (0)