Skip to content

Commit

Permalink
Sync changes to upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
dsereni committed Nov 27, 2014
1 parent 679a234 commit 63f049d
Show file tree
Hide file tree
Showing 157 changed files with 1,491 additions and 388 deletions.
5 changes: 4 additions & 1 deletion Makefile
Expand Up @@ -86,6 +86,8 @@ FILES_TO_COPY=\
# Rules #
################################################################################

CC_FLAGS=-DNO_LZ4
CC_OPTS=$(foreach flag, $(CC_FLAGS), -ccopt $(flag))
INCLUDE_OPTS=$(foreach dir,$(MODULES),-I $(dir))
LIB_OPTS=$(foreach lib,$(OCAML_LIBRARIES),-lib $(lib))
NATIVE_LIB_OPTS=$(foreach lib, $(NATIVE_LIBRARIES),-cclib -l -cclib $(lib))
Expand All @@ -107,7 +109,8 @@ build-flow: build-flow-native-deps build-flowlib-archive
ocamlbuild -no-links $(INCLUDE_OPTS) $(LIB_OPTS) -lflags "$(LINKER_FLAGS)" src/flow.native

build-flow-native-deps: build-flow-stubs
ocamlbuild -cflags "$(EXTRA_INCLUDE_OPTS)" $(NATIVE_OBJECT_FILES)
ocamlbuild -ocamlc "ocamlc.opt $(EXTRA_INCLUDE_OPTS) $(CC_OPTS)"\
$(NATIVE_OBJECT_FILES)

build-flow-stubs:
echo 'const char* const BuildInfo_kRevision = "${SHA}";' > hack/utils/get_build_id.gen.c
Expand Down
7 changes: 5 additions & 2 deletions hack/Makefile
Expand Up @@ -74,7 +74,8 @@ OCAML_LIBRARIES=\
str

NATIVE_LIBRARIES=\
$(ELF)
$(ELF)\
pthread

################################################################################
# Rules #
Expand All @@ -83,12 +84,14 @@ NATIVE_LIBRARIES=\
INCLUDE_OPTS=$(foreach dir,$(MODULES),-I $(dir))
LIB_OPTS=$(foreach lib,$(OCAML_LIBRARIES),-lib $(lib))
NATIVE_LIB_OPTS=$(foreach lib, $(NATIVE_LIBRARIES),-cclib -l$(lib))
EXTRA_NATIVE_LIB_OPTS=$(foreach lib, $(EXTRA_NATIVE_LIBRARIES),-cclib -l$(lib))
EXTRA_INCLUDE_OPTS=$(foreach dir, $(EXTRA_INCLUDE_PATHS),-ccopt -I$(dir))
EXTRA_CC_OPTS=$(foreach opt, $(EXTRA_CC_FLAGS),-ccopt $(opt))
EXTRA_LIB_OPTS=$(foreach dir, $(EXTRA_LIB_PATHS),-cclib -L$(dir))
FRAMEWORK_OPTS=$(foreach framework, $(FRAMEWORKS),-cclib -framework -cclib $(framework))

LINKER_FLAGS=$(NATIVE_OBJECT_FILES) $(NATIVE_LIB_OPTS) $(EXTRA_LIB_OPTS) $(FRAMEWORK_OPTS) $(SECTCREATE)
LINKER_FLAGS=$(NATIVE_OBJECT_FILES) $(NATIVE_LIB_OPTS) $(EXTRA_LIB_OPTS) \
$(EXTRA_NATIVE_LIB_OPTS) $(FRAMEWORK_OPTS) $(SECTCREATE)

all: build-hhi-archive build-hack copy-hack-files

Expand Down
8 changes: 5 additions & 3 deletions hack/client/clientBuild.ml
Expand Up @@ -77,8 +77,8 @@ let rec main_ env retries =
| ServerMsg.PONG -> (* successful case *)
begin
let exit_code = ref 0 in
EventLogger.client_begin_work (
ClientLogCommand.LCBuild env.root);
EventLogger.client_begin_work (ClientLogCommand.LCBuild
(env.root, env.build_opts.ServerMsg.incremental));
try
while true do
let line:ServerMsg.build_progress = Marshal.from_channel ic in
Expand All @@ -87,7 +87,9 @@ let rec main_ env retries =
| ServerMsg.BUILD_ERROR s -> exit_code := 2; print_endline s
done
with End_of_file ->
exit (!exit_code)
if !exit_code = 0
then ()
else exit (!exit_code)
end
| resp -> Printf.printf "Unexpected server response %s.\n%!"
(ServerMsg.response_to_string resp)
Expand Down
22 changes: 13 additions & 9 deletions hack/client/clientCheckStatus.ml
Expand Up @@ -9,6 +9,7 @@
*)
open ClientEnv
open ClientExceptions
open Utils

module C = Tty

Expand Down Expand Up @@ -52,15 +53,10 @@ let print_error_color e =
List.iter (print_reason_color ~first:false ~code) (List.tl msg_list)

let check_status connect (args:client_check_env) =
Sys.set_signal Sys.sigalrm (Sys.Signal_handle (fun _ -> raise Server_busy));
ignore(Unix.alarm 6);

let name = "hh_server" in

(* Check if a server is up *)
if not (ClientUtils.server_exists args.root)
then begin
ignore (Unix.alarm 0);
if args.autostart
then
(* fork the server and raise an exception *)
Expand All @@ -71,10 +67,18 @@ let check_status connect (args:client_check_env) =
};
raise Server_missing
end;
let ic, oc = connect args in
ServerMsg.cmd_to_channel oc (ServerMsg.STATUS args.root);
let response = ServerMsg.response_from_channel ic in
ignore (Unix.alarm 0);
let response = with_context
~enter:(fun () ->
Sys.set_signal Sys.sigalrm (Sys.Signal_handle (fun _ ->
raise Server_busy));
ignore (Unix.alarm 6))
~exit:(fun () ->
ignore (Unix.alarm 0);
Sys.set_signal Sys.sigalrm Sys.Signal_default)
~do_:(fun () ->
let ic, oc = connect args in
ServerMsg.cmd_to_channel oc (ServerMsg.STATUS args.root);
ServerMsg.response_from_channel ic) in
match response with
| ServerMsg.SERVER_OUT_OF_DATE ->
if args.autostart
Expand Down
2 changes: 1 addition & 1 deletion hack/client/clientLogCommand.ml
Expand Up @@ -27,5 +27,5 @@
| LCStop of Path.path
| LCRestart of Path.path
| LCStatus of Path.path option
| LCBuild of Path.path
| LCBuild of Path.path * (* incremental *) bool
| LCProlog of Path.path
4 changes: 3 additions & 1 deletion hack/client/clientLogCommandUtils.ml
Expand Up @@ -17,5 +17,7 @@ let log_command_of_command = function
| C.CStop env -> LC.LCStop env.ClientStop.root
| C.CRestart env -> LC.LCRestart env.ClientStart.root
| C.CStatus env -> LC.LCStatus env.ClientStatus.root
| C.CBuild env -> LC.LCBuild env.ClientBuild.root
| C.CBuild env ->
LC.LCBuild (env.ClientBuild.root,
env.ClientBuild.build_opts.ServerMsg.incremental)
| C.CProlog env -> LC.LCProlog env.ClientProlog.root
9 changes: 4 additions & 5 deletions hack/client/clientRestart.ml
Expand Up @@ -10,8 +10,7 @@

let main env =
if ClientUtils.server_exists env.ClientStart.root
then begin
HackClientStop.kill_server env.ClientStart.root;
ClientStart.start_server env
end else Printf.fprintf stderr "Error: no server to restart for %s\n%!"
(Path.string_of_path env.ClientStart.root)
then HackClientStop.kill_server env.ClientStart.root
else Printf.fprintf stderr "Warning: no server to restart for %s\n%!"
(Path.string_of_path env.ClientStart.root);
ClientStart.start_server env
28 changes: 19 additions & 9 deletions hack/client/clientStart.ml
Expand Up @@ -9,6 +9,7 @@
*)

open ClientExceptions
open Utils

let get_hhserver () =
let server_next_to_client = (Filename.dirname Sys.argv.(0)) ^ "/hh_server" in
Expand Down Expand Up @@ -44,17 +45,20 @@ let start_server env =
let cmd = Printf.sprintf "%s %s %s" cmd
(Shell.escape_string_for_shell (Path.string_of_path env.root))
(Shell.escape_string_for_shell Build_id.build_id_ohai) in
(try Utils.exec_read cmd with _ -> "")
(try Utils.exec_read cmd with e ->
prerr_endline (Printexc.to_string e);
Printexc.print_backtrace stderr;
"")
| None -> "" in
let hh_server = Printf.sprintf "%s -d %s %s"
(get_hhserver())
(Path.string_of_path env.root)
server_options in
Printf.fprintf stderr "Server launched with the following command:\n\t%s\n%!"
hh_server;
match Unix.system hh_server with
let () = match Unix.system hh_server with
| Unix.WEXITED 0 -> ()
| _ -> (Printf.fprintf stderr "Could not start hh_server!\n"; exit 77);
| _ -> Printf.fprintf stderr "Could not start hh_server!\n"; exit 77 in
if env.wait then wait env;
()

Expand All @@ -63,12 +67,18 @@ let should_start env =
then begin
try
(* Let's ping the server to make sure it's up and not out of date *)
Sys.set_signal Sys.sigalrm (Sys.Signal_handle (fun _ -> raise Server_busy));
ignore(Unix.alarm 6);
let ic, oc = ClientUtils.connect env.root in
ServerMsg.cmd_to_channel oc ServerMsg.PING;
let response = ServerMsg.response_from_channel ic in
ignore (Unix.alarm 0);
let response = with_context
~enter:(fun () ->
Sys.set_signal Sys.sigalrm (Sys.Signal_handle (fun _ ->
raise Server_busy));
ignore (Unix.alarm 6))
~exit:(fun () ->
ignore (Unix.alarm 0);
Sys.set_signal Sys.sigalrm Sys.Signal_default)
~do_:(fun () ->
let ic, oc = ClientUtils.connect env.root in
ServerMsg.cmd_to_channel oc ServerMsg.PING;
ServerMsg.response_from_channel ic) in
match response with
| ServerMsg.PONG -> false
| ServerMsg.SERVER_OUT_OF_DATE ->
Expand Down
34 changes: 19 additions & 15 deletions hack/client/clientStop.ml
Expand Up @@ -8,6 +8,8 @@
*
*)

open Utils

exception FailedToKill

type env = {
Expand Down Expand Up @@ -35,21 +37,23 @@ module StopCommand (Config : STOP_CONFIG) : STOP_COMMAND = struct
let root = env.root in
Printf.fprintf stderr "Attempting to nicely kill server for %s\n%!"
(Path.string_of_path root);
let response = try
Sys.set_signal
Sys.sigalrm
(Sys.Signal_handle (fun _ -> raise ClientExceptions.Server_busy));
ignore(Unix.alarm 6);

let ic, oc = ClientUtils.connect root in
Config.kill_cmd_to_channel oc;
let response = Config.response_from_channel ic in
ignore (Unix.alarm 0);
response
with e -> begin
Printf.fprintf stderr "%s\n%!" (Printexc.to_string e);
raise FailedToKill
end in
let response = with_context
~enter:(fun () ->
Sys.set_signal Sys.sigalrm (Sys.Signal_handle (fun _ ->
raise ClientExceptions.Server_busy));
ignore (Unix.alarm 6))
~exit:(fun () ->
ignore (Unix.alarm 0);
Sys.set_signal Sys.sigalrm Sys.Signal_default)
~do_:(fun () ->
try
let ic, oc = ClientUtils.connect root in
Config.kill_cmd_to_channel oc;
Config.response_from_channel ic
with e -> begin
Printf.fprintf stderr "%s\n%!" (Printexc.to_string e);
raise FailedToKill
end) in
if Config.is_expected response then begin
ignore(Unix.sleep 1);
if ClientUtils.server_exists root
Expand Down

0 comments on commit 63f049d

Please sign in to comment.