]> granicus.if.org Git - clang/commitdiff
[analyzer] CmpRuns.cmpScanBuildResults() should be easy to call from other modules.
authorAnna Zaks <ganna@apple.com>
Mon, 12 Sep 2011 21:32:41 +0000 (21:32 +0000)
committerAnna Zaks <ganna@apple.com>
Mon, 12 Sep 2011 21:32:41 +0000 (21:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139543 91177308-0d34-0410-b5e6-96231b3b80d8

utils/analyzer/CmpRuns.py

index 739d5847734dd0ee87b02de5334ab868bac92bc0..d20cd6aa64c58be4110ad48bac277c30c0aa8b9e 100755 (executable)
@@ -44,6 +44,11 @@ class multidict:
     
 #
 
+class CmpOptions:
+    def __init__(self, verboseLog=None, root=""):
+        self.root = root
+        self.verboseLog = verboseLog
+
 class AnalysisReport:
     def __init__(self, run, files):
         self.run = run
@@ -170,23 +175,7 @@ def compareResults(A, B):
 
     return res
 
-def main():
-    from optparse import OptionParser
-    parser = OptionParser("usage: %prog [options] [dir A] [dir B]")
-    parser.add_option("", "--root", dest="root",
-                      help="Prefix to ignore on source files",
-                      action="store", type=str, default="")
-    parser.add_option("", "--verbose-log", dest="verboseLog",
-                      help="Write additional information to LOG [default=None]",
-                      action="store", type=str, default=None,
-                      metavar="LOG")
-    (opts, args) = parser.parse_args()
-
-    if len(args) != 2:
-        parser.error("invalid number of arguments")
-
-    dirA,dirB = args
-
+def cmpScanBuildResults(dirA, dirB, opts):
     # Load the run results.
     resultsA = loadResults(dirA, opts)
     resultsB = loadResults(dirB, opts)
@@ -198,21 +187,25 @@ def main():
         auxLog = None
 
     diff = compareResults(resultsA, resultsB)
+    foundDiffs = False
     for res in diff:
         a,b,confidence = res
         if a is None:
             print "ADDED: %r" % b.getReadableName()
+            foundDiffs = True
             if auxLog:
                 print >>auxLog, ("('ADDED', %r, %r)" % (b.getReadableName(),
                                                         b.getReportData()))
         elif b is None:
             print "REMOVED: %r" % a.getReadableName()
+            foundDiffs = True
             if auxLog:
                 print >>auxLog, ("('REMOVED', %r, %r)" % (a.getReadableName(),
                                                           a.getReportData()))
         elif confidence:
             print "CHANGED: %r to %r" % (a.getReadableName(),
                                          b.getReadableName())
+            foundDiffs = True
             if auxLog:
                 print >>auxLog, ("('CHANGED', %r, %r, %r, %r)" 
                                  % (a.getReadableName(),
@@ -224,7 +217,28 @@ def main():
 
     print "TOTAL REPORTS: %r" % len(resultsB.diagnostics)
     if auxLog:
-        print >>auxLog, "('TOTAL', %r)" % len(resultsB.diagnostics)
+        print >>auxLog, "('TOTAL REPORTS', %r)" % len(resultsB.diagnostics)
+    
+    return foundDiffs    
+
+def main():
+    from optparse import OptionParser
+    parser = OptionParser("usage: %prog [options] [dir A] [dir B]")
+    parser.add_option("", "--root", dest="root",
+                      help="Prefix to ignore on source files",
+                      action="store", type=str, default="")
+    parser.add_option("", "--verbose-log", dest="verboseLog",
+                      help="Write additional information to LOG [default=None]",
+                      action="store", type=str, default=None,
+                      metavar="LOG")
+    (opts, args) = parser.parse_args()
+
+    if len(args) != 2:
+        parser.error("invalid number of arguments")
+
+    dirA,dirB = args
+
+    cmpScanBuildResults(dirA, dirB, opts)    
 
 if __name__ == '__main__':
     main()