Skip to content

Commit d3785d9

Browse files
authored
Merge pull request #25434 from nkcsgexi/infer-module-swift-only
swift-api-checker: teach the script to collect Swift only frameworks from the SDK.
2 parents 6d3e3f0 + 06c958e commit d3785d9

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def get_immediate_subdirectories(a_dir):
1515
if os.path.isdir(os.path.join(a_dir, name))]
1616

1717

18-
def get_frameworks(sdk_path):
18+
def get_frameworks(sdk_path, swift_frameworks_only):
1919
frameworks_path = sdk_path + "/System/Library/Frameworks"
2020
names = []
2121
for frame in os.listdir(frameworks_path):
@@ -32,6 +32,9 @@ def get_frameworks(sdk_path):
3232
if name not in blacklist:
3333
names.append(name)
3434
continue
35+
# We only care about Swift frameworks then we are done.
36+
if swift_frameworks_only:
37+
continue
3538

3639
if not os.path.exists(header_dir_path):
3740
if os.path.exists(module_dir_path):
@@ -95,7 +98,8 @@ def main():
9598
parser.add_option("-o", "--output", help="output mode",
9699
type=str, dest="out_mode", default="list")
97100
parser.add_option("--hash", action="store_true", dest="use_hash")
98-
101+
parser.add_option("--swift-frameworks-only", action="store_true")
102+
parser.add_option("--v", action="store_true")
99103
(opts, cmd) = parser.parse_args()
100104

101105
if not opts.sdk:
@@ -105,7 +109,10 @@ def main():
105109
parser.error(
106110
"output mode not specified: 'clang-import'/'swift-import'/'list'")
107111

108-
frames = get_frameworks(opts.sdk)
112+
frames = get_frameworks(opts.sdk, opts.swift_frameworks_only)
113+
if opts.v:
114+
for name in frames:
115+
print >>sys.stderr, 'Including: ', name
109116
if opts.out_mode == "clang-import":
110117
print_clang_imports(frames, opts.use_hash)
111118
elif opts.out_mode == "swift-import":

utils/api_checker/swift-api-checker.py

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

4949

50-
def prepare_module_list(platform, file):
51-
check_call([INFER_IMPORT_PATH, '-s', get_sdk_path(platform)], output=file)
50+
def prepare_module_list(platform, file, verbose, swift_frameworks_only):
51+
cmd = [INFER_IMPORT_PATH, '-s', get_sdk_path(platform)]
52+
if swift_frameworks_only:
53+
cmd.extend(['--swift-frameworks-only'])
54+
if verbose:
55+
cmd.extend(['--v'])
56+
check_call(cmd, output=file)
57+
# The fixed modules are all objc frameworks.
58+
if swift_frameworks_only:
59+
return
5260
with open(INFER_IMPORT_DIR + '/fixed-modules-common.txt', 'r') as extra:
5361
file.write(extra.read())
5462
with open(INFER_IMPORT_DIR + '/fixed-modules-' + platform + '.txt',
@@ -78,7 +86,8 @@ def __init__(self, tool_path, platform):
7886
self.sdk + '/System/Library/Frameworks/',
7987
os.path.realpath(self.sdk + '/../../Library/Frameworks/')]
8088

81-
def run(self, output, module, swift_ver, opts, verbose):
89+
def run(self, output, module, swift_ver, opts, verbose,
90+
swift_frameworks_only):
8291
cmd = [self.tool_path, '-o', output, '-sdk', self.sdk, '-target',
8392
self.target, '-dump-sdk', '-module-cache-path',
8493
'/tmp/ModuleCache', '-swift-version',
@@ -93,7 +102,8 @@ def run(self, output, module, swift_ver, opts, verbose):
93102
check_call(cmd, verbose=verbose)
94103
else:
95104
with tempfile.NamedTemporaryFile() as tmp:
96-
prepare_module_list(self.platform, tmp)
105+
prepare_module_list(self.platform, tmp, verbose,
106+
swift_frameworks_only)
97107
cmd.extend(['-module-list-file', tmp.name])
98108
check_call(cmd, verbose=verbose)
99109

@@ -147,6 +157,10 @@ def main():
147157
name of the module/framework to generate baseline, e.g. Foundation
148158
''')
149159

160+
basic_group.add_argument('--swift-frameworks-only',
161+
action='store_true',
162+
help='Only include Swift frameworks in the dump')
163+
150164
basic_group.add_argument('--opts', nargs='+', default=[], help='''
151165
additional flags to pass to swift-api-digester
152166
''')
@@ -176,7 +190,8 @@ def main():
176190
runner = DumpConfig(tool_path=args.tool_path, platform=args.target)
177191
runner.run(output=args.output, module=args.module,
178192
swift_ver=args.swift_version, opts=args.opts,
179-
verbose=args.v)
193+
verbose=args.v,
194+
swift_frameworks_only=args.swift_frameworks_only)
180195
elif args.action == 'diagnose':
181196
if not args.dump_before:
182197
fatal_error("Need to specify --dump-before")

0 commit comments

Comments
 (0)