From 6b9a37f5cd8bc184d1e94dd3c72c3952300f07a8 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Fri, 7 Apr 2017 04:12:10 -0700 Subject: [PATCH] [capture] Fail when buck call fails Reviewed By: jvillard Differential Revision: D4843247 fbshipit-source-id: f99405e --- infer/src/backend/infer.ml | 8 ++-- .../integration/CaptureCompilationDatabase.ml | 43 +++++++++++-------- infer/src/integration/Clang.ml | 2 +- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/infer/src/backend/infer.ml b/infer/src/backend/infer.ml index 0e03fc400..8b79ebb11 100644 --- a/infer/src/backend/infer.ml +++ b/infer/src/backend/infer.ml @@ -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 diff --git a/infer/src/integration/CaptureCompilationDatabase.ml b/infer/src/integration/CaptureCompilationDatabase.ml index dbde16772..898c86fad 100644 --- a/infer/src/integration/CaptureCompilationDatabase.ml +++ b/infer/src/integration/CaptureCompilationDatabase.ml @@ -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 diff --git a/infer/src/integration/Clang.ml b/infer/src/integration/Clang.ml index e12203eb6..dcee59a6f 100644 --- a/infer/src/integration/Clang.ml +++ b/infer/src/integration/Clang.ml @@ -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)