summaryrefslogtreecommitdiffstats
path: root/clang/tools/scan-build-py/libscanbuild/analyze.py
diff options
context:
space:
mode:
Diffstat (limited to 'clang/tools/scan-build-py/libscanbuild/analyze.py')
-rw-r--r--clang/tools/scan-build-py/libscanbuild/analyze.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/clang/tools/scan-build-py/libscanbuild/analyze.py b/clang/tools/scan-build-py/libscanbuild/analyze.py
index 855311d1b41..8e9f317e693 100644
--- a/clang/tools/scan-build-py/libscanbuild/analyze.py
+++ b/clang/tools/scan-build-py/libscanbuild/analyze.py
@@ -18,13 +18,16 @@ import os.path
import json
import argparse
import logging
+import tempfile
import subprocess
import multiprocessing
+import contextlib
+import datetime
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
+from libscanbuild.report import document
from libscanbuild.clang import get_checkers
from libscanbuild.compilation import split_command
@@ -190,6 +193,39 @@ def analyze_build_wrapper(cplusplus):
return result
+@contextlib.contextmanager
+def report_directory(hint, keep):
+ """ Responsible for the report directory.
+
+ hint -- could specify the parent directory of the output directory.
+ keep -- a boolean value to keep or delete the empty report directory. """
+
+ stamp_format = 'scan-build-%Y-%m-%d-%H-%M-%S-%f-'
+ stamp = datetime.datetime.now().strftime(stamp_format)
+ parent_dir = os.path.abspath(hint)
+ if not os.path.exists(parent_dir):
+ os.makedirs(parent_dir)
+ name = tempfile.mkdtemp(prefix=stamp, dir=parent_dir)
+
+ logging.info('Report directory created: %s', name)
+
+ try:
+ yield name
+ finally:
+ if os.listdir(name):
+ msg = "Run 'scan-view %s' to examine bug reports."
+ keep = True
+ else:
+ if keep:
+ msg = "Report directory '%s' contains no report, but kept."
+ else:
+ msg = "Removing directory '%s' because it contains no report."
+ logging.warning(msg, name)
+
+ if not keep:
+ os.rmdir(name)
+
+
def analyzer_params(args):
""" A group of command line arguments can mapped to command
line arguments of the analyzer. This method generates those. """
OpenPOWER on IntegriCloud