diff --git a/infer/lib/python/infer b/infer/lib/python/infer index 9b416feed..eb93424d3 100755 --- a/infer/lib/python/infer +++ b/infer/lib/python/infer @@ -19,6 +19,7 @@ from inferlib import analyze, config, utils from inferlib.capture import make CAPTURE_PACKAGE = 'capture' +TOP_LEVEL_ENVVAR = 'TOP_LEVEL_INFER_INSTANCE_ALREADY_RUNNING' # token that identifies the end of the options for infer and the beginning # of the compilation command @@ -99,6 +100,12 @@ def create_argparser(parents=[]): def main(): + toplevel_envvar_value = os.environ.get(TOP_LEVEL_ENVVAR, None) + is_toplevel_instance = False + if toplevel_envvar_value is None: + os.environ[TOP_LEVEL_ENVVAR] = '1' + is_toplevel_instance = True + to_parse, cmd = split_args_to_parse() # get the module name (if any), then load it capture_module_name = os.path.basename(cmd[0]) if len(cmd) > 0 else None @@ -179,6 +186,18 @@ def main(): analysis.analyze_and_report() analysis.save_stats() + if is_toplevel_instance is True: + buck_out_for_stats_aggregator = None + if (mod_name == 'buck' and + os.path.isfile( + os.path.join(args.infer_out, + config.INFER_BUCK_DEPS_FILENAME))): + buck_out_for_stats_aggregator = 'buck-out' + logging.info('Aggregating stats') + output = utils.run_infer_stats_aggregator( + args.infer_out, buck_out_for_stats_aggregator) + logging.info(output) + if args.fail_on_bug: bugs_filename = os.path.join(args.infer_out, config.JSON_REPORT_FILENAME) diff --git a/infer/lib/python/inferlib/utils.py b/infer/lib/python/inferlib/utils.py index 7412aa855..1cabb60a1 100644 --- a/infer/lib/python/inferlib/utils.py +++ b/infer/lib/python/inferlib/utils.py @@ -129,6 +129,22 @@ def infer_key(analyzer): return os.pathsep.join([analyzer, infer_version()]) +def run_infer_stats_aggregator(infer_out, buck_out=None): + buck_out_args = [] + if buck_out is not None: + buck_out_args = ['--buck-out', buck_out] + try: + cmd = get_cmd_in_bin_dir('InferStatsAggregator') + return subprocess.check_output( + [cmd, '--results-dir', infer_out] + buck_out_args, + stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as exc: + output = 'Error while aggregating stats ({ec}): {output}'\ + .format(ec=exc.returncode, output=exc.output) + stderr(output) + return output + + def vcs_branch(dir='.'): cwd = os.getcwd() devnull = open(os.devnull, 'w')