Skip to content

Commit 053f3b4

Browse files
authored
Merge pull request #5281 from DougGregor/swift-api-dump-fixes
2 parents 16c2b0d + 2354929 commit 053f3b4

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ ImportPaths("I", llvm::cl::desc("add a directory to the import search path"));
246246
static llvm::cl::list<std::string>
247247
FrameworkPaths("F", llvm::cl::desc("add a directory to the framework search path"));
248248

249+
static llvm::cl::list<std::string>
250+
SystemFrameworkPaths("iframework", llvm::cl::desc("add a directory to the system framework search path"));
251+
249252
static llvm::cl::opt<std::string>
250253
ResourceDir("resource-dir",
251254
llvm::cl::desc("The directory that holds the compiler resource files"));
@@ -2783,6 +2786,11 @@ int main(int argc, char *argv[]) {
27832786
options::ModuleCachePath;
27842787
InitInvok.setImportSearchPaths(options::ImportPaths);
27852788
InitInvok.setFrameworkSearchPaths(options::FrameworkPaths);
2789+
for (const auto &systemFrameworkPath : options::SystemFrameworkPaths) {
2790+
auto &extraArgs = InitInvok.getClangImporterOptions().ExtraArgs;
2791+
extraArgs.push_back("-iframework");
2792+
extraArgs.push_back(systemFrameworkPath);
2793+
}
27862794
InitInvok.getFrontendOptions().EnableSourceImport |=
27872795
options::EnableSourceImport;
27882796
InitInvok.getFrontendOptions().ImplicitObjCHeaderPath =

utils/swift-api-dump.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
#!/usr/bin/env python
22

3-
# This tool dumps imported Swift APIs to help validate changes in the
4-
# Clang importer and its heuristics. One can execute it to dump the
5-
# API of a given module within a particular SDK, e.g., UIKit from the
6-
# iOS SDK as seen in Swift 3 after the "grand renaming":
3+
# This tool dumps imported Swift APIs to help validate changes in the projection
4+
# of (Objective-)C APIs into Swift, which is a function of the (Objective-)C
5+
# APIs, any API notes added on top of those APIs, and the Clang importer
6+
# itself. One can execute it to dump the API of a given module within a
7+
# particular SDK, e.g., UIKit from the iOS SDK as seen in Swift 3 compatibility
8+
# mode:
79
#
8-
# /path/to/bin/dir/swift-api-dump.py -3 -o output-dir -m UIKit -s iphoneos
10+
# /path/to/bin/dir/swift-api-dump.py -swift-version 3 -o output-dir -m UIKit -s iphoneos
911
#
10-
# The -3 argument indicates that we're using the Swift 3 Clang
11-
# importer rules. The "-m" argument can be omitted, in which case the
12-
# script will collect all of the frameworks in the named SDK(s) and
13-
# dump their APIs.
12+
# The "-m" argument can be omitted, in which case the script will collect all of
13+
# the frameworks in the named SDK(s) and dump their APIs.
1414
#
1515
# One can supply multiple SDKs, written as a list. For example, to
16-
# dump the API for all frameworks across OS X, iOS, watchOS, and tvOS,
17-
# with the Swift 3 rules, use:
16+
# dump the API for all frameworks across macOS, iOS, watchOS, and tvOS,
17+
# in Swift 4, use:
1818
#
19-
# /path/to/bin/dir/swift-api-dump.py -3 -o output-dir -s macosx iphoneos \
19+
# /path/to/bin/dir/swift-api-dump.py -swift-version 4 -o output-dir -s macosx iphoneos \
2020
# watchos appletvos
2121
#
2222

@@ -93,11 +93,15 @@ def create_parser():
9393
help='Print extra information.')
9494
parser.add_argument('-F', '--framework-dir', action='append',
9595
help='Add additional framework directories')
96+
parser.add_argument('-iframework', '--system-framework-dir', action='append',
97+
help='Add additional system framework directories')
9698
parser.add_argument('-I', '--include-dir', action='append',
9799
help='Add additional include directories')
98100
parser.add_argument('--enable-infer-import-as-member', action='store_true',
99101
help='Infer when a global could be imported as a ' +
100102
'member.')
103+
parser.add_argument('-swift-version', type=int, metavar='N',
104+
help='the Swift version to use')
101105
return parser
102106

103107

@@ -187,7 +191,7 @@ def dump_module_api((cmd, extra_dump_args, output_dir, module, quiet,
187191

188192
def pretty_sdk_name(sdk):
189193
if sdk.find("macosx") == 0:
190-
return 'OSX'
194+
return 'macOS'
191195
if sdk.find("iphoneos") == 0:
192196
return 'iOS'
193197
if sdk.find("watchos") == 0:
@@ -277,14 +281,16 @@ def main():
277281
'-module-print-skip-overlay',
278282
'-skip-unavailable',
279283
'-skip-print-doc-comments',
280-
'-always-argument-labels',
281284
'-skip-overrides'
282285
]
283286

284-
# Add -F / -I arguments.
287+
# Add -F / -iframework / -I arguments.
285288
if args.framework_dir:
286289
for path in args.framework_dir:
287290
cmd_common = cmd_common + ['-F', path]
291+
if args.system_framework_dir:
292+
for path in args.system_framework_dir:
293+
cmd_common = cmd_common + ['-iframework', path]
288294
if args.include_dir:
289295
for path in args.include_dir:
290296
cmd_common = cmd_common + ['-I', path]
@@ -293,6 +299,9 @@ def main():
293299
extra_args = ['-skip-imports']
294300
if args.enable_infer_import_as_member:
295301
extra_args = extra_args + ['-enable-infer-import-as-member']
302+
if args.swift_version:
303+
extra_args = extra_args + ['-swift-version', '%d' % args.swift_version]
304+
296305
# Create a .swift file we can feed into swift-ide-test
297306
subprocess.call(['touch', source_filename])
298307

0 commit comments

Comments
 (0)