r177804 - [analyzer] CmpRuns.py: Accept single files as input.

Jordan Rose jordan_rose at apple.com
Fri Mar 22 18:21:26 PDT 2013


Author: jrose
Date: Fri Mar 22 20:21:26 2013
New Revision: 177804

URL: http://llvm.org/viewvc/llvm-project?rev=177804&view=rev
Log:
[analyzer] CmpRuns.py: Accept single files as input.

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.

Modified:
    cfe/trunk/utils/analyzer/CmpRuns.py

Modified: cfe/trunk/utils/analyzer/CmpRuns.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/analyzer/CmpRuns.py?rev=177804&r1=177803&r2=177804&view=diff
==============================================================================
--- cfe/trunk/utils/analyzer/CmpRuns.py (original)
+++ cfe/trunk/utils/analyzer/CmpRuns.py Fri Mar 22 20:21:26 2013
@@ -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 = "", d
 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) :





More information about the cfe-commits mailing list