diff options
author | Laszlo Nagy <rizsotto.mailinglist@gmail.com> | 2017-02-14 10:30:50 +0000 |
---|---|---|
committer | Laszlo Nagy <rizsotto.mailinglist@gmail.com> | 2017-02-14 10:30:50 +0000 |
commit | 631669a87f577d97dbef3774f095ffd560334da3 (patch) | |
tree | 9386e55a41c97e473803e760cd539e8aad956ee7 /tools/scan-build-py | |
parent | c644cb6f1e7f85c9b918b6d4917dd161aa207960 (diff) | |
download | clang-631669a87f577d97dbef3774f095ffd560334da3.tar.gz |
[scan-build-py] use subprocess wrapper to execute build
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@295043 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/scan-build-py')
-rw-r--r-- | tools/scan-build-py/libscanbuild/__init__.py | 13 | ||||
-rw-r--r-- | tools/scan-build-py/libscanbuild/analyze.py | 7 | ||||
-rw-r--r-- | tools/scan-build-py/libscanbuild/intercept.py | 6 |
3 files changed, 18 insertions, 8 deletions
diff --git a/tools/scan-build-py/libscanbuild/__init__.py b/tools/scan-build-py/libscanbuild/__init__.py index f5adc86f78..4b5582de05 100644 --- a/tools/scan-build-py/libscanbuild/__init__.py +++ b/tools/scan-build-py/libscanbuild/__init__.py @@ -39,6 +39,19 @@ def tempdir(): 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. diff --git a/tools/scan-build-py/libscanbuild/analyze.py b/tools/scan-build-py/libscanbuild/analyze.py index 244c34b758..855311d1b4 100644 --- a/tools/scan-build-py/libscanbuild/analyze.py +++ b/tools/scan-build-py/libscanbuild/analyze.py @@ -20,7 +20,8 @@ import argparse 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 @@ def analyze_build_main(bin_dir, from_build_command): # 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 diff --git a/tools/scan-build-py/libscanbuild/intercept.py b/tools/scan-build-py/libscanbuild/intercept.py index 17fbc0951e..b3c55e0417 100644 --- a/tools/scan-build-py/libscanbuild/intercept.py +++ b/tools/scan-build-py/libscanbuild/intercept.py @@ -31,7 +31,7 @@ import argparse 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 @@ def capture(args, bin_dir): 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)) |