[driver] Improvements to buck compilation database mode

Reviewed By: jvillard

Differential Revision: D4835415

fbshipit-source-id: 2a44d7e
master
Dulma Churchill 8 years ago committed by Facebook Github Bot
parent 5503487704
commit 830b185e6a

@ -72,7 +72,7 @@ let string_of_build_system build_system =
type driver_mode =
| Analyze
| BuckGenrule of string
| BuckCompilationDB
| BuckCompilationDB of string * string list
| Clang of Clang.compiler * string * string list
| ClangCompilationDB of [ `Escaped of string | `Raw of string ] list
| Javac of Javac.compiler * string * string list
@ -92,7 +92,7 @@ let pp_driver_mode fmt driver_mode =
with exn ->
F.fprintf fmt " Error reading file '%s':@\n %a@." fname Exn.pp exn in
match driver_mode with
| Analyze | BuckGenrule _ | BuckCompilationDB | ClangCompilationDB _ | PythonCapture (_,_)
| Analyze | BuckGenrule _ | BuckCompilationDB _ | ClangCompilationDB _ | PythonCapture (_,_)
| XcodeXcpretty _ ->
(* these are pretty boring, do not log anything *)
()
@ -119,6 +119,7 @@ let pp_driver_mode fmt driver_mode =
in case nothing got captured. *)
let clean_compilation_command driver_mode =
match driver_mode with
| BuckCompilationDB (prog, _)
| Clang (_, prog, _) ->
Some (prog ^ " clean")
| XcodeXcpretty (prog, args) ->
@ -236,9 +237,9 @@ let capture_with_compilation_database db_files =
let capture = function
| Analyze->
()
| BuckCompilationDB ->
| BuckCompilationDB (prog, args) ->
L.stdout "Capturing using Buck's compilation database...@\n";
let json_cdb = CaptureCompilationDatabase.get_compilation_database_files_buck () in
let json_cdb = CaptureCompilationDatabase.get_compilation_database_files_buck ~prog ~args in
capture_with_compilation_database json_cdb
| BuckGenrule path ->
L.stdout "Capturing for Buck genrule compatibility...@\n";
@ -453,7 +454,7 @@ let driver_mode_of_build_cmd build_cmd =
| BAnalyze ->
Analyze
| BBuck when Option.is_some Config.buck_compilation_database ->
BuckCompilationDB
BuckCompilationDB (prog, List.append args (List.rev Config.buck_build_args))
| BClang ->
Clang (Clang.Clang, prog, args)
| BMake ->

@ -31,7 +31,7 @@ let create_process_and_wait ~prog ~args =
|> function
| Ok () -> ()
| Error err as status ->
L.do_err "Executing: %s@\n%s@\n"
L.stderr "Executing: %s@\n%s@\n"
(String.concat ~sep:" " (prog :: args)) (Unix.Exit_or_signal.to_string_hum status) ;
exit (match err with `Exit_non_zero i -> i | `Signal _ -> 1)

@ -79,14 +79,13 @@ let run_compilation_database compilation_database should_capture_file =
(run_compilation_file compilation_database) job_to_string
(** Computes the compilation database files. *)
let get_compilation_database_files_buck () =
let cmd = List.rev_append Config.rest (List.rev Config.buck_build_args) in
match Buck.add_flavors_to_buck_command cmd with
| buck :: build :: args_with_flavor -> (
let get_compilation_database_files_buck ~prog ~args =
match Buck.add_flavors_to_buck_command args with
| build :: args_with_flavor -> (
let build_args = build :: "--config" :: "*//cxx.pch_enabled=false" :: args_with_flavor in
Process.create_process_and_wait ~prog:buck ~args:build_args;
Process.create_process_and_wait ~prog ~args:build_args;
let buck_targets_shell =
buck :: "targets" :: "--show-output" :: args_with_flavor
prog :: "targets" :: "--show-output" :: args_with_flavor
|> Utils.shell_escape_command in
try
match fst @@ Utils.with_process_in buck_targets_shell In_channel.input_lines with
@ -109,7 +108,7 @@ let get_compilation_database_files_buck () =
"Cannot execute %s: %s\n%!" buck_targets_shell (Unix.error_message err)
)
| _ ->
let cmd = String.concat ~sep:" " cmd in
let cmd = String.concat ~sep:" " (prog :: args) in
Process.print_error_and_exit "Incorrect buck command: %s. Please use buck build <targets>" cmd
(** Compute the compilation database files. *)

@ -19,7 +19,8 @@ val capture_file_in_database : CompilationDatabase.t -> SourceFile.t -> unit
(** Get the compilation database files that contain the compilation given by the
buck command. It will be the compilation of the passed targets only or also
the dependencies according to the flag --buck-compilation-database deps | no-deps *)
val get_compilation_database_files_buck : unit -> [> `Raw of string ] list
val get_compilation_database_files_buck : prog:string -> args:string list ->
[> `Raw of string ] list
(** Get the compilation database files that contain the compilation given by the
xcodebuild command, using xcpretty. *)

Loading…
Cancel
Save