From fc782a341a68a3e8b447a81bf3f6215f44b6a2a0 Mon Sep 17 00:00:00 2001 From: George Karpenkov Date: Fri, 9 Feb 2018 18:39:47 +0000 Subject: [PATCH] [analyzer] [tests] [NFC] Remove a fragile tightly-coupled component emulating parser output ...when we can just use the real parser instead. Differential Revision: https://reviews.llvm.org/D43098 llvm-svn: 324759 --- clang/utils/analyzer/CmpRuns.py | 31 ++++++++++------------------- clang/utils/analyzer/SATestBuild.py | 3 ++- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/clang/utils/analyzer/CmpRuns.py b/clang/utils/analyzer/CmpRuns.py index 68668d510d8c..4e54edda2f5e 100755 --- a/clang/utils/analyzer/CmpRuns.py +++ b/clang/utils/analyzer/CmpRuns.py @@ -102,20 +102,6 @@ class AnalysisDiagnostic: return self._data -class CmpOptions: - """ - Fake output of option parser with manually constructed options. - """ - - def __init__(self, verboseLog=None, rootA="", rootB=""): - self.rootA = rootA - self.rootB = rootB - self.verboseLog = verboseLog - self.relative_path_histogram = False - self.relative_log_path_histogram = False - self.absolute_path_histogram = False - - class AnalysisReport: def __init__(self, run, files): self.run = run @@ -322,9 +308,7 @@ def dumpScanBuildResultsDiff(dirA, dirB, opts, deleteEmpty=True): return foundDiffs, len(resultsA.diagnostics), len(resultsB.diagnostics) - -def main(): - from optparse import OptionParser +def generate_option_parser(): parser = OptionParser("usage: %prog [options] [dir A] [dir B]") parser.add_option("", "--rootA", dest="rootA", help="Prefix to ignore on source files for directory A", @@ -334,24 +318,29 @@ def main(): action="store", type=str, default="") parser.add_option("", "--verbose-log", dest="verboseLog", help="Write additional information to LOG \ - [default=None]", + [default=None]", action="store", type=str, default=None, metavar="LOG") parser.add_option("--relative-path-differences-histogram", action="store_true", dest="relative_path_histogram", default=False, help="Show histogram of relative paths differences. \ - Requires matplotlib") + Requires matplotlib") parser.add_option("--relative-log-path-differences-histogram", action="store_true", dest="relative_log_path_histogram", default=False, help="Show histogram of log relative paths differences. \ - Requires matplotlib") + Requires matplotlib") parser.add_option("--absolute-path-differences-histogram", action="store_true", dest="absolute_path_histogram", default=False, help="Show histogram of absolute paths differences. \ - Requires matplotlib") + Requires matplotlib") + return parser + + +def main(): + parser = generate_option_parser() (opts, args) = parser.parse_args() if len(args) != 2: diff --git a/clang/utils/analyzer/SATestBuild.py b/clang/utils/analyzer/SATestBuild.py index e69df4f3f844..2becaa07a7dc 100755 --- a/clang/utils/analyzer/SATestBuild.py +++ b/clang/utils/analyzer/SATestBuild.py @@ -566,7 +566,8 @@ def runCmpResults(Dir, Strictness=0): RefDir, NewDir)) PatchedSourceDirPath = os.path.join(Dir, PatchedSourceDirName) - Opts = CmpRuns.CmpOptions(rootA="", rootB=PatchedSourceDirPath) + Opts, Args = CmpRuns.generate_option_parser().parse_args( + ["", PatchedSourceDirPath]) # Scan the results, delete empty plist files. NumDiffs, ReportsInRef, ReportsInNew = \ CmpRuns.dumpScanBuildResultsDiff(RefDir, NewDir, Opts, False)