diff --git a/infer/src/.merlin b/infer/src/.merlin index 5cb595931..217b7441d 100644 --- a/infer/src/.merlin +++ b/infer/src/.merlin @@ -14,6 +14,7 @@ PKG parmap PKG ppx_compare PKG ptrees PKG sawja +PKG spawn PKG sqlite3 PKG str PKG unix diff --git a/infer/src/integration/CaptureCompilationDatabase.ml b/infer/src/integration/CaptureCompilationDatabase.ml index 1fc036cb1..bf4bdf88b 100644 --- a/infer/src/integration/CaptureCompilationDatabase.ml +++ b/infer/src/integration/CaptureCompilationDatabase.ml @@ -32,22 +32,28 @@ let sentinel_exists sentinel_opt = Option.value_map ~default:false sentinel_opt ~f:file_exists let invoke_cmd ~fail_sentinel cmd = + let create_sentinel_if_needed () = + let create_empty_file fname = Utils.with_file_out ~f:(fun _ -> ()) fname in + Option.iter fail_sentinel ~f:create_empty_file + in if sentinel_exists fail_sentinel then L.progress "E%!" - else ( - Unix.chdir cmd.cwd ; - let pid = - Unix.fork_exec ~prog:cmd.prog ~argv:[cmd.prog; ("@" ^ cmd.args); "-fsyntax-only"] - ~use_path:false () - in - let create_sentinel_if_needed () = - let create_empty_file fname = Utils.with_file_out ~f:(fun _ -> ()) fname in - Option.iter fail_sentinel ~f:create_empty_file - in - match Unix.waitpid pid with - | Ok () - -> L.progress ".%!" - | Error _ - -> L.progress "!%!" ; create_sentinel_if_needed () ) + else + try + let pid = + let prog = cmd.prog in + let argv = [prog; ("@" ^ cmd.args); "-fsyntax-only"] in + Spawn.(spawn ~cwd:(Path cmd.cwd) ~prog ~argv ()) + in + match Unix.waitpid (Pid.of_int pid) with + | Ok () + -> L.progress ".%!" + | Error _ + -> L.progress "!%!" ; create_sentinel_if_needed () + with exn -> + let trace = Printexc.get_backtrace () in + L.external_error "@\nException caught:@\n%a.@\n%s@\n" Exn.pp exn trace ; + L.progress "X%!" ; + create_sentinel_if_needed () let run_compilation_database compilation_database should_capture_file = let compilation_data =