Skip to content

Commit 6562fa4

Browse files
authored
Merge pull request #26748 from nkcsgexi/fixed-modules-swift
swift-api-checker: rename existing fixed-module lists to fixed-clang-modules
2 parents c4ee7ec + 362ece8 commit 6562fa4

13 files changed

+58
-18
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Empty
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Empty
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Empty
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Empty
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Empty
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CreateML
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Empty

utils/api_checker/swift-api-checker.py

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,38 @@ def check_output(cmd, verbose=False):
4444

4545

4646
def get_sdk_path(platform):
47+
if platform.startswith('iosmac'):
48+
platform = 'macosx'
4749
return check_output(['xcrun', '-sdk', platform, '-show-sdk-path'])
4850

4951

52+
def write_fixed_module(file, platform, infix, verbose):
53+
common_modules_path = os.path.join(INFER_IMPORT_DIR, 'fixed-' + infix +
54+
'-modules-common.txt')
55+
platform_modules_path = os.path.join(INFER_IMPORT_DIR, 'fixed-' + infix +
56+
'-modules-' + platform + '.txt')
57+
with open(common_modules_path, 'r') as extra:
58+
if verbose:
59+
print('Including modules in: ' + common_modules_path)
60+
file.write(extra.read())
61+
with open(platform_modules_path, 'r') as extra:
62+
if verbose:
63+
print('Including modules in: ' + platform_modules_path)
64+
file.write(extra.read())
65+
66+
5067
def prepare_module_list(platform, file, verbose, module_filter_flags,
51-
include_fixed_modules):
68+
include_fixed_clang_modules):
5269
cmd = [INFER_IMPORT_PATH, '-s', get_sdk_path(platform)]
5370
cmd.extend(module_filter_flags)
5471
if verbose:
5572
cmd.extend(['--v'])
5673
check_call(cmd, output=file)
57-
# The fixed modules are all objc frameworks.
58-
if not include_fixed_modules:
59-
return
60-
with open(INFER_IMPORT_DIR + '/fixed-modules-common.txt', 'r') as extra:
61-
file.write(extra.read())
62-
with open(INFER_IMPORT_DIR + '/fixed-modules-' + platform + '.txt',
63-
'r') as extra:
64-
file.write(extra.read())
74+
# Always include fixed swift modules
75+
write_fixed_module(file, platform, 'swift', verbose)
76+
# Check if we need fixed clang modules
77+
if include_fixed_clang_modules:
78+
write_fixed_module(file, platform, 'clang', verbose)
6579

6680

6781
def get_api_digester_path(tool_path):
@@ -82,50 +96,69 @@ def __init__(self, tool_path, platform):
8296
'macosx': 'x86_64-apple-macosx10.15',
8397
'appletvos': 'arm64-apple-tvos13.0',
8498
'watchos': 'armv7k-apple-watchos6.0',
99+
'iosmac': 'x86_64-apple-ios13.0-macabi',
85100
}
86101
self.tool_path = get_api_digester_path(tool_path)
87102
self.platform = platform
88103
self.target = target_map[platform]
89104
self.sdk = get_sdk_path(platform)
105+
self.inputs = []
106+
if self.platform == 'macosx':
107+
# We need this input search path for CreateML
108+
self.inputs.extend([self.sdk + '/usr/lib/swift/'])
90109
self.frameworks = [
91110
self.sdk + '/System/Library/Frameworks/',
92111
os.path.realpath(self.sdk + '/../../Library/Frameworks/')]
112+
if self.platform.startswith('iosmac'):
113+
# Catalyst modules need this extra framework dir
114+
iOSSupport = self.sdk + \
115+
'/System/iOSSupport/System/Library/Frameworks'
116+
self.frameworks.extend([iOSSupport])
93117

94118
def run(self, output, module, swift_ver, opts, verbose,
95-
module_filter_flags, include_fixed_modules, separate_by_module):
119+
module_filter_flags, include_fixed_clang_modules,
120+
separate_by_module):
96121
cmd = [self.tool_path, '-sdk', self.sdk, '-target',
97122
self.target, '-dump-sdk', '-module-cache-path',
98123
'/tmp/ModuleCache', '-swift-version',
99124
swift_ver, '-abort-on-module-fail']
125+
_environ = dict(os.environ)
126+
_environ['SWIFT_FORCE_MODULE_LOADING'] = 'prefer-interface'
100127
for path in self.frameworks:
101128
cmd.extend(['-iframework', path])
129+
for path in self.inputs:
130+
cmd.extend(['-I', path])
102131
cmd.extend(['-' + o for o in opts])
103132
if verbose:
104133
cmd.extend(['-v'])
105134
if module:
106135
cmd.extend(['-module', module])
107136
cmd.extend(['-o', output])
108-
check_call(cmd, verbose=verbose)
137+
check_call(cmd, env=_environ, verbose=verbose)
109138
else:
110139
with tempfile.NamedTemporaryFile() as tmp:
111140
prepare_module_list(self.platform, tmp, verbose,
112-
module_filter_flags, include_fixed_modules)
141+
module_filter_flags,
142+
include_fixed_clang_modules)
113143
if separate_by_module:
114144
tmp.seek(0)
115145
create_directory(output)
116146
for module in [name.strip() for name in tmp.readlines()]:
147+
# Skip comments
148+
if module.startswith('//'):
149+
continue
117150
dir_path = os.path.realpath(output + '/' + module)
118151
file_path = os.path.realpath(dir_path + '/' +
119152
self.platform + '.json')
120153
create_directory(dir_path)
121154
current_cmd = list(cmd)
122155
current_cmd.extend(['-module', module])
123156
current_cmd.extend(['-o', file_path])
124-
check_call(current_cmd, verbose=verbose)
157+
check_call(current_cmd, env=_environ, verbose=verbose)
125158
else:
126159
cmd.extend(['-o', output])
127160
cmd.extend(['-module-list-file', tmp.name])
128-
check_call(cmd, verbose=verbose)
161+
check_call(cmd, env=_environ, verbose=verbose)
129162

130163

131164
class DiagnoseConfig:
@@ -214,21 +247,21 @@ def main():
214247
fatal_error("Need to specify --output")
215248
if args.module_filter == '':
216249
module_filter_flags = []
217-
include_fixed_modules = True
250+
include_fixed_clang_modules = True
218251
elif args.module_filter == 'swift-frameworks-only':
219252
module_filter_flags = ['--swift-frameworks-only']
220-
include_fixed_modules = False
253+
include_fixed_clang_modules = False
221254
elif args.module_filter == 'swift-overlay-only':
222255
module_filter_flags = ['--swift-overlay-only']
223-
include_fixed_modules = False
256+
include_fixed_clang_modules = False
224257
else:
225258
fatal_error("cannot recognize --module-filter")
226259
runner = DumpConfig(tool_path=args.tool_path, platform=args.target)
227260
runner.run(output=args.output, module=args.module,
228261
swift_ver=args.swift_version, opts=args.opts,
229262
verbose=args.v,
230263
module_filter_flags=module_filter_flags,
231-
include_fixed_modules=include_fixed_modules,
264+
include_fixed_clang_modules=include_fixed_clang_modules,
232265
separate_by_module=args.separate_by_module)
233266
elif args.action == 'diagnose':
234267
if not args.dump_before:

0 commit comments

Comments
 (0)