Skip to content

Commit

Permalink
Revert "whitespace cleanup"
Browse files Browse the repository at this point in the history
This reverts commit 7a7843e8bdaca4b421d513c1e4dc3e9ff2d392b4.
  • Loading branch information
rauanmayemir committed Mar 16, 2018
1 parent b5c7af6 commit f4df56f
Show file tree
Hide file tree
Showing 4 changed files with 3,336 additions and 3,335 deletions.
22 changes: 11 additions & 11 deletions jscomp/bsb/bsb_clean.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(* Copyright (C) 2017 Authors of BuckleScript
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand All @@ -17,7 +17,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
Expand All @@ -30,23 +30,23 @@ let ninja_clean ~nested bsc_dir proj_dir =
try
let cmd = "ninja.exe" in
let cwd = proj_dir // nested // Bsb_config.lib_bs in
if Sys.file_exists cwd then
let eid =
if Sys.file_exists cwd then
let eid =
(Bsb_unix.run_command_execv { cmd ; args = [|cmd; "-t"; "clean"|] ; cwd ; env = (Unix.environment ()) }) in
if eid <> 0 then
if eid <> 0 then
Bsb_log.warn "@{<warning>ninja clean failed@}@."
with e ->
with e ->
Bsb_log.warn "@{<warning>ninja clean failed@} : %s @." (Printexc.to_string e)

let clean_bs_garbage ?(nested="") bsc_dir proj_dir =
Bsb_log.info "@{<info>Cleaning:@} in %s@." proj_dir ;
Bsb_log.info "@{<info>Cleaning:@} in %s@." proj_dir ;
let aux x =
let x = (proj_dir // x) in
if Sys.file_exists x then
Bsb_unix.remove_dir_recursive x in
try
ninja_clean ~nested bsc_dir proj_dir ;
List.iter aux Bsb_config.all_lib_artifacts;
try
ninja_clean ~nested bsc_dir proj_dir ;
List.iter aux Bsb_config.all_lib_artifacts;
with
e ->
Bsb_log.warn "@{<warning>Failed@} to clean due to %s" (Printexc.to_string e)
Expand All @@ -67,7 +67,7 @@ let clean_bs_deps ~is_cmdline_build_kind_set ~nested bsc_dir proj_dir =
)
end

let clean_self ~is_cmdline_build_kind_set ~nested bsc_dir proj_dir =
let clean_self ~is_cmdline_build_kind_set ~nested bsc_dir proj_dir =
if is_cmdline_build_kind_set then
clean_bs_garbage ~nested bsc_dir proj_dir
else begin
Expand Down
133 changes: 67 additions & 66 deletions jscomp/bsb/bsb_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@

let cwd = Sys.getcwd ()
let bsc_dir = Bsb_build_util.get_bsc_dir cwd
let () = Bsb_log.setup ()
let () = Bsb_log.setup ()
let (//) = Ext_path.combine
let force_regenerate = ref false
let exec = ref false
let node_lit = "node"
let current_theme = ref "basic"
let set_theme s = current_theme := s
let set_theme s = current_theme := s
let generate_theme_with_path = ref None
let regen = "-regen"
let separator = "--"
let watch_mode = ref false
let make_world = ref false
let make_world = ref false
let set_make_world () = make_world := true
let bs_version_string = Bs_version.version

let cmdline_build_kind = ref Bsb_config_types.Js
(* Used only for "-clean" and "-clean-world" to track what artifacts should be
cleaned. Those arguments are trigger happy (ie as soon as they're parsed they
(* Used only for "-clean" and "-clean-world" to track what artifacts should be
cleaned. Those arguments are trigger happy (ie as soon as they're parsed they
run the command associated with them) so them and -backend are order dependent.
To (kinda) counter-act that we track if -backend was set. If not we clean
everything but if yes we clean what was specified. That's to avoid the
To (kinda) counter-act that we track if -backend was set. If not we clean
everything but if yes we clean what was specified. That's to avoid the
problems that could be caused by someone expecting their bytecode artifacts
to be clean but they're putting the -backend arg after the -clean-world arg
to be clean but they're putting the -backend arg after the -clean-world arg
making it clean the JS artifacts. Have fun with that lol
Ben - August 9th 2017
Ben - August 9th 2017
*)
let is_cmdline_build_kind_set = ref false

Expand All @@ -63,29 +63,29 @@ let get_backend () =
if !is_cmdline_build_kind_set then
!cmdline_build_kind
else
let entries = Bsb_config_parse.entries_from_bsconfig () in
let entries = Bsb_config_parse.entries_from_bsconfig () in
begin match List.hd entries with
| Bsb_config_types.JsTarget _ -> Bsb_config_types.Js
| Bsb_config_types.NativeTarget _ -> Bsb_config_types.Native
| Bsb_config_types.BytecodeTarget _ -> Bsb_config_types.Bytecode
end
end

let get_string_backend = function
| Bsb_config_types.Js -> "js"
| Bsb_config_types.Native -> "native"
| Bsb_config_types.Bytecode -> "bytecode"


let print_version_string () =
let print_version_string () =
print_string bs_version_string;
print_newline ();
exit 0
print_newline ();
exit 0

let bsb_main_flags : (string * Arg.spec * string) list=
[
"-v", Arg.Unit print_version_string,
"-v", Arg.Unit print_version_string,
" Print version and exit";
"-version", Arg.Unit print_version_string,
"-version", Arg.Unit print_version_string,
" Print version and exit";
"-verbose", Arg.Unit Bsb_log.verbose,
" Set the output(from bsb) to be verbose";
Expand All @@ -94,7 +94,7 @@ let bsb_main_flags : (string * Arg.spec * string) list=
"-no-color", Arg.Clear Bsb_log.color_enabled,
" forced no color output";
"-w", Arg.Set watch_mode,
" Watch mode" ;
" Watch mode" ;
regen, Arg.Set force_regenerate,
" (internal) Always regenerate build.ninja no matter bsconfig.json is changed or not (for debugging purpose)"
;
Expand All @@ -114,11 +114,11 @@ let bsb_main_flags : (string * Arg.spec * string) list=
"-themes", Arg.Unit Bsb_theme_init.list_themes,
" List all available themes";
"-where",
Arg.Unit (fun _ ->
Arg.Unit (fun _ ->
print_endline (Filename.dirname Sys.executable_name)),
" Show where bsb.exe is located";

"-backend", Arg.String (fun s ->
"-backend", Arg.String (fun s ->
is_cmdline_build_kind_set := true;
match s with
| "js" -> cmdline_build_kind := Bsb_config_types.Js
Expand All @@ -138,48 +138,48 @@ let bsb_main_flags : (string * Arg.spec * string) list=
(** Invariant: it has to be the last command of [bsb] *)
let exec_command_then_exit command =
Bsb_log.info "@{<info>CMD:@} %s@." command;
exit (Sys.command command )
exit (Sys.command command )

(* Execute the underlying ninja build call, then exit (as opposed to keep watching) *)
let ninja_command_exit vendor_ninja ninja_args nested build_library =
let ninja_args_len = Array.length ninja_args in
if Ext_sys.is_windows_or_cygwin then
let path_ninja = Filename.quote vendor_ninja in
exec_command_then_exit @@
(if ninja_args_len = 0 then
let path_ninja = Filename.quote vendor_ninja in
exec_command_then_exit @@
(if ninja_args_len = 0 then
Ext_string.inter3
path_ninja "-C" Bsb_config.lib_bs // nested
else
let args =
Array.append
else
let args =
Array.append
[| path_ninja ; "-C"; Bsb_config.lib_bs // nested|]
ninja_args in
ninja_args in
Ext_string.concat_array Ext_string.single_space args)
else
let ninja_common_args = [|"ninja.exe"; "-C"; Bsb_config.lib_bs // nested |] in
let args =
if ninja_args_len = 0 then ninja_common_args else
Array.append ninja_common_args ninja_args in
let ninja_common_args = [|"ninja.exe"; "-C"; Bsb_config.lib_bs // nested |] in
let args =
if ninja_args_len = 0 then ninja_common_args else
Array.append ninja_common_args ninja_args in
Bsb_log.info_args args ;
let environment = Unix.environment () in
let environment = (Array.append environment [| "BSB_BACKEND=" ^ nested |]) in
if build_library then
if Unix.fork () = 0 then
if Unix.fork () = 0 then
Unix.execvpe vendor_ninja args environment
else begin
let nested = "native" in
let ninja_common_args = [|"ninja.exe"; "-C"; Bsb_config.lib_bs // nested |] in
let args =
if ninja_args_len = 0 then ninja_common_args else
Array.append ninja_common_args ninja_args in
let ninja_common_args = [|"ninja.exe"; "-C"; Bsb_config.lib_bs // nested |] in
let args =
if ninja_args_len = 0 then ninja_common_args else
Array.append ninja_common_args ninja_args in
Bsb_log.info_args args ;
let environment = Unix.environment () in
let environment = (Array.append environment [| "BSB_BACKEND=" ^ nested |]) in
Unix.execvpe vendor_ninja args environment
end
else
Unix.execvpe vendor_ninja args environment




Expand All @@ -203,9 +203,9 @@ let handle_anonymous_arg arg =
let watch_exit () =
exit 0
(* Bsb_log.info "@{<info>Watching@}... @.";
(* @Incomplete windows support here. We need to pass those args to the nodejs file.
(* @Incomplete windows support here. We need to pass those args to the nodejs file.
Didn't bother for now.
Ben - July 23rd 2017
Ben - July 23rd 2017
*)
let backend = "-backend" in
let backend_kind = get_string_backend (get_backend ()) in
Expand All @@ -228,7 +228,7 @@ let () =
let vendor_ninja = "ninja.exe" in
match Sys.argv with
(* Both of those are equivalent and the watcher will always pass in the `-backend` flag. *)
| [| _; "-backend"; _ |]
| [| _; "-backend"; _ |]
| [| _ |] -> (* specialize this path [bsb.exe] which is used in watcher *)
begin
(* Quickly parse the backend argument to make sure we're building to the right target. *)
Expand All @@ -237,14 +237,14 @@ let () =
let backend = get_backend () in

(* print_endline __LOC__; *)
(* TODO(sansouci): Optimize this. Not passing acc_libraries_for_linking
will cause regenerate_ninja to re-crawl the external dep graph (only
(* TODO(sansouci): Optimize this. Not passing acc_libraries_for_linking
will cause regenerate_ninja to re-crawl the external dep graph (only
for Native and Bytecode). *)
let _config_opt =
Bsb_ninja_regen.regenerate_ninja
~override_package_specs:None
let _config_opt =
Bsb_ninja_regen.regenerate_ninja
~override_package_specs:None
~is_top_level:true
~not_dev:false
~not_dev:false
~generate_watch_metadata:true
~root_project_dir:cwd
~forced:true
Expand All @@ -256,7 +256,7 @@ let () =
let nested = get_string_backend backend in
ninja_command_exit vendor_ninja [||] nested !build_library
end
| argv ->
| argv ->
begin
match Ext_array.find_and_split argv Ext_string.equal separator with
| `No_split
Expand All @@ -266,13 +266,13 @@ let () =
(* first, check whether we're in boilerplate generation mode, aka -init foo -theme bar *)
match !generate_theme_with_path with
| Some path -> Bsb_theme_init.init_sample_project ~cwd ~theme:!current_theme path
| None ->
| None ->
let backend = get_backend () in

(* [-make-world] should never be combined with [-package-specs] *)
let make_world = !make_world in
let make_world = !make_world in
begin match make_world, !force_regenerate, !build_library with
| false, false, false ->
| false, false, false ->
(* [regenerate_ninja] is not triggered in this case
There are several cases we wish ninja will not be triggered.
[bsb -clean-world]
Expand All @@ -289,12 +289,12 @@ let () =
Some (Bsb_world.make_world_deps cwd ~root_project_dir:cwd ~backend)
else None in
(* don't regenerate files when we only run [bsb -clean-world] *)
let _ = Bsb_ninja_regen.regenerate_ninja
?acc_libraries_for_linking
~generate_watch_metadata:true
~override_package_specs:None
let _ = Bsb_ninja_regen.regenerate_ninja
?acc_libraries_for_linking
~generate_watch_metadata:true
~override_package_specs:None
~is_top_level:true
~not_dev:false
~not_dev:false
~root_project_dir:cwd
~forced:force_regenerate
~build_library
Expand All @@ -318,14 +318,14 @@ let () =
-> (* -make-world all dependencies fall into this category *)
begin
Arg.parse_argv bsb_args bsb_main_flags handle_anonymous_arg usage ;

let backend = get_backend () in

(* [-make-world] should never be combined with [-package-specs] *)
let acc_libraries_for_linking = if !make_world then
let acc_libraries_for_linking = if !make_world then
Some (Bsb_world.make_world_deps cwd ~root_project_dir:cwd ~backend)
else None in
let _ = Bsb_ninja_regen.regenerate_ninja
let _ = Bsb_ninja_regen.regenerate_ninja
?acc_libraries_for_linking
~generate_watch_metadata:true
~override_package_specs:None
Expand All @@ -337,30 +337,31 @@ let () =
~backend
cwd bsc_dir ocaml_dir in
if !watch_mode then watch_exit ()
else begin
else begin
Opam_of_packagejson.generate cwd;
let nested = get_string_backend backend in
ninja_command_exit vendor_ninja ninja_args nested !build_library
end
end
end
end
with
with
| Bsb_exception.Error e ->
Bsb_exception.print Format.err_formatter e ;
Format.pp_print_newline Format.err_formatter ();
exit 2
| Ext_json_parse.Error (start,_,e) ->
| Ext_json_parse.Error (start,_,e) ->
Format.fprintf Format.err_formatter
"File %S, line %d\n\
@{<error>Error:@} %a@."
start.pos_fname start.pos_lnum
Ext_json_parse.report_error e ;
exit 2
| Arg.Bad s
| Sys_error s ->
| Arg.Bad s
| Sys_error s ->
Format.fprintf Format.err_formatter
"@{<error>Error:@} %s@."
s ;
exit 2
| e -> Ext_pervasives.reraise e
| e -> Ext_pervasives.reraise e

Loading

0 comments on commit f4df56f

Please sign in to comment.