diff options
author | Laszlo Nagy <rizsotto.mailinglist@gmail.com> | 2017-02-14 10:43:38 +0000 |
---|---|---|
committer | Laszlo Nagy <rizsotto.mailinglist@gmail.com> | 2017-02-14 10:43:38 +0000 |
commit | 258ff25bbce734e8826a7d2275392a46bc7e3bcd (patch) | |
tree | e6527e6b29a3783465ab5fea299fc5f11ab8df87 /clang/tools/scan-build-py/libscanbuild/analyze.py | |
parent | 93a8e9df44ee2e858f29c64fb68ae840e34de879 (diff) | |
download | llvm-258ff25bbce734e8826a7d2275392a46bc7e3bcd.zip llvm-258ff25bbce734e8826a7d2275392a46bc7e3bcd.tar.gz llvm-258ff25bbce734e8826a7d2275392a46bc7e3bcd.tar.bz2 |
[scan-build-py] move function report_directory from report module to analyze module
Differential Revision: https://reviews.llvm.org/D29255
llvm-svn: 295045
Diffstat (limited to 'clang/tools/scan-build-py/libscanbuild/analyze.py')
-rw-r--r-- | clang/tools/scan-build-py/libscanbuild/analyze.py | 38 |
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 855311d..8e9f317 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. """ |