- Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathsil-opt-verify-all-modules.py
executable file
·170 lines (140 loc) · 5.63 KB
/
sil-opt-verify-all-modules.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env python3
# utils/sil-opt-verify-all-modules.py - Verifies Swift modules -*- python -*-
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
importargparse
importglob
importmultiprocessing
importos
importshlex
importsubprocess
importsys
importtempfile
defget_verify_toolchain_modules_commands(toolchain_dir, sil_opt):
ifsil_optisNone:
sil_opt=os.path.join(toolchain_dir, 'usr', 'bin', 'sil-opt')
toolchain_basename=os.path.basename(toolchain_dir)
iftoolchain_basename.startswith('Legacy'):
return []
iftoolchain_basename.startswith('XcodeDefault'):
toolchain_name='XcodeDefault'
iftoolchain_basename.startswith('tvOS'):
toolchain_name='tvOS'
iftoolchain_basename.startswith('OSX'):
toolchain_name='OSX'
iftoolchain_basename.startswith('watchOS'):
toolchain_name='watchOS'
iftoolchain_basename.startswith('iOS'):
toolchain_name='iOS'
returnget_verify_resource_dir_modules_commands(
os.path.join(toolchain_dir, 'usr', 'lib', 'swift'),
os.path.join(toolchain_dir, 'usr', 'bin', 'sil-opt'),
toolchain_name)
defget_verify_build_dir_commands(build_dir, toolchain_name='XcodeDefault'):
returnget_verify_resource_dir_modules_commands(
os.path.join(build_dir, 'lib', 'swift'),
os.path.join(build_dir, 'bin', 'sil-opt'),
toolchain_name)
defget_verify_resource_dir_modules_commands(
resource_dir, sil_opt, toolchain_name):
print("================================================================")
print("Resource dir: "+resource_dir)
print("sil-opt path: "+sil_opt)
known_platforms= [
('appletvos', 'arm64', 'arm64-apple-tvos9.0'),
('appletvsimulator', 'x86_64', 'x86_64-apple-tvos9.0'),
('iphoneos', 'arm64', 'arm64-apple-ios7.0'),
('iphonesimulator', 'x86_64', 'x86_64-apple-ios7.0'),
('macosx', 'x86_64', 'x86_64-apple-macosx10.9'),
('watchos', 'armv7k', 'armv7k-apple-watchos2.0'),
('watchsimulator', 'i386', 'i386-apple-watchos2.0'),
]
commands= []
module_cache_dir=tempfile.mkdtemp(
prefix="swift-testsuite-clang-module-cache")
for (subdir, arch, triple) inknown_platforms:
modules_dir=os.path.join(resource_dir, subdir, arch)
print(modules_dir)
modules=glob.glob(os.path.join(modules_dir, '*.swiftmodule'))
formodule_file_nameinmodules:
ifmodule_file_name.endswith('XCTest.swiftmodule'):
# FIXME: sil-opt does not have the '-F' option.
continue
commands.append([
'xcrun', '--toolchain', toolchain_name, '--sdk', subdir,
sil_opt,
'-target', triple,
'-resource-dir', resource_dir,
'-module-cache-path', module_cache_dir,
'-verify',
module_file_name,
])
returncommands
defquote_shell_command(args):
return" ".join([shlex.quote(a) forainargs])
defrun_commands_in_parallel(commands):
makefile=".DEFAULT_GOAL := all\n"
targets= []
forcincommands:
target_name="target"+str(len(targets))
targets.append(target_name)
makefile+=target_name+":\n"
makefile+= \
"\t"+quote_shell_command(c) + \
" > {target}.stdout\n".format(target=target_name)
makefile+="all: "+" ".join(targets) +"\n"
temp_dir=tempfile.mkdtemp(prefix="swift-testsuite-main")
withopen(os.path.join(temp_dir, 'Makefile'), 'w') asmakefile_file:
makefile_file.write(makefile)
max_processes=multiprocessing.cpu_count()
subprocess.check_call([
'make',
'-C', temp_dir,
'-j', str(max_processes),
'--keep-going'
])
defmain():
parser=argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""Verifies Swift modules.""")
parser.add_argument(
"--sil-opt",
help="use the specified 'sil-opt' binary",
metavar="PATH")
parser.add_argument(
"--verify-build-dir",
help="verify the Swift resource directory under the given build dir.",
metavar="PATH")
parser.add_argument(
"--verify-xcode",
help="verify the Xcode.app that is currently xcode-select'ed",
action="store_true")
args=parser.parse_args()
ifargs.verify_build_dirisnotNoneandargs.verify_xcode:
print("--verify-build-dir and --verify-xcode can't be used together")
return1
ifargs.verify_build_dirisnotNone:
commands=get_verify_build_dir_commands(args.verify_build_dir)
ifargs.verify_xcode:
# Find Xcode.
swift_path=subprocess.check_output(['xcrun', '--find', 'swift'])
xcode_path=swift_path
for_inrange(0, 7):
xcode_path=os.path.dirname(xcode_path)
toolchains_dir=os.path.join(
xcode_path, 'Contents', 'Developer', 'Toolchains')
toolchains=glob.glob(os.path.join(toolchains_dir, '*.xctoolchain'))
commands= []
fortoolchain_dirintoolchains:
commands+=get_verify_toolchain_modules_commands(
toolchain_dir, args.sil_opt)
run_commands_in_parallel(commands)
return0
if__name__=="__main__":
sys.exit(main())