@@ -18,14 +18,14 @@ import os
18
18
import json
19
19
import argparse
20
20
import platform
21
- import codecs
22
21
23
22
import common
23
+ from typing import List
24
24
25
25
script_dir = os .path .abspath (os .path .dirname (__file__ ))
26
26
27
27
28
- def main ():
28
+ def main () -> int :
29
29
if platform .system () != 'Darwin' :
30
30
raise common .UnsupportedPlatform
31
31
@@ -51,7 +51,7 @@ def main():
51
51
return 0
52
52
53
53
54
- def parse_args ():
54
+ def parse_args () -> argparse . Namespace :
55
55
parser = argparse .ArgumentParser ()
56
56
parser .add_argument ('swift_branch' )
57
57
parser .add_argument ('--sandbox' , action = 'store_true' )
@@ -97,15 +97,19 @@ def parse_args():
97
97
action = 'store_true' )
98
98
parser .add_argument ('--add-swift-flags' ,
99
99
metavar = 'FLAGS' ,
100
- help = 'add flags to each Swift invocation (note: field '
101
- 'names from projects.json enclosed in {} will be '
102
- 'replaced with their value)' ,
100
+ help = '''
101
+ add flags to each Swift invocation (note: field
102
+ names from projects.json enclosed in {} will be
103
+ replaced with their value)
104
+ ''' ,
103
105
default = '' )
104
106
parser .add_argument ('--add-xcodebuild-flags' ,
105
107
metavar = 'FLAGS' ,
106
- help = 'add flags to each xcodebuild invocation (note: field '
107
- 'names from projects.json enclosed in {} will be '
108
- 'replaced with their value)' ,
108
+ help = '''
109
+ add flags to each xcodebuild invocation (note: field
110
+ names from projects.json enclosed in {} will be
111
+ replaced with their value)
112
+ ''' ,
109
113
default = '' )
110
114
parser .add_argument ('--cmake-c-launcher' ,
111
115
metavar = "PATH" ,
@@ -115,45 +119,45 @@ def parse_args():
115
119
help = 'the absolute path to set CMAKE_CXX_COMPILER_LAUNCHER for build-script' )
116
120
return parser .parse_args ()
117
121
118
- def get_swiftc_path (workspace , args ) :
122
+ def get_swiftc_path (workspace : str , args : argparse . Namespace ) -> str :
119
123
if args .swiftc :
120
124
return args .swiftc
121
125
else :
122
126
return os .path .join (workspace , 'build/compat_macos/install/toolchain/usr/bin/swiftc' )
123
127
124
- def get_sk_swiftc_wrapper_path (workspace , args ) :
128
+ def get_sk_swiftc_wrapper_path (workspace : str , args : argparse . Namespace ) -> str :
125
129
if args .sk_swiftc_wrapper :
126
130
return args .sk_swiftc_wrapper
127
131
else :
128
132
# If not explicitly specified, fall back to finding `sk-swiftc-wrapper` next to `swiftc`
129
133
swiftc_path = get_swiftc_path (workspace , args )
130
134
return os .path .join (os .path .dirname (swiftc_path ), 'sk-swiftc-wrapper' )
131
135
132
- def get_sk_stress_test_path (workspace , args ) :
136
+ def get_sk_stress_test_path (workspace : str , args : argparse . Namespace ) -> str :
133
137
if args .sk_stress_test :
134
138
return args .sk_stress_test
135
139
else :
136
140
# If not explicitly specified, fall back to finding `sk-stress-test` next to `swiftc`
137
141
swiftc_path = get_swiftc_path (workspace , args )
138
142
return os .path .join (os .path .dirname (swiftc_path ), 'sk-stress-test' )
139
143
140
- def get_sandbox_profile_flags ():
144
+ def get_sandbox_profile_flags () -> List [ str ] :
141
145
return [
142
146
'--sandbox-profile-xcodebuild' ,
143
147
'../../../workspace-private/swift-source-compat-suite-sandbox/sandbox_xcodebuild.sb' ,
144
148
'--sandbox-profile-package' ,
145
149
'../../../workspace-private/swift-source-compat-suite-sandbox/sandbox_package.sb'
146
150
]
147
151
148
- def clone_stress_tester (workspace , swift_branch ) :
152
+ def clone_stress_tester (workspace : str , swift_branch : str ) -> None :
149
153
stress_clone_cmd = [
150
154
'git' ,'clone' , '-q' , '-b' , swift_branch , '--recursive' ,
151
155
'https://github.com/apple/swift-stress-tester' ,
152
156
'{}/swift-stress-tester' .format (workspace )
153
157
]
154
158
common .check_execute (stress_clone_cmd , timeout = - 1 )
155
159
156
- def clone_swift_syntax (workspace , swift_branch ) :
160
+ def clone_swift_syntax (workspace : str , swift_branch : str ) -> None :
157
161
syntax_clone_cmd = [
158
162
'git' ,'clone' , '-q' , '-b' , swift_branch , '--recursive' ,
159
163
'https://github.com/apple/swift-syntax' ,
@@ -162,7 +166,7 @@ def clone_swift_syntax(workspace, swift_branch):
162
166
common .check_execute (syntax_clone_cmd , timeout = - 1 )
163
167
164
168
165
- def execute_runner (workspace , args ) :
169
+ def execute_runner (workspace : str , args : argparse . Namespace ) -> bool :
166
170
swiftc_path = get_swiftc_path (workspace , args )
167
171
wrapper_path = get_sk_swiftc_wrapper_path (workspace , args )
168
172
stress_tester_path = get_sk_stress_test_path (workspace , args )
@@ -189,7 +193,7 @@ def execute_runner(workspace, args):
189
193
return passed
190
194
191
195
192
- def build_swift_toolchain (workspace , args ) :
196
+ def build_swift_toolchain (workspace : str , args : argparse . Namespace ) -> None :
193
197
build_command = [
194
198
os .path .join (workspace , 'swift/utils/build-script' ),
195
199
'--debug' if args .debug else '--release' ,
@@ -209,7 +213,7 @@ def build_swift_toolchain(workspace, args):
209
213
'--darwin-install-extract-symbols' ,
210
214
'--darwin-toolchain-alias=swift' ,
211
215
'--darwin-toolchain-bundle-identifier=org.swift.compat-macos' ,
212
- '--darwin-toolchain-display-name-short=Swift Development Snapshot'
216
+ '--darwin-toolchain-display-name-short=Swift Development Snapshot' ,
213
217
'--darwin-toolchain-display-name=Swift Development Snapshot' ,
214
218
'--darwin-toolchain-name=swift-DEVELOPMENT-SNAPSHOT' ,
215
219
'--darwin-toolchain-version=3.999.999' ,
@@ -235,32 +239,37 @@ def build_swift_toolchain(workspace, args):
235
239
common .check_execute (build_command , timeout = 9999999 )
236
240
237
241
238
- def processed_files_contain (processed_files , file_path ) :
239
- """
240
- Returns `True` if a path in `processed_files` contains `file_path` as a substring, `False` otherwise
241
- """
242
- for processed_file in processed_files :
243
- if file_path in processed_file :
244
- return True
245
- return False
242
+ def processed_files_contain (processed_files : List [ str ] , file_path : str ) -> bool :
243
+ """
244
+ Returns `True` if a path in `processed_files` contains `file_path` as a substring, `False` otherwise
245
+ """
246
+ for processed_file in processed_files :
247
+ if file_path in processed_file :
248
+ return True
249
+ return False
246
250
247
251
248
252
class StressTesterRunner (object ):
249
253
"""sets up the Swift compatibility suite runner to use the stress tester's swiftc-wrapper, executes it, and processes its output for failures."""
250
254
251
- def __init__ (self , wrapper , stress_tester , swiftc , projects , branch , xfails ):
255
+ wrapper : str
256
+ stress_tester : str
257
+ swiftc : str
258
+ branch : str
259
+
260
+ def __init__ (self , wrapper : str , stress_tester : str , swiftc : str , projects_path : str , branch : str , xfails_path : str ):
252
261
self .wrapper = wrapper
253
262
self .stress_tester = stress_tester
254
263
self .swiftc = swiftc
255
264
256
- self .xfails_path = xfails
257
- self .projects_path = projects
265
+ self .xfails_path = xfails_path
266
+ self .projects_path = projects_path
258
267
self .swift_branch = branch
259
268
260
269
self .compat_runner_failed = False
261
270
262
271
263
- def run (self , extra_runner_args = []):
272
+ def run (self , extra_runner_args : List [ str ] = []) -> bool :
264
273
# temporary file paths
265
274
filtered_projects = os .path .join (script_dir , 'stress-tester-projects.json' )
266
275
results = os .path .join (script_dir , 'stress-tester-results.json' )
@@ -312,14 +321,14 @@ class StressTesterRunner(object):
312
321
return success
313
322
314
323
315
- def _process_output (self , results_path , xfails_path ) :
324
+ def _process_output (self , results_path : str , xfails_path : str ) -> bool :
316
325
if not os .path .isfile (results_path ):
317
326
return not self .compat_runner_failed
318
327
319
- with open (results_path , 'rb ' ) as results_file :
328
+ with open (results_path , 'r ' ) as results_file :
320
329
results = json .load (results_file , encoding = 'utf-8' )
321
- with open (xfails_path , 'rb ' ) as xfails_path :
322
- xfails = json .load (xfails_path , encoding = 'utf-8' )
330
+ with open (xfails_path , 'r ' ) as xfails_file :
331
+ xfails = json .load (xfails_file , encoding = 'utf-8' )
323
332
324
333
xfails_not_processed = []
325
334
for xfail in xfails :
@@ -390,14 +399,14 @@ class StressTesterRunner(object):
390
399
return success
391
400
392
401
@staticmethod
393
- def _print_issue (index , issue , url = None ):
402
+ def _print_issue (index : int , issue , url = None ):
394
403
if url != None :
395
404
print (u'\n {}. [{}] {}' .format (index + 1 , url , issue ))
396
405
else :
397
406
print (u'\n {}. {}' .format (index + 1 , issue ))
398
407
399
408
400
- def _filter_projects (self , output ) :
409
+ def _filter_projects (self , output : str ) -> str :
401
410
with open (self .projects_path ) as json_file :
402
411
projects = json .load (json_file )
403
412
for project in projects :
@@ -419,21 +428,13 @@ class StressTesterRunner(object):
419
428
return output
420
429
421
430
@staticmethod
422
- def _cleanup (paths ) :
431
+ def _cleanup (paths : List [ str ]) -> None :
423
432
for path in paths :
424
433
try :
425
434
os .remove (path )
426
435
except OSError :
427
436
pass
428
437
429
- if os .isatty (sys .stdout .fileno ()):
430
- encoding = sys .stdout .encoding
431
- errors = 'replace'
432
- else :
433
- encoding = 'utf-8'
434
- errors = None
435
- sys .stdout = codecs .getwriter (encoding )(sys .stdout , errors = errors )
436
-
437
438
if __name__ == '__main__' :
438
439
sys .exit (main ())
439
440
0 commit comments