Skip to content

Commit d8528dc

Browse files
committed
swift-api-checker: teach the script to dump entire SDK content to files separated by modules
1 parent 5550839 commit d8528dc

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

utils/api_checker/swift-api-checker.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ def get_api_digester_path(tool_path):
7070
return check_output(['xcrun', '--find', 'swift-api-digester'])
7171

7272

73+
def create_directory(path):
74+
if not os.path.isdir(path):
75+
os.makedirs(path)
76+
77+
7378
class DumpConfig:
7479
def __init__(self, tool_path, platform):
7580
target_map = {
@@ -87,8 +92,8 @@ def __init__(self, tool_path, platform):
8792
os.path.realpath(self.sdk + '/../../Library/Frameworks/')]
8893

8994
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',
9297
self.target, '-dump-sdk', '-module-cache-path',
9398
'/tmp/ModuleCache', '-swift-version',
9499
swift_ver, '-abort-on-module-fail']
@@ -99,13 +104,28 @@ def run(self, output, module, swift_ver, opts, verbose,
99104
cmd.extend(['-v'])
100105
if module:
101106
cmd.extend(['-module', module])
107+
cmd.extend(['-o', output])
102108
check_call(cmd, verbose=verbose)
103109
else:
104110
with tempfile.NamedTemporaryFile() as tmp:
105111
prepare_module_list(self.platform, tmp, verbose,
106112
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)
109129

110130

111131
class DiagnoseConfig:
@@ -181,6 +201,10 @@ def main():
181201
Path to the json file generated after change
182202
''')
183203

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')
184208
args = parser.parse_args(sys.argv[1:])
185209
if args.action == 'dump':
186210
if not args.target:
@@ -191,7 +215,8 @@ def main():
191215
runner.run(output=args.output, module=args.module,
192216
swift_ver=args.swift_version, opts=args.opts,
193217
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)
195220
elif args.action == 'diagnose':
196221
if not args.dump_before:
197222
fatal_error("Need to specify --dump-before")

0 commit comments

Comments
 (0)