From e30024c96f88578fb7666d6d76977e4834127919 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Sat, 23 Mar 2013 01:21:26 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177804 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/analyzer/CmpRuns.py | 97 ++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 46 deletions(-) diff --git a/utils/analyzer/CmpRuns.py b/utils/analyzer/CmpRuns.py index bca02124ee..30157bed3d 100755 --- a/utils/analyzer/CmpRuns.py +++ b/utils/analyzer/CmpRuns.py @@ -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) : -- 2.40.0