[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
let capture = function
| Analyze->
| Analyze ->
()
| 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
capture_with_compilation_database json_cdb
| BuckGenrule path ->
L.stdout "Capturing for Buck genrule compatibility...@\n";
L.stdout "Capturing for Buck genrule compatibility...@.";
JMain.from_arguments path
| Clang (compiler, prog, args) ->
L.stdout "Capturing in make/cc mode...@.";
@ -312,7 +312,7 @@ let capture = function
()
)
| XcodeXcpretty (prog, args) ->
L.stdout "Capturing using xcodebuild and xcpretty...@\n";
L.stdout "Capturing using xcodebuild and xcpretty...@.";
check_xcpretty ();
let json_cdb =
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 =
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
| [] -> Logging.stdout "There are no files to process, exiting."; exit 0
| lines ->
Logging.out "Reading compilation database from:@\n%s@\n"
(String.concat ~sep:"\n" lines);
(* this assumes that flavors do not contain spaces *)
let split_regex = Str.regexp "#[^ ]* " in
let scan_output compilation_database_files line =
match Str.bounded_split split_regex line 2 with
| _::filename::[] ->
`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
with Unix.Unix_error (err, _, _) ->
Process.print_error_and_exit
"Cannot execute %s: %s\n%!" buck_targets_shell (Unix.error_message err)
let (output, exit_or_signal) =
Utils.with_process_in buck_targets_shell In_channel.input_lines in
match exit_or_signal with
| Error _ as status ->
failwithf "*** ERROR: command failed:@\n*** %s@\n*** %s@."
buck_targets_shell
(Unix.Exit_or_signal.to_string_hum status)
| Ok () ->
match output with
| [] -> Logging.stderr "There are no files to process, exiting@."; exit 0
| lines ->
Logging.out "Reading compilation database from:@\n%s@\n"
(String.concat ~sep:"\n" lines);
(* this assumes that flavors do not contain spaces *)
let split_regex = Str.regexp "#[^ ]* " in
let scan_output compilation_database_files line =
match Str.bounded_split split_regex line 2 with
| _::filename::[] ->
`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

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

Loading…
Cancel
Save