Skip to content

Commit 5184994

Browse files
committed
swift-api-checker: teach the script to collect all frameworks with Swift overlay in SDKs
1 parent d8528dc commit 5184994

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

utils/api_checker/sdk-module-lists/infer-imports.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ def get_frameworks(sdk_path, swift_frameworks_only):
5757
return names
5858

5959

60+
def get_overlays(sdk_path):
61+
overlay_path = sdk_path + "/usr/lib/swift/"
62+
names = []
63+
for overlay in os.listdir(overlay_path):
64+
if overlay.endswith(".swiftmodule"):
65+
overlay = overlay[:-len(".swiftmodule")]
66+
if overlay in blacklist:
67+
continue
68+
names.append(overlay)
69+
return names
70+
71+
6072
def should_exclude_framework(frame_path):
6173
module_map_path = frame_path + '/Modules/module.modulemap'
6274
if not os.path.exists(module_map_path):
@@ -99,6 +111,7 @@ def main():
99111
type=str, dest="out_mode", default="list")
100112
parser.add_option("--hash", action="store_true", dest="use_hash")
101113
parser.add_option("--swift-frameworks-only", action="store_true")
114+
parser.add_option("--swift-overlay-only", action="store_true")
102115
parser.add_option("--v", action="store_true")
103116
(opts, cmd) = parser.parse_args()
104117

@@ -109,7 +122,10 @@ def main():
109122
parser.error(
110123
"output mode not specified: 'clang-import'/'swift-import'/'list'")
111124

112-
frames = get_frameworks(opts.sdk, opts.swift_frameworks_only)
125+
if opts.swift_overlay_only:
126+
frames = get_overlays(opts.sdk)
127+
else:
128+
frames = get_frameworks(opts.sdk, opts.swift_frameworks_only)
113129
if opts.v:
114130
for name in frames:
115131
print >>sys.stderr, 'Including: ', name

utils/api_checker/swift-api-checker.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ def get_sdk_path(platform):
4747
return check_output(['xcrun', '-sdk', platform, '-show-sdk-path'])
4848

4949

50-
def prepare_module_list(platform, file, verbose, swift_frameworks_only):
50+
def prepare_module_list(platform, file, verbose, module_filter_flags,
51+
include_fixed_modules):
5152
cmd = [INFER_IMPORT_PATH, '-s', get_sdk_path(platform)]
52-
if swift_frameworks_only:
53-
cmd.extend(['--swift-frameworks-only'])
53+
cmd.extend(module_filter_flags)
5454
if verbose:
5555
cmd.extend(['--v'])
5656
check_call(cmd, output=file)
5757
# The fixed modules are all objc frameworks.
58-
if swift_frameworks_only:
58+
if not include_fixed_modules:
5959
return
6060
with open(INFER_IMPORT_DIR + '/fixed-modules-common.txt', 'r') as extra:
6161
file.write(extra.read())
@@ -92,7 +92,7 @@ def __init__(self, tool_path, platform):
9292
os.path.realpath(self.sdk + '/../../Library/Frameworks/')]
9393

9494
def run(self, output, module, swift_ver, opts, verbose,
95-
swift_frameworks_only, separate_by_module):
95+
module_filter_flags, include_fixed_modules, separate_by_module):
9696
cmd = [self.tool_path, '-sdk', self.sdk, '-target',
9797
self.target, '-dump-sdk', '-module-cache-path',
9898
'/tmp/ModuleCache', '-swift-version',
@@ -109,7 +109,7 @@ def run(self, output, module, swift_ver, opts, verbose,
109109
else:
110110
with tempfile.NamedTemporaryFile() as tmp:
111111
prepare_module_list(self.platform, tmp, verbose,
112-
swift_frameworks_only)
112+
module_filter_flags, include_fixed_modules)
113113
if separate_by_module:
114114
tmp.seek(0)
115115
create_directory(output)
@@ -177,9 +177,9 @@ def main():
177177
name of the module/framework to generate baseline, e.g. Foundation
178178
''')
179179

180-
basic_group.add_argument('--swift-frameworks-only',
181-
action='store_true',
182-
help='Only include Swift frameworks in the dump')
180+
basic_group.add_argument('--module-filter', default='', help='''
181+
the action to perform for swift-api-digester
182+
''')
183183

184184
basic_group.add_argument('--opts', nargs='+', default=[], help='''
185185
additional flags to pass to swift-api-digester
@@ -206,16 +206,29 @@ def main():
206206
help='When importing entire SDK, dump content '
207207
'seprately by module names')
208208
args = parser.parse_args(sys.argv[1:])
209+
209210
if args.action == 'dump':
210211
if not args.target:
211212
fatal_error("Need to specify --target")
212213
if not args.output:
213214
fatal_error("Need to specify --output")
215+
if args.module_filter == '':
216+
module_filter_flags = []
217+
include_fixed_modules = True
218+
elif args.module_filter == 'swift-frameworks-only':
219+
module_filter_flags = ['--swift-frameworks-only']
220+
include_fixed_modules = False
221+
elif args.module_filter == 'swift-overlay-only':
222+
module_filter_flags = ['--swift-overlay-only']
223+
include_fixed_modules = False
224+
else:
225+
fatal_error("cannot recognize --module-filter")
214226
runner = DumpConfig(tool_path=args.tool_path, platform=args.target)
215227
runner.run(output=args.output, module=args.module,
216228
swift_ver=args.swift_version, opts=args.opts,
217229
verbose=args.v,
218-
swift_frameworks_only=args.swift_frameworks_only,
230+
module_filter_flags=module_filter_flags,
231+
include_fixed_modules=include_fixed_modules,
219232
separate_by_module=args.separate_by_module)
220233
elif args.action == 'diagnose':
221234
if not args.dump_before:

0 commit comments

Comments
 (0)