]> granicus.if.org Git - clang/commitdiff
[scan-build-py] move function report_directory from report module to analyze module
authorLaszlo Nagy <rizsotto.mailinglist@gmail.com>
Tue, 14 Feb 2017 10:43:38 +0000 (10:43 +0000)
committerLaszlo Nagy <rizsotto.mailinglist@gmail.com>
Tue, 14 Feb 2017 10:43:38 +0000 (10:43 +0000)
Differential Revision: https://reviews.llvm.org/D29255

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@295045 91177308-0d34-0410-b5e6-96231b3b80d8

tools/scan-build-py/libscanbuild/analyze.py
tools/scan-build-py/libscanbuild/report.py
tools/scan-build-py/tests/unit/test_analyze.py
tools/scan-build-py/tests/unit/test_report.py

index 855311d1b412b5221c46b0ca21a8dcbb6e87311c..8e9f317e693301bf20fac5c31c4d00350c5f1aaa 100644 (file)
@@ -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. """
index 766ddef7199093dcba906cf85eb2838733bf7193..83b581b79fc17c237dfd438debc98ac0a76278f8 100644 (file)
@@ -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']
-
-
-@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):
index 481cc0c0993b9f93ed0f7c9a525f3849650bfa93..5cfc12126630d1c69f11b093f95b60aebdcd6165 100644 (file)
@@ -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)
index c82b5593e0dc771285603527cd210d92ed931e48..3f249ce2aa0c8b33b548aadb1bcd2e93d476aa68 100644 (file)
@@ -146,16 +146,3 @@ class GetPrefixFromCompilationDatabaseTest(unittest.TestCase):
     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)