[analyzer] Modernize analyzer's Python scripts
Summary:
Fix read/write in binary format, which crashes Python 3.
Additionally, clean up redundant (as for Python 3) code and
fix a handful of flake8 warnings.
Differential Revision: https://reviews.llvm.org/D79932
diff --git a/clang/utils/analyzer/SATestBuild.py b/clang/utils/analyzer/SATestBuild.py
index 42b2658..7ca0544 100755
--- a/clang/utils/analyzer/SATestBuild.py
+++ b/clang/utils/analyzer/SATestBuild.py
@@ -75,7 +75,8 @@
level=logging.DEBUG,
format='%(asctime)s:%(levelname)s:%(name)s: %(message)s')
-class StreamToLogger(object):
+
+class StreamToLogger:
def __init__(self, logger, log_level=logging.INFO):
self.logger = logger
self.log_level = log_level
@@ -377,7 +378,7 @@
# Build and call the analyzer command.
OutputOption = "-o '%s.plist' " % os.path.join(PlistPath, FileName)
Command = CmdPrefix + OutputOption + ("'%s'" % FileName)
- LogFile = open(os.path.join(FailPath, FileName + ".stderr.txt"), "w+b")
+ LogFile = open(os.path.join(FailPath, FileName + ".stderr.txt"), "w+")
try:
if Verbose == 1:
Local.stdout.write(" Executing: %s\n" % (Command,))
@@ -432,7 +433,7 @@
os.makedirs(os.path.join(SBOutputDir, LogFolderName))
# Build and analyze the project.
- with open(BuildLogPath, "wb+") as PBuildLogFile:
+ with open(BuildLogPath, "w+") as PBuildLogFile:
if (ProjectBuildMode == 1):
downloadAndPatch(Dir, PBuildLogFile)
runCleanupScript(Dir, PBuildLogFile)
@@ -646,7 +647,7 @@
self.TasksQueue = TasksQueue
self.ResultsDiffer = ResultsDiffer
self.FailureFlag = FailureFlag
- super(TestProjectThread, self).__init__()
+ super().__init__()
# Needed to gracefully handle interrupts with Ctrl-C
self.daemon = True
@@ -700,7 +701,7 @@
def projectFileHandler():
- return open(getProjectMapPath(), "rb")
+ return open(getProjectMapPath(), "r")
def iterateOverProjects(PMapFile):
@@ -709,25 +710,26 @@
from the start.
"""
PMapFile.seek(0)
- for I in csv.reader(PMapFile):
- if (SATestUtils.isCommentCSVLine(I)):
+ for ProjectInfo in csv.reader(PMapFile):
+ if (SATestUtils.isCommentCSVLine(ProjectInfo)):
continue
- yield I
+ yield ProjectInfo
def validateProjectFile(PMapFile):
"""
Validate project file.
"""
- for I in iterateOverProjects(PMapFile):
- if len(I) != 2:
+ for ProjectInfo in iterateOverProjects(PMapFile):
+ if len(ProjectInfo) != 2:
print("Error: Rows in the ProjectMapFile should have 2 entries.")
raise Exception()
- if I[1] not in ('0', '1', '2'):
- print("Error: Second entry in the ProjectMapFile should be 0" \
+ if ProjectInfo[1] not in ('0', '1', '2'):
+ print("Error: Second entry in the ProjectMapFile should be 0"
" (single file), 1 (project), or 2(single file c++11).")
raise Exception()
+
def singleThreadedTestAll(Args, ProjectsToTest):
"""
Run all projects.
@@ -738,6 +740,7 @@
Success &= testProject(Args, *ProjArgs)
return Success
+
def multiThreadedTestAll(Args, ProjectsToTest, Jobs):
"""
Run each project in a separate thread.