@@ -30,7 +30,7 @@ def escapeCmdArg(arg):
30
30
return arg
31
31
32
32
33
- def check_call (cmd , cwd = None , env = os .environ , verbose = True , output = None ):
33
+ def check_call (cmd , cwd = None , env = os .environ , verbose = False , output = None ):
34
34
if verbose :
35
35
print (' ' .join ([escapeCmdArg (arg ) for arg in cmd ]))
36
36
return subprocess .check_call (cmd , cwd = cwd , env = env ,
@@ -56,24 +56,29 @@ def prepare_module_list(platform, file):
56
56
file .write (extra .read ())
57
57
58
58
59
+ def get_api_digester_path (tool_path ):
60
+ if tool_path :
61
+ return tool_path
62
+ return check_output (['xcrun' , '--find' , 'swift-api-digester' ])
63
+
64
+
59
65
class DumpConfig :
60
- def __init__ (self , platform ):
66
+ def __init__ (self , tool_path , platform ):
61
67
target_map = {
62
68
'iphoneos' : 'arm64-apple-ios10.0' ,
63
69
'macosx' : 'x86_64-apple-macosx10.11' ,
64
70
'appletvos' : 'arm64-apple-tvos10.0' ,
65
71
'watchos' : 'armv7k-apple-watchos3.0' ,
66
72
}
73
+ self .tool_path = get_api_digester_path (tool_path )
67
74
self .platform = platform
68
75
self .target = target_map [platform ]
69
76
self .sdk = get_sdk_path (platform )
70
77
self .frameworks = [
71
78
self .sdk + '/System/Library/Frameworks/' ,
72
79
os .path .realpath (self .sdk + '/../../Library/Frameworks/' )]
73
- self .tool_path = check_output (['xcrun' , '--find' ,
74
- 'swift-api-digester' ])
75
80
76
- def run (self , output , module , swift_ver , abi ):
81
+ def run (self , output , module , swift_ver , abi , verbose ):
77
82
cmd = [self .tool_path , '-o' , output , '-sdk' , self .sdk , '-target' ,
78
83
self .target , '-dump-sdk' , '-module-cache-path' ,
79
84
'/tmp/ModuleCache' , '-swift-version' ,
@@ -82,14 +87,32 @@ def run(self, output, module, swift_ver, abi):
82
87
cmd .extend (['-iframework' , path ])
83
88
if abi :
84
89
cmd .extend (['-abi' ])
90
+ if verbose :
91
+ cmd .extend (['-v' ])
85
92
if module :
86
93
cmd .extend (['-module' , module ])
87
- check_call (cmd )
94
+ check_call (cmd , verbose = verbose )
88
95
else :
89
96
with tempfile .NamedTemporaryFile () as tmp :
90
97
prepare_module_list (self .platform , tmp )
91
98
cmd .extend (['-module-list-file' , tmp .name ])
92
- check_call (cmd )
99
+ check_call (cmd , verbose = verbose )
100
+
101
+
102
+ class DiagnoseConfig :
103
+ def __init__ (self , tool_path ):
104
+ self .tool_path = get_api_digester_path (tool_path )
105
+
106
+ def run (self , abi , before , after , output , verbose ):
107
+ cmd = [self .tool_path , '-diagnose-sdk' , '-input-paths' , before ,
108
+ '-input-paths' , after ]
109
+ if output :
110
+ cmd .extend (['-o' , output ])
111
+ if abi :
112
+ cmd .extend (['-abi' ])
113
+ if verbose :
114
+ cmd .extend (['-v' ])
115
+ check_call (cmd , verbose = verbose )
93
116
94
117
95
118
def main ():
@@ -100,6 +123,12 @@ def main():
100
123
''' )
101
124
102
125
basic_group = parser .add_argument_group ('Basic' )
126
+
127
+ basic_group .add_argument ('--tool-path' , default = None , help = '''
128
+ the path to a swift-api-digester; if not specified, the script will
129
+ use the one from the toolchain
130
+ ''' )
131
+
103
132
basic_group .add_argument ('--action' , default = '' , help = '''
104
133
the action to perform for swift-api-digester
105
134
''' )
@@ -124,18 +153,39 @@ def main():
124
153
action = 'store_true' ,
125
154
help = 'Whether we are jsonizing for abi' )
126
155
127
- args = parser .parse_args (sys .argv [1 :])
128
- if not args .target :
129
- fatal_error ("Need to specify --target" )
130
- if not args .output :
131
- fatal_error ("Need to specify --output" )
156
+ basic_group .add_argument ('--v' ,
157
+ action = 'store_true' ,
158
+ help = 'Process verbosely' )
159
+
160
+ basic_group .add_argument ('--dump-before' ,
161
+ action = None ,
162
+ help = '''
163
+ Path to the json file generated before change'
164
+ ''' )
165
+
166
+ basic_group .add_argument ('--dump-after' ,
167
+ action = None ,
168
+ help = '''
169
+ Path to the json file generated after change
170
+ ''' )
132
171
172
+ args = parser .parse_args (sys .argv [1 :])
133
173
if args .action == 'dump' :
134
- runner = DumpConfig (platform = args .target )
174
+ if not args .target :
175
+ fatal_error ("Need to specify --target" )
176
+ if not args .output :
177
+ fatal_error ("Need to specify --output" )
178
+ runner = DumpConfig (tool_path = args .tool_path , platform = args .target )
135
179
runner .run (output = args .output , module = args .module ,
136
- swift_ver = args .swift_version , abi = args .abi )
180
+ swift_ver = args .swift_version , abi = args .abi , verbose = args . v )
137
181
elif args .action == 'diagnose' :
138
- fatal_error ('Not implemented' )
182
+ if not args .dump_before :
183
+ fatal_error ("Need to specify --dump-before" )
184
+ if not args .dump_after :
185
+ fatal_error ("Need to specify --dump-after" )
186
+ runner = DiagnoseConfig (tool_path = args .tool_path )
187
+ runner .run (abi = args .abi , before = args .dump_before ,
188
+ after = args .dump_after , output = args .output , verbose = args .v )
139
189
else :
140
190
fatal_error ('Cannot recognize action: ' + args .action )
141
191
0 commit comments