Skip to content

swift-api-checker: teach the script to collect Swift only frameworks from the SDK. #25434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions utils/api_checker/sdk-module-lists/infer-imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_immediate_subdirectories(a_dir):
if os.path.isdir(os.path.join(a_dir, name))]


def get_frameworks(sdk_path):
def get_frameworks(sdk_path, swift_frameworks_only):
frameworks_path = sdk_path + "/System/Library/Frameworks"
names = []
for frame in os.listdir(frameworks_path):
Expand All @@ -32,6 +32,9 @@ def get_frameworks(sdk_path):
if name not in blacklist:
names.append(name)
continue
# We only care about Swift frameworks then we are done.
if swift_frameworks_only:
continue

if not os.path.exists(header_dir_path):
if os.path.exists(module_dir_path):
Expand Down Expand Up @@ -95,7 +98,8 @@ def main():
parser.add_option("-o", "--output", help="output mode",
type=str, dest="out_mode", default="list")
parser.add_option("--hash", action="store_true", dest="use_hash")

parser.add_option("--swift-frameworks-only", action="store_true")
parser.add_option("--v", action="store_true")
(opts, cmd) = parser.parse_args()

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

frames = get_frameworks(opts.sdk)
frames = get_frameworks(opts.sdk, opts.swift_frameworks_only)
if opts.v:
for name in frames:
print >>sys.stderr, 'Including: ', name
if opts.out_mode == "clang-import":
print_clang_imports(frames, opts.use_hash)
elif opts.out_mode == "swift-import":
Expand Down
25 changes: 20 additions & 5 deletions utils/api_checker/swift-api-checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@ def get_sdk_path(platform):
return check_output(['xcrun', '-sdk', platform, '-show-sdk-path'])


def prepare_module_list(platform, file):
check_call([INFER_IMPORT_PATH, '-s', get_sdk_path(platform)], output=file)
def prepare_module_list(platform, file, verbose, swift_frameworks_only):
cmd = [INFER_IMPORT_PATH, '-s', get_sdk_path(platform)]
if swift_frameworks_only:
cmd.extend(['--swift-frameworks-only'])
if verbose:
cmd.extend(['--v'])
check_call(cmd, output=file)
# The fixed modules are all objc frameworks.
if swift_frameworks_only:
return
with open(INFER_IMPORT_DIR + '/fixed-modules-common.txt', 'r') as extra:
file.write(extra.read())
with open(INFER_IMPORT_DIR + '/fixed-modules-' + platform + '.txt',
Expand Down Expand Up @@ -78,7 +86,8 @@ def __init__(self, tool_path, platform):
self.sdk + '/System/Library/Frameworks/',
os.path.realpath(self.sdk + '/../../Library/Frameworks/')]

def run(self, output, module, swift_ver, opts, verbose):
def run(self, output, module, swift_ver, opts, verbose,
swift_frameworks_only):
cmd = [self.tool_path, '-o', output, '-sdk', self.sdk, '-target',
self.target, '-dump-sdk', '-module-cache-path',
'/tmp/ModuleCache', '-swift-version',
Expand All @@ -93,7 +102,8 @@ def run(self, output, module, swift_ver, opts, verbose):
check_call(cmd, verbose=verbose)
else:
with tempfile.NamedTemporaryFile() as tmp:
prepare_module_list(self.platform, tmp)
prepare_module_list(self.platform, tmp, verbose,
swift_frameworks_only)
cmd.extend(['-module-list-file', tmp.name])
check_call(cmd, verbose=verbose)

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

basic_group.add_argument('--swift-frameworks-only',
action='store_true',
help='Only include Swift frameworks in the dump')

basic_group.add_argument('--opts', nargs='+', default=[], help='''
additional flags to pass to swift-api-digester
''')
Expand Down Expand Up @@ -176,7 +190,8 @@ def main():
runner = DumpConfig(tool_path=args.tool_path, platform=args.target)
runner.run(output=args.output, module=args.module,
swift_ver=args.swift_version, opts=args.opts,
verbose=args.v)
verbose=args.v,
swift_frameworks_only=args.swift_frameworks_only)
elif args.action == 'diagnose':
if not args.dump_before:
fatal_error("Need to specify --dump-before")
Expand Down