@@ -70,6 +70,11 @@ def get_api_digester_path(tool_path):
70
70
return check_output (['xcrun' , '--find' , 'swift-api-digester' ])
71
71
72
72
73
+ def create_directory (path ):
74
+ if not os .path .isdir (path ):
75
+ os .makedirs (path )
76
+
77
+
73
78
class DumpConfig :
74
79
def __init__ (self , tool_path , platform ):
75
80
target_map = {
@@ -87,8 +92,8 @@ def __init__(self, tool_path, platform):
87
92
os .path .realpath (self .sdk + '/../../Library/Frameworks/' )]
88
93
89
94
def run (self , output , module , swift_ver , opts , verbose ,
90
- swift_frameworks_only ):
91
- cmd = [self .tool_path , '-o' , output , '- sdk' , self .sdk , '-target' ,
95
+ swift_frameworks_only , separate_by_module ):
96
+ cmd = [self .tool_path , '-sdk' , self .sdk , '-target' ,
92
97
self .target , '-dump-sdk' , '-module-cache-path' ,
93
98
'/tmp/ModuleCache' , '-swift-version' ,
94
99
swift_ver , '-abort-on-module-fail' ]
@@ -99,13 +104,28 @@ def run(self, output, module, swift_ver, opts, verbose,
99
104
cmd .extend (['-v' ])
100
105
if module :
101
106
cmd .extend (['-module' , module ])
107
+ cmd .extend (['-o' , output ])
102
108
check_call (cmd , verbose = verbose )
103
109
else :
104
110
with tempfile .NamedTemporaryFile () as tmp :
105
111
prepare_module_list (self .platform , tmp , verbose ,
106
112
swift_frameworks_only )
107
- cmd .extend (['-module-list-file' , tmp .name ])
108
- check_call (cmd , verbose = verbose )
113
+ if separate_by_module :
114
+ tmp .seek (0 )
115
+ create_directory (output )
116
+ for module in [name .strip () for name in tmp .readlines ()]:
117
+ dir_path = os .path .realpath (output + '/' + module )
118
+ file_path = os .path .realpath (dir_path + '/' +
119
+ self .platform + '.json' )
120
+ create_directory (dir_path )
121
+ current_cmd = list (cmd )
122
+ current_cmd .extend (['-module' , module ])
123
+ current_cmd .extend (['-o' , file_path ])
124
+ check_call (current_cmd , verbose = verbose )
125
+ else :
126
+ cmd .extend (['-o' , output ])
127
+ cmd .extend (['-module-list-file' , tmp .name ])
128
+ check_call (cmd , verbose = verbose )
109
129
110
130
111
131
class DiagnoseConfig :
@@ -181,6 +201,10 @@ def main():
181
201
Path to the json file generated after change
182
202
''' )
183
203
204
+ basic_group .add_argument ('--separate-by-module' ,
205
+ action = 'store_true' ,
206
+ help = 'When importing entire SDK, dump content '
207
+ 'seprately by module names' )
184
208
args = parser .parse_args (sys .argv [1 :])
185
209
if args .action == 'dump' :
186
210
if not args .target :
@@ -191,7 +215,8 @@ def main():
191
215
runner .run (output = args .output , module = args .module ,
192
216
swift_ver = args .swift_version , opts = args .opts ,
193
217
verbose = args .v ,
194
- swift_frameworks_only = args .swift_frameworks_only )
218
+ swift_frameworks_only = args .swift_frameworks_only ,
219
+ separate_by_module = args .separate_by_module )
195
220
elif args .action == 'diagnose' :
196
221
if not args .dump_before :
197
222
fatal_error ("Need to specify --dump-before" )
0 commit comments