diff --git a/infer/lib/python/inferlib/capture/ant.py b/infer/lib/python/inferlib/capture/ant.py index 808691383..3b71265af 100644 --- a/infer/lib/python/inferlib/capture/ant.py +++ b/infer/lib/python/inferlib/capture/ant.py @@ -6,6 +6,7 @@ # of patent rights can be found in the PATENTS file in the same directory. import logging +import os from . import util from inferlib import jwlib @@ -78,6 +79,9 @@ class AntCapture: return calls def capture(self): - cmds = self.get_infer_commands(util.get_build_output(self.build_cmd)) - clean_cmd = '%s clean' % self.build_cmd[0] + (code, verbose_out) = util.get_build_output(self.build_cmd) + if code != os.EX_OK: + return code + clean_cmd = '\'{}\' clean'.format(self.build_cmd[0]) + cmds = self.get_infer_commands(verbose_out) return util.run_compilation_commands(cmds, clean_cmd) diff --git a/infer/lib/python/inferlib/capture/buck.py b/infer/lib/python/inferlib/capture/buck.py index 8e8c41e44..e5a9941d6 100644 --- a/infer/lib/python/inferlib/capture/buck.py +++ b/infer/lib/python/inferlib/capture/buck.py @@ -144,6 +144,8 @@ class BuckAnalyzer: [x for x in buck_results_cmd if x != KEEP_GOING_OPTION] proc = subprocess.Popen(buck_results_cmd, stdout=subprocess.PIPE) (buck_output, _) = proc.communicate() + if proc.returncode != 0: + return None # remove target name prefixes from each line and split them into a list out = [x.split(None, 1)[1] for x in buck_output.strip().split('\n')] return [os.path.dirname(x) @@ -240,6 +242,9 @@ class BuckAnalyzer: if not ret == os.EX_OK and not self.keep_going: return ret result_paths = self._get_analysis_result_paths() + if result_paths is None: + # huho, the Buck command to extract results paths failed + return os.EX_SOFTWARE merged_reports_path = os.path.join( self.args.infer_out, config.JSON_REPORT_FILENAME) merged_deps_path = os.path.join( diff --git a/infer/lib/python/inferlib/capture/gradle.py b/infer/lib/python/inferlib/capture/gradle.py index 0681fff82..5aee3cc59 100644 --- a/infer/lib/python/inferlib/capture/gradle.py +++ b/infer/lib/python/inferlib/capture/gradle.py @@ -83,6 +83,9 @@ class GradleCapture: def capture(self): print('Running and capturing gradle compilation...') - cmds = self.get_infer_commands(util.get_build_output(self.build_cmd)) + (code, verbose_out) = util.get_build_output(self.build_cmd) + if code != os.EX_OK: + return code + cmds = self.get_infer_commands(verbose_out) clean_cmd = '%s clean' % self.build_cmd[0] return util.run_compilation_commands(cmds, clean_cmd) diff --git a/infer/lib/python/inferlib/capture/util.py b/infer/lib/python/inferlib/capture/util.py index 32e950f89..dd807d2cd 100644 --- a/infer/lib/python/inferlib/capture/util.py +++ b/infer/lib/python/inferlib/capture/util.py @@ -25,7 +25,12 @@ def get_build_output(build_cmd): # TODO make it return generator to be able to handle large builds proc = subprocess.Popen(build_cmd, stdout=subprocess.PIPE) (verbose_out_chars, _) = proc.communicate() - return utils.decode(verbose_out_chars).split('\n') + if proc.returncode != 0: + utils.stderr( + 'ERROR: couldn\'t run compilation command `{}`'.format(build_cmd)) + return (proc.returncode, None) + out = utils.decode(verbose_out_chars).split('\n') + return (os.EX_OK, out) def run_compilation_commands(cmds, clean_cmd): @@ -33,7 +38,7 @@ def run_compilation_commands(cmds, clean_cmd): in case there is nothing to compile. """ # TODO call it in parallel - if len(cmds) == 0: + if cmds is None or len(cmds) == 0: utils.stderr('Nothing to compile. Try running `{}` first.' .format(clean_cmd)) return os.EX_NOINPUT