10
10
import os
11
11
import re
12
12
import subprocess
13
+ import multiprocessing
13
14
14
15
DEFAULT_TARGET_BASED_ON_SDK = {
15
16
'macosx' : 'x86_64-apple-macosx10.11' ,
@@ -50,6 +51,7 @@ def create_parser():
50
51
prog = 'omit-needless-words.py' ,
51
52
usage = 'python omit-needless-words.py -m AppKit' )
52
53
parser .add_argument ('-m' , '--module' , help = 'The module name.' )
54
+ parser .add_argument ('-j' , '--jobs' , type = int , help = 'The number of parallel jobs to execute' )
53
55
parser .add_argument ('-s' , '--sdk' , nargs = '+' , required = True , help = "The SDKs to use." )
54
56
parser .add_argument ('-t' , '--target' , help = "The target triple to use." )
55
57
parser .add_argument ('-i' , '--swift-ide-test' , default = 'swift-ide-test' , help = "The swift-ide-test executable." )
@@ -88,7 +90,7 @@ def collect_submodules(common_args, module):
88
90
return sorted (list (submodules ))
89
91
90
92
# Dump the API for the given module.
91
- def dump_module_api (cmd , extra_dump_args , output_dir , module , quiet ):
93
+ def dump_module_api (( cmd , extra_dump_args , output_dir , module , quiet ) ):
92
94
# Collect the submodules
93
95
submodules = collect_submodules (cmd , module )
94
96
@@ -150,7 +152,7 @@ def collect_frameworks(sdk):
150
152
151
153
return (sorted (list (frameworks )), sdk_path )
152
154
153
- def dump_sdk_api (cmd_common , cmd_extra_args , sdk , module , target , source_filename , output_dir , quiet ):
155
+ def create_dump_module_api_args (cmd_common , cmd_extra_args , sdk , module , target , source_filename , output_dir , quiet ):
154
156
155
157
# Determine the SDK root and collect the set of frameworks.
156
158
(frameworks , sdk_root ) = collect_frameworks (sdk )
@@ -165,15 +167,16 @@ def dump_sdk_api(cmd_common, cmd_extra_args, sdk, module, target, source_filenam
165
167
pretty_sdk = pretty_sdk_name (sdk )
166
168
sdk_output_dir = '%s/%s' % (output_dir , pretty_sdk )
167
169
168
- # Dump the APIs
170
+ # Create the sets of arguments to dump_module_api.
171
+ results = []
169
172
cmd = cmd_common + ['-sdk' , sdk_root , '-target' , sdk_target ]
170
173
if module :
171
- dump_module_api ( cmd , cmd_extra_args , sdk_output_dir , module , quiet )
174
+ results . append (( cmd , cmd_extra_args , sdk_output_dir , module , quiet ) )
172
175
else :
173
176
for framework in frameworks :
174
- dump_module_api ( cmd , cmd_extra_args , sdk_output_dir , framework , quiet )
177
+ results . append (( cmd , cmd_extra_args , sdk_output_dir , framework , quiet ) )
175
178
176
- return
179
+ return results
177
180
178
181
def main ():
179
182
source_filename = 'omit-needless-words.swift'
@@ -190,9 +193,14 @@ def main():
190
193
# Create a .swift file we can feed into swift-ide-test
191
194
subprocess .call (['touch' , source_filename ])
192
195
193
- # Dump the requested APIs.
196
+ # Construct the set of API dumps we should perform.
197
+ jobs = []
194
198
for sdk in args .sdk :
195
- dump_sdk_api (cmd_common , extra_args , sdk , args .module , args .target , source_filename , args .output_dir , args .quiet )
199
+ jobs = jobs + create_dump_module_api_args (cmd_common , extra_args , sdk , args .module , args .target , source_filename , args .output_dir , args .quiet )
200
+
201
+ # Execute the API dumps
202
+ pool = multiprocessing .Pool (processes = args .jobs )
203
+ pool .map (dump_module_api , jobs )
196
204
197
205
# Remove the .swift file we fed into swift-ide-test
198
206
subprocess .call (['rm' , '-f' , source_filename ])
0 commit comments