]> granicus.if.org Git - clang/commitdiff
[scan-build-py] use subprocess wrapper to execute build
authorLaszlo Nagy <rizsotto.mailinglist@gmail.com>
Tue, 14 Feb 2017 10:30:50 +0000 (10:30 +0000)
committerLaszlo Nagy <rizsotto.mailinglist@gmail.com>
Tue, 14 Feb 2017 10:30:50 +0000 (10:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@295043 91177308-0d34-0410-b5e6-96231b3b80d8

tools/scan-build-py/libscanbuild/__init__.py
tools/scan-build-py/libscanbuild/analyze.py
tools/scan-build-py/libscanbuild/intercept.py

index f5adc86f78432ad433c942fcb91c2dd99c976ccf..4b5582de05f9118e2e4c14ab66c630d0ca9364d5 100644 (file)
@@ -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.
 
index 244c34b75837db946d5dce391f63f88b1d4e804f..855311d1b412b5221c46b0ca21a8dcbb6e87311c 100644 (file)
@@ -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
index 17fbc0951e4cceeb1cf52460bb0aa04ee0e06e1b..b3c55e0417d0b07b4939fb10dc5df357f1a2652f 100644 (file)
@@ -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))