]> granicus.if.org Git - clang/commitdiff
[analyzer] CmpRuns.py: Accept single files as input.
authorJordan Rose <jordan_rose@apple.com>
Sat, 23 Mar 2013 01:21:26 +0000 (01:21 +0000)
committerJordan Rose <jordan_rose@apple.com>
Sat, 23 Mar 2013 01:21:26 +0000 (01:21 +0000)
This allows us to compare two direct invocations of the analyzer on a
single source file without having to wrap the output plists in their
own directories.

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

utils/analyzer/CmpRuns.py

index bca02124eec9add35c43d2a607cc3cbd0ed14a88..30157bed3d4218f105f4d24ea6bb04027196bcd0 100755 (executable)
@@ -138,6 +138,46 @@ class AnalysisRun:
     def getClangVersion(self):
         return self.clang_version
 
+    def readSingleFile(self, p, deleteEmpty):
+        data = plistlib.readPlist(p)
+
+        # We want to retrieve the clang version even if there are no 
+        # reports. Assume that all reports were created using the same 
+        # clang version (this is always true and is more efficient).
+        if 'clang_version' in data:
+            if self.clang_version == None:
+                self.clang_version = data.pop('clang_version')
+            else:
+                data.pop('clang_version')
+
+        # Ignore/delete empty reports.
+        if not data['files']:
+            if deleteEmpty == True:
+                os.remove(p)
+            return
+
+        # Extract the HTML reports, if they exists.
+        if 'HTMLDiagnostics_files' in data['diagnostics'][0]:
+            htmlFiles = []
+            for d in data['diagnostics']:
+                # FIXME: Why is this named files, when does it have multiple
+                # files?
+                assert len(d['HTMLDiagnostics_files']) == 1
+                htmlFiles.append(d.pop('HTMLDiagnostics_files')[0])
+        else:
+            htmlFiles = [None] * len(data['diagnostics'])
+            
+        report = AnalysisReport(self, data.pop('files'))
+        diagnostics = [AnalysisDiagnostic(d, report, h) 
+                       for d,h in zip(data.pop('diagnostics'),
+                                      htmlFiles)]
+
+        assert not data
+
+        report.diagnostics.extend(diagnostics)
+        self.reports.append(report)
+        self.diagnostics.extend(diagnostics)
+
 
 # Backward compatibility API. 
 def loadResults(path, opts, root = "", deleteEmpty=True):
@@ -150,52 +190,17 @@ def loadResults(path, opts, root = "", deleteEmpty=True):
 def loadResultsFromSingleRun(info, deleteEmpty=True):
     path = info.path
     run = AnalysisRun(info)
-    
-    for (dirpath, dirnames, filenames) in os.walk(path):
-        for f in filenames:
-            if (not f.endswith('plist')):
-                continue
-    
-            p = os.path.join(dirpath, f)
-            data = plistlib.readPlist(p)
-    
-            # We want to retrieve the clang version even if there are no 
-            # reports. Assume that all reports were created using the same 
-            # clang version (this is always true and is more efficient).
-            if ('clang_version' in data) :
-                if (run.clang_version == None) :
-                    run.clang_version = data.pop('clang_version')
-                else:
-                    data.pop('clang_version')
-                
-            # Ignore/delete empty reports.
-            if not data['files']:
-                if deleteEmpty == True:
-                    os.remove(p)
-                continue
-    
-            # Extract the HTML reports, if they exists.
-            if 'HTMLDiagnostics_files' in data['diagnostics'][0]:
-                htmlFiles = []
-                for d in data['diagnostics']:
-                    # FIXME: Why is this named files, when does it have multiple
-                    # files?
-                    assert len(d['HTMLDiagnostics_files']) == 1
-                    htmlFiles.append(d.pop('HTMLDiagnostics_files')[0])
-            else:
-                htmlFiles = [None] * len(data['diagnostics'])
-            
-            report = AnalysisReport(run, data.pop('files'))
-            diagnostics = [AnalysisDiagnostic(d, report, h) 
-                           for d,h in zip(data.pop('diagnostics'),
-                                          htmlFiles)]
-    
-            assert not data
-            
-            report.diagnostics.extend(diagnostics)
-            run.reports.append(report)
-            run.diagnostics.extend(diagnostics)
-            
+
+    if os.path.isfile(path):
+        run.readSingleFile(path, deleteEmpty)
+    else:
+        for (dirpath, dirnames, filenames) in os.walk(path):
+            for f in filenames:
+                if (not f.endswith('plist')):
+                    continue
+                p = os.path.join(dirpath, f)
+                run.readSingleFile(p, deleteEmpty)
+
     return run
 
 def cmpAnalysisDiagnostic(d) :