Index: tools/scan-build-py/libscanbuild/__init__.py =================================================================== --- tools/scan-build-py/libscanbuild/__init__.py +++ tools/scan-build-py/libscanbuild/__init__.py @@ -39,6 +39,19 @@ return os.getenv('TMPDIR', os.getenv('TEMP', os.getenv('TMP', '/tmp'))) +def run_build(command, *args, **kwargs): + """ Run and report build command execution + + :param command: array of tokens + :return: exit code of the process + """ + environment = kwargs.get('env', os.environ) + logging.debug('run build %s, in environment: %s', command, environment) + exit_code = subprocess.call(command, *args, **kwargs) + logging.debug('build finished with exit code: %d', exit_code) + return exit_code + + def run_command(command, cwd=None): """ Run a given command and report the execution. Index: tools/scan-build-py/libscanbuild/analyze.py =================================================================== --- tools/scan-build-py/libscanbuild/analyze.py +++ tools/scan-build-py/libscanbuild/analyze.py @@ -20,7 +20,8 @@ import logging import subprocess import multiprocessing -from libscanbuild import initialize_logging, tempdir, command_entry_point +from libscanbuild import initialize_logging, tempdir, command_entry_point, \ + run_build from libscanbuild.runner import run from libscanbuild.intercept import capture from libscanbuild.report import report_directory, document @@ -70,9 +71,7 @@ # run the build command with compiler wrappers which # execute the analyzer too. (interposition) environment = setup_environment(args, target_dir, bin_dir) - logging.debug('run build in environment: %s', environment) - exit_code = subprocess.call(args.build, env=environment) - logging.debug('build finished with exit code: %d', exit_code) + exit_code = run_build(args.build, env=environment) # cover report generation and bug counting number_of_bugs = document(args, target_dir, False) # set exit status as it was requested Index: tools/scan-build-py/libscanbuild/intercept.py =================================================================== --- tools/scan-build-py/libscanbuild/intercept.py +++ tools/scan-build-py/libscanbuild/intercept.py @@ -31,7 +31,7 @@ import logging import subprocess from libear import build_libear, TemporaryDirectory -from libscanbuild import command_entry_point, run_command +from libscanbuild import command_entry_point, run_build, run_command from libscanbuild import duplicate_check, tempdir, initialize_logging from libscanbuild.compilation import split_command from libscanbuild.shell import encode, decode @@ -95,9 +95,7 @@ with TemporaryDirectory(prefix='intercept-', dir=tempdir()) as tmp_dir: # run the build command environment = setup_environment(args, tmp_dir, bin_dir) - logging.debug('run build in environment: %s', environment) - exit_code = subprocess.call(args.build, env=environment) - logging.info('build finished with exit code: %d', exit_code) + exit_code = run_build(args.build, env=environment) # read the intercepted exec calls exec_traces = itertools.chain.from_iterable( parse_exec_trace(os.path.join(tmp_dir, filename))