[capture] Fail when buck call fails

Reviewed By: jvillard

Differential Revision: D4843247

fbshipit-source-id: f99405e
master
Dulma Churchill 8 years ago committed by Facebook Github Bot
parent 3cdb0e04f5
commit 6b9a37f5cd

@ -235,14 +235,14 @@ let capture_with_compilation_database db_files =
CaptureCompilationDatabase.capture_files_in_database compilation_database CaptureCompilationDatabase.capture_files_in_database compilation_database
let capture = function let capture = function
| Analyze-> | Analyze ->
() ()
| BuckCompilationDB (prog, args) -> | BuckCompilationDB (prog, args) ->
L.stdout "Capturing using Buck's compilation database...@\n"; L.stdout "Capturing using Buck's compilation database...@.";
let json_cdb = CaptureCompilationDatabase.get_compilation_database_files_buck ~prog ~args in let json_cdb = CaptureCompilationDatabase.get_compilation_database_files_buck ~prog ~args in
capture_with_compilation_database json_cdb capture_with_compilation_database json_cdb
| BuckGenrule path -> | BuckGenrule path ->
L.stdout "Capturing for Buck genrule compatibility...@\n"; L.stdout "Capturing for Buck genrule compatibility...@.";
JMain.from_arguments path JMain.from_arguments path
| Clang (compiler, prog, args) -> | Clang (compiler, prog, args) ->
L.stdout "Capturing in make/cc mode...@."; L.stdout "Capturing in make/cc mode...@.";
@ -312,7 +312,7 @@ let capture = function
() ()
) )
| XcodeXcpretty (prog, args) -> | XcodeXcpretty (prog, args) ->
L.stdout "Capturing using xcodebuild and xcpretty...@\n"; L.stdout "Capturing using xcodebuild and xcpretty...@.";
check_xcpretty (); check_xcpretty ();
let json_cdb = let json_cdb =
CaptureCompilationDatabase.get_compilation_database_files_xcodebuild ~prog ~args in CaptureCompilationDatabase.get_compilation_database_files_xcodebuild ~prog ~args in

@ -87,25 +87,30 @@ let get_compilation_database_files_buck ~prog ~args =
let buck_targets_shell = let buck_targets_shell =
prog :: "targets" :: "--show-output" :: args_with_flavor prog :: "targets" :: "--show-output" :: args_with_flavor
|> Utils.shell_escape_command in |> Utils.shell_escape_command in
try let (output, exit_or_signal) =
match fst @@ Utils.with_process_in buck_targets_shell In_channel.input_lines with Utils.with_process_in buck_targets_shell In_channel.input_lines in
| [] -> Logging.stdout "There are no files to process, exiting."; exit 0 match exit_or_signal with
| lines -> | Error _ as status ->
Logging.out "Reading compilation database from:@\n%s@\n" failwithf "*** ERROR: command failed:@\n*** %s@\n*** %s@."
(String.concat ~sep:"\n" lines); buck_targets_shell
(* this assumes that flavors do not contain spaces *) (Unix.Exit_or_signal.to_string_hum status)
let split_regex = Str.regexp "#[^ ]* " in | Ok () ->
let scan_output compilation_database_files line = match output with
match Str.bounded_split split_regex line 2 with | [] -> Logging.stderr "There are no files to process, exiting@."; exit 0
| _::filename::[] -> | lines ->
`Raw filename::compilation_database_files Logging.out "Reading compilation database from:@\n%s@\n"
| _ -> (String.concat ~sep:"\n" lines);
failwithf (* this assumes that flavors do not contain spaces *)
"Failed to parse `buck targets --show-output ...` line of output:@\n%s" line in let split_regex = Str.regexp "#[^ ]* " in
List.fold ~f:scan_output ~init:[] lines let scan_output compilation_database_files line =
with Unix.Unix_error (err, _, _) -> match Str.bounded_split split_regex line 2 with
Process.print_error_and_exit | _::filename::[] ->
"Cannot execute %s: %s\n%!" buck_targets_shell (Unix.error_message err) `Raw filename::compilation_database_files
| _ ->
failwithf
"Failed to parse `buck targets --show-output ...` line of output:@\n%s"
line in
List.fold ~f:scan_output ~init:[] lines
) )
| _ -> | _ ->
let cmd = String.concat ~sep:" " (prog :: args) in let cmd = String.concat ~sep:" " (prog :: args) in

@ -45,6 +45,6 @@ let capture compiler ~prog ~args =
|> function |> function
| Ok () -> () | Ok () -> ()
| Error _ as status -> | Error _ as status ->
failwithf "*** ERROR: capture command failed:@*** %s@*** %s@" failwithf "*** ERROR: capture command failed:@\n*** %s@\n*** %s@."
(String.concat ~sep:" " (prog::args)) (String.concat ~sep:" " (prog::args))
(Unix.Exit_or_signal.to_string_hum status) (Unix.Exit_or_signal.to_string_hum status)

Loading…
Cancel
Save