|
23 | 23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
|
24 | 24 |
|
25 | 25 | let () = Bsb_log.setup ()
|
26 |
| - |
27 |
| -let force_regenerate = ref false |
28 |
| - |
29 | 26 | let current_theme = ref "basic"
|
30 |
| -let set_theme s = current_theme := s |
31 | 27 | let generate_theme_with_path = ref None
|
32 | 28 | let regen = "-regen"
|
33 | 29 | let separator = "--"
|
34 | 30 | let watch_mode = ref false
|
35 | 31 | let make_world = ref false
|
36 | 32 | let do_install = ref false
|
37 |
| -let set_make_world () = make_world := true |
38 | 33 | let bs_version_string = Bs_version.version
|
39 |
| - |
40 | 34 | let print_version_string () =
|
41 | 35 | print_string bs_version_string;
|
42 | 36 | print_newline ();
|
43 | 37 | exit 0
|
| 38 | +type spec = Bsb_arg.spec |
44 | 39 |
|
45 |
| -let bsb_main_flags : (string * Arg.spec * string) list= |
| 40 | +let call_spec f : spec = Unit (Unit_call f ) |
| 41 | +let unit_set_spec b : spec = Unit (Unit_set b) |
| 42 | + |
| 43 | + |
| 44 | +let force_regenerate = ref false |
| 45 | +let bsb_main_flags : (string * spec * string) list= |
46 | 46 | [
|
47 |
| - "-v", Unit print_version_string, |
48 |
| - " Print version and exit"; |
49 |
| - "-version", Unit print_version_string, |
50 |
| - " Print version and exit"; |
51 |
| - "-verbose", Unit Bsb_log.verbose, |
52 |
| - " Set the output(from bsb) to be verbose"; |
53 |
| - "-w", Set watch_mode, |
54 |
| - " Watch mode" ; |
55 |
| - "-clean-world", Unit (fun _ -> |
| 47 | + "-v", call_spec print_version_string, |
| 48 | + "Print version and exit"; |
| 49 | + "-version", call_spec print_version_string, |
| 50 | + "Print version and exit"; |
| 51 | + "-verbose", call_spec Bsb_log.verbose, |
| 52 | + "Set the output(from bsb) to be verbose"; |
| 53 | + "-w", unit_set_spec watch_mode, |
| 54 | + "Watch mode" ; |
| 55 | + "-clean-world",call_spec (fun _ -> |
56 | 56 | Bsb_clean.clean_bs_deps Bsb_global_paths.cwd),
|
57 |
| - " Clean all bs dependencies"; |
58 |
| - "-clean", Unit (fun _ -> |
| 57 | + "Clean all bs dependencies"; |
| 58 | + "-clean", call_spec (fun _ -> |
59 | 59 | Bsb_clean.clean_self Bsb_global_paths.cwd),
|
60 |
| - " Clean only current project"; |
61 |
| - "-make-world", Unit set_make_world, |
62 |
| - " Build all dependencies and itself "; |
63 |
| - "-install", Set do_install, |
64 |
| - " Install public interface files into lib/ocaml"; |
65 |
| - "-init", String (fun path -> generate_theme_with_path := Some path), |
66 |
| - " Init sample project to get started. Note (`bsb -init sample` will create a sample project while `bsb -init .` will reuse current directory)"; |
67 |
| - "-theme", String set_theme, |
68 |
| - " The theme for project initialization, default is basic(https://github.com/bucklescript/bucklescript/tree/master/jscomp/bsb/templates)"; |
| 60 | + "Clean only current project"; |
| 61 | + "-make-world", unit_set_spec make_world, |
| 62 | + "Build all dependencies and itself "; |
| 63 | + "-install", unit_set_spec do_install, |
| 64 | + "Install public interface files into lib/ocaml"; |
| 65 | + "-init", String (String_call (fun path -> generate_theme_with_path := Some path)), |
| 66 | + "Init sample project to get started. Note (`bsb -init sample` will create a sample project while `bsb -init .` will reuse current directory)"; |
| 67 | + "-theme", String (String_set current_theme), |
| 68 | + "The theme for project initialization, default is basic(https://github.com/bucklescript/bucklescript/tree/master/jscomp/bsb/templates)"; |
69 | 69 |
|
70 |
| - regen, Set force_regenerate, |
71 |
| - " (internal) Always regenerate build.ninja no matter bsconfig.json is changed or not (for debugging purpose)"; |
72 |
| - "-themes", Unit Bsb_theme_init.list_themes, |
73 |
| - " List all available themes"; |
| 70 | + regen, unit_set_spec force_regenerate, |
| 71 | + "(internal) Always regenerate build.ninja no matter bsconfig.json is changed or not (for debugging purpose)"; |
| 72 | + "-themes", call_spec Bsb_theme_init.list_themes, |
| 73 | + "List all available themes"; |
74 | 74 | "-where",
|
75 |
| - Unit (fun _ -> |
| 75 | + call_spec (fun _ -> |
76 | 76 | print_endline (Filename.dirname Sys.executable_name)),
|
77 |
| - " Show where bsb.exe is located"; |
| 77 | + "Show where bsb.exe is located"; |
78 | 78 | (** Below flags are only for bsb script, it is not available for bsb.exe
|
79 | 79 | we make it at this time to make `bsb -help` easier
|
80 | 80 | *)
|
81 |
| - "-ws", Bool ignore, |
82 |
| - " [host:]port specify a websocket number (and optionally, a host). When a build finishes, we send a message to that port. For tools that listen on build completion." ; |
| 81 | + "-ws", call_spec ignore, |
| 82 | + "[host:]port specify a websocket number (and optionally, a host). When a build finishes, we send a message to that port. For tools that listen on build completion." ; |
83 | 83 | #if BS_NATIVE then
|
84 |
| - "-backend", String (fun s -> |
| 84 | + "-backend", String (String_call (fun s -> |
85 | 85 | match s with
|
86 | 86 | | "js" -> Bsb_global_backend.set_backend Bsb_config_types.Js
|
87 | 87 | | "native" -> Bsb_global_backend.set_backend Bsb_config_types.Native
|
88 | 88 | | "bytecode" -> Bsb_global_backend.set_backend Bsb_config_types.Bytecode
|
89 | 89 | | _ -> failwith "-backend should be one of: 'js', 'bytecode' or 'native'."
|
90 |
| - ), |
91 |
| - " Builds the entries specified in the bsconfig that match the given backend. Can be either 'js', 'bytecode' or 'native'."; |
| 90 | + )), |
| 91 | + "Builds the entries specified in the bsconfig that match the given backend. Can be either 'js', 'bytecode' or 'native'."; |
92 | 92 | #end
|
93 | 93 | ]
|
94 | 94 |
|
@@ -135,13 +135,16 @@ let ninja_command_exit ninja_args =
|
135 | 135 | ninja -C _build
|
136 | 136 | *)
|
137 | 137 | let usage = "Usage : bsb.exe <bsb-options> -- <ninja_options>\n\
|
138 |
| - For ninja options, try ninja -h \n\ |
| 138 | + For ninja options, try bsb.exe -- -h. \n\ |
| 139 | + Note they are supposed to be internals and not reliable.\n\ |
139 | 140 | ninja will be loaded either by just running `bsb.exe' or `bsb.exe .. -- ..`\n\
|
140 |
| - It is always recommended to run ninja via bsb.exe \n\ |
141 |
| - Bsb options are:" |
| 141 | + It is always recommended to run ninja via bsb.exe" |
142 | 142 |
|
143 |
| -let handle_anonymous_arg arg = |
144 |
| - raise (Arg.Bad ("Unknown arg \"" ^ arg ^ "\"")) |
| 143 | +let handle_anonymous_arg ~rev_args = |
| 144 | + match rev_args with |
| 145 | + | [] -> () |
| 146 | + | arg:: _ -> |
| 147 | + raise (Bsb_arg.Bad ("Unknown arg \"" ^ arg ^ "\"")) |
145 | 148 |
|
146 | 149 |
|
147 | 150 | let program_exit () =
|
@@ -199,10 +202,16 @@ let () =
|
199 | 202 | | `No_split
|
200 | 203 | ->
|
201 | 204 | begin
|
202 |
| - Arg.parse bsb_main_flags handle_anonymous_arg usage; |
| 205 | + Bsb_arg.parse_exn |
| 206 | + ~usage |
| 207 | + ~argv |
| 208 | + ~start:1 |
| 209 | + bsb_main_flags |
| 210 | + handle_anonymous_arg |
| 211 | + ; |
203 | 212 | (* first, check whether we're in boilerplate generation mode, aka -init foo -theme bar *)
|
204 | 213 | match !generate_theme_with_path with
|
205 |
| - | Some path -> Bsb_theme_init.init_sample_project ~cwd:Bsb_global_paths.cwd ~theme:!current_theme path |
| 214 | + | Some path -> Bsb_theme_init.init_sample_project ~cwd:Bsb_global_paths.cwd ~theme:!current_theme path |
206 | 215 | | None ->
|
207 | 216 | (* [-make-world] should never be combined with [-package-specs] *)
|
208 | 217 | let make_world = !make_world in
|
@@ -240,17 +249,21 @@ let () =
|
240 | 249 | | `Split (bsb_args,ninja_args)
|
241 | 250 | -> (* -make-world all dependencies fall into this category *)
|
242 | 251 | begin
|
243 |
| - Arg.parse_argv bsb_args bsb_main_flags handle_anonymous_arg usage ; |
244 |
| - let config_opt = |
245 |
| - Bsb_ninja_regen.regenerate_ninja |
| 252 | + Bsb_arg.parse_exn |
| 253 | + ~usage |
| 254 | + ~argv:bsb_args |
| 255 | + ~start:1 |
| 256 | + bsb_main_flags handle_anonymous_arg ; |
| 257 | + let config_opt = lazy |
| 258 | + (Bsb_ninja_regen.regenerate_ninja |
246 | 259 | ~toplevel_package_specs:None
|
247 | 260 | ~per_proj_dir:Bsb_global_paths.cwd
|
248 |
| - ~forced:!force_regenerate in |
| 261 | + ~forced:!force_regenerate) in |
249 | 262 | (* [-make-world] should never be combined with [-package-specs] *)
|
250 | 263 | if !make_world then
|
251 |
| - Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args; |
| 264 | + Bsb_world.make_world_deps Bsb_global_paths.cwd (Lazy.force config_opt) ninja_args; |
252 | 265 | if !do_install then
|
253 |
| - install_target config_opt; |
| 266 | + install_target (Lazy.force config_opt); |
254 | 267 | if !watch_mode then program_exit ()
|
255 | 268 | else ninja_command_exit ninja_args
|
256 | 269 | end
|
|
0 commit comments