From 5f57d199f3c3590f45a7683f9e38c564285c6f04 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Tue, 10 Nov 2015 11:21:10 -0800 Subject: [PATCH] print more info about ant/gradle/make/mvn capture Summary: public Print "Capturing..." message, and some info in case it fails, eg: $ cd examples/android_hello/ $ infer -- ./gradlew build Running and capturing gradle compilation... [... stuff ...] $ infer -- ./gradlew build Running and capturing gradle compilation... Nothing to compile. Try running `./gradlew clean` first. Reviewed By: jeremydubreil Differential Revision: D2637024 fb-gh-sync-id: 0e8867d --- infer/lib/python/inferlib/capture/ant.py | 3 ++- infer/lib/python/inferlib/capture/gradle.py | 4 +++- infer/lib/python/inferlib/capture/make.py | 9 +++++++++ infer/lib/python/inferlib/capture/mvn.py | 3 ++- infer/lib/python/inferlib/capture/util.py | 6 +++++- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/infer/lib/python/inferlib/capture/ant.py b/infer/lib/python/inferlib/capture/ant.py index e6a466f73..f3717a915 100644 --- a/infer/lib/python/inferlib/capture/ant.py +++ b/infer/lib/python/inferlib/capture/ant.py @@ -77,4 +77,5 @@ class AntCapture: def capture(self): cmds = self.get_infer_commands(util.get_build_output(self.build_cmd)) - return util.run_commands(cmds) + clean_cmd = '%s clean' % self.build_cmd[0] + return util.run_compilation_commands(cmds, clean_cmd) diff --git a/infer/lib/python/inferlib/capture/gradle.py b/infer/lib/python/inferlib/capture/gradle.py index 0aded3032..6a042449e 100644 --- a/infer/lib/python/inferlib/capture/gradle.py +++ b/infer/lib/python/inferlib/capture/gradle.py @@ -80,5 +80,7 @@ class GradleCapture: return calls def capture(self): + print('Running and capturing gradle compilation...') cmds = self.get_infer_commands(util.get_build_output(self.build_cmd)) - return util.run_commands(cmds) + clean_cmd = '%s clean' % self.build_cmd[0] + return util.run_compilation_commands(cmds, clean_cmd) diff --git a/infer/lib/python/inferlib/capture/make.py b/infer/lib/python/inferlib/capture/make.py index 81977ff5d..b6c9ea7e3 100644 --- a/infer/lib/python/inferlib/capture/make.py +++ b/infer/lib/python/inferlib/capture/make.py @@ -58,6 +58,15 @@ class MakeCapture: env = self.get_envvars() logging.info('Running command %s with env:\n%s' % (self.cmd, env)) subprocess.check_call(self.cmd, env=env) + capture_dir = os.path.join(self.args.infer_out, 'captured') + if len(os.listdir(capture_dir)) < 1: + # Don't return with a failure code unless we're + # running make. It could be normal to have captured + # nothing (eg, empty source file). Further output will + # alert the user that there was nothing to analyze. + if self.cmd[0] == 'make': + # reuse code from gradle, etc. integration + return util.run_compilation_commands([], 'make clean') return os.EX_OK except subprocess.CalledProcessError as exc: if self.args.debug: diff --git a/infer/lib/python/inferlib/capture/mvn.py b/infer/lib/python/inferlib/capture/mvn.py index 2f9482a28..309c099f9 100644 --- a/infer/lib/python/inferlib/capture/mvn.py +++ b/infer/lib/python/inferlib/capture/mvn.py @@ -61,4 +61,5 @@ class MavenCapture: def capture(self): cmds = self.get_infer_commands(util.get_build_output(self.build_cmd)) - return util.run_commands(cmds) + 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 14febcd6a..281e08b2a 100644 --- a/infer/lib/python/inferlib/capture/util.py +++ b/infer/lib/python/inferlib/capture/util.py @@ -33,9 +33,13 @@ def get_build_output(build_cmd): return verbose_out_chars.split('\n') -def run_commands(cmds): +def run_compilation_commands(cmds, clean_cmd): + """runs compilation commands, and suggests a project cleaning command + in case there is nothing to compile. + """ # TODO call it in parallel if len(cmds) == 0: + print('Nothing to compile. Try running `%s` first.' % clean_cmd) return os.EX_NOINPUT for cmd in cmds: if cmd.start() != os.EX_OK: