r295045 - [scan-build-py] move function report_directory from report module to analyze module
Laszlo Nagy via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 14 02:43:38 PST 2017
Author: rizsotto
Date: Tue Feb 14 04:43:38 2017
New Revision: 295045
URL: http://llvm.org/viewvc/llvm-project?rev=295045&view=rev
Log:
[scan-build-py] move function report_directory from report module to analyze module
Differential Revision: https://reviews.llvm.org/D29255
Modified:
cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
cfe/trunk/tools/scan-build-py/libscanbuild/report.py
cfe/trunk/tools/scan-build-py/tests/unit/test_analyze.py
cfe/trunk/tools/scan-build-py/tests/unit/test_report.py
Modified: cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py?rev=295045&r1=295044&r2=295045&view=diff
==============================================================================
--- cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py Tue Feb 14 04:43:38 2017
@@ -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
+ at 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. """
Modified: cfe/trunk/tools/scan-build-py/libscanbuild/report.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/report.py?rev=295045&r1=295044&r2=295045&view=diff
==============================================================================
--- cfe/trunk/tools/scan-build-py/libscanbuild/report.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/report.py Tue Feb 14 04:43:38 2017
@@ -13,54 +13,15 @@ import os
import os.path
import sys
import shutil
-import time
-import tempfile
import itertools
import plistlib
import glob
import json
import logging
-import contextlib
-import datetime
from libscanbuild import duplicate_check
from libscanbuild.clang import get_version
-__all__ = ['report_directory', 'document']
-
-
- at 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)
-
- parentdir = os.path.abspath(hint)
- if not os.path.exists(parentdir):
- os.makedirs(parentdir)
-
- name = tempfile.mkdtemp(prefix=stamp, dir=parentdir)
-
- 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' contans no report, but kept."
- else:
- msg = "Removing directory '%s' because it contains no report."
- logging.warning(msg, name)
-
- if not keep:
- os.rmdir(name)
+__all__ = ['document']
def document(args, output_dir, use_cdb):
Modified: cfe/trunk/tools/scan-build-py/tests/unit/test_analyze.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/tests/unit/test_analyze.py?rev=295045&r1=295044&r2=295045&view=diff
==============================================================================
--- cfe/trunk/tools/scan-build-py/tests/unit/test_analyze.py (original)
+++ cfe/trunk/tools/scan-build-py/tests/unit/test_analyze.py Tue Feb 14 04:43:38 2017
@@ -4,4 +4,19 @@
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
+import libear
import libscanbuild.analyze as sut
+import unittest
+
+class ReportDirectoryTest(unittest.TestCase):
+
+ # Test that successive report directory names ascend in lexicographic
+ # order. This is required so that report directories from two runs of
+ # scan-build can be easily matched up to compare results.
+ def test_directory_name_comparison(self):
+ with libear.TemporaryDirectory() as tmpdir, \
+ sut.report_directory(tmpdir, False) as report_dir1, \
+ sut.report_directory(tmpdir, False) as report_dir2, \
+ sut.report_directory(tmpdir, False) as report_dir3:
+ self.assertLess(report_dir1, report_dir2)
+ self.assertLess(report_dir2, report_dir3)
Modified: cfe/trunk/tools/scan-build-py/tests/unit/test_report.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/tests/unit/test_report.py?rev=295045&r1=295044&r2=295045&view=diff
==============================================================================
--- cfe/trunk/tools/scan-build-py/tests/unit/test_report.py (original)
+++ cfe/trunk/tools/scan-build-py/tests/unit/test_report.py Tue Feb 14 04:43:38 2017
@@ -146,16 +146,3 @@ class GetPrefixFromCompilationDatabaseTe
def test_empty(self):
self.assertEqual(
sut.commonprefix([]), '')
-
-class ReportDirectoryTest(unittest.TestCase):
-
- # Test that successive report directory names ascend in lexicographic
- # order. This is required so that report directories from two runs of
- # scan-build can be easily matched up to compare results.
- def test_directory_name_comparison(self):
- with libear.TemporaryDirectory() as tmpdir, \
- sut.report_directory(tmpdir, False) as report_dir1, \
- sut.report_directory(tmpdir, False) as report_dir2, \
- sut.report_directory(tmpdir, False) as report_dir3:
- self.assertLess(report_dir1, report_dir2)
- self.assertLess(report_dir2, report_dir3)
More information about the cfe-commits
mailing list