Skip to content

Commit 1667feb

Browse files
[clang][tools] Update Python2 code in set-xcode-analyzer to Python3 (#163737)
It wanted at least Python 3.6, LLVM's minimum is now 3.8, so remove this check. It was still using print as a statement, which was removed in 3.0 (https://docs.python.org/3/whatsnew/3.0.html#print-is-a-function). Exception syntax changed in 3.0 from "A, B" to "A as B" (https://docs.python.org/3/whatsnew/3.0.html#changed-syntax).
1 parent de2797c commit 1667feb

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

clang/tools/scan-build/bin/set-xcode-analyzer

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
# This one has the scripting bridge enabled.
66

77
import sys
8-
if sys.version_info < (3, 6):
9-
print "set-xcode-analyzer requires Python 3.6 or later"
10-
sys.exit(1)
11-
128
import os
139
import subprocess
1410
import re
@@ -18,7 +14,7 @@ import stat
1814
from AppKit import *
1915

2016
def FindClangSpecs(path):
21-
print "(+) Searching for xcspec file in: ", path
17+
print("(+) Searching for xcspec file in: ", path)
2218
for root, dirs, files in os.walk(path):
2319
for f in files:
2420
if f.endswith(".xcspec") and f.startswith("Clang LLVM"):
@@ -49,14 +45,14 @@ def ModifySpec(path, isBuiltinAnalyzer, pathToChecker):
4945
foundAnalyzer = False
5046
t.write(line)
5147
t.close()
52-
print "(+) processing:", path
48+
print("(+) processing:", path)
5349
try:
5450
shutil.copy(t.name, path)
5551
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
56-
except IOError, why:
57-
print " (-) Cannot update file:", why, "\n"
58-
except OSError, why:
59-
print " (-) Cannot update file:", why, "\n"
52+
except IOError as why:
53+
print(" (-) Cannot update file:", why, "\n")
54+
except OSError as why:
55+
print(" (-) Cannot update file:", why, "\n")
6056
os.unlink(t.name)
6157

6258
def main():
@@ -75,20 +71,20 @@ def main():
7571
# determine if Xcode is running
7672
for x in NSWorkspace.sharedWorkspace().runningApplications():
7773
if x.localizedName().find("Xcode") >= 0:
78-
print "(-) You must quit Xcode first before modifying its configuration files."
74+
print("(-) You must quit Xcode first before modifying its configuration files.")
7975
sys.exit(1)
8076

8177
isBuiltinAnalyzer = False
8278
if options.path:
8379
# Expand tildes.
8480
path = os.path.expanduser(options.path)
8581
if not path.endswith("clang"):
86-
print "(+) Using Clang bundled with checker build:", path
82+
print("(+) Using Clang bundled with checker build:", path)
8783
path = os.path.join(path, "bin", "clang");
8884
else:
89-
print "(+) Using Clang located at:", path
85+
print("(+) Using Clang located at:", path)
9086
else:
91-
print "(+) Using the Clang bundled with Xcode"
87+
print("(+) Using the Clang bundled with Xcode")
9288
path = options.default
9389
isBuiltinAnalyzer = True
9490

@@ -108,7 +104,7 @@ def main():
108104
ModifySpec(x, isBuiltinAnalyzer, path)
109105

110106
if not foundSpec:
111-
print "(-) No compiler configuration file was found. Xcode's analyzer has not been updated."
107+
print("(-) No compiler configuration file was found. Xcode's analyzer has not been updated.")
112108

113109
if __name__ == '__main__':
114110
main()

0 commit comments

Comments
 (0)