Skip to content

Commit 6a502aa

Browse files
committed
swift-api-checker: allow users to specify the path of a swift-api-digester
1 parent 51bd604 commit 6a502aa

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

utils/api_checker/swift-api-checker.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,27 @@ def prepare_module_list(platform, file):
5656
file.write(extra.read())
5757

5858

59+
def get_api_digester_path(tool_path):
60+
if tool_path:
61+
return tool_path
62+
return check_output(['xcrun', '--find', 'swift-api-digester'])
63+
64+
5965
class DumpConfig:
60-
def __init__(self, platform):
66+
def __init__(self, tool_path, platform):
6167
target_map = {
6268
'iphoneos': 'arm64-apple-ios10.0',
6369
'macosx': 'x86_64-apple-macosx10.11',
6470
'appletvos': 'arm64-apple-tvos10.0',
6571
'watchos': 'armv7k-apple-watchos3.0',
6672
}
73+
self.tool_path = get_api_digester_path(tool_path)
6774
self.platform = platform
6875
self.target = target_map[platform]
6976
self.sdk = get_sdk_path(platform)
7077
self.frameworks = [
7178
self.sdk + '/System/Library/Frameworks/',
7279
os.path.realpath(self.sdk + '/../../Library/Frameworks/')]
73-
self.tool_path = check_output(['xcrun', '--find',
74-
'swift-api-digester'])
7580

7681
def run(self, output, module, swift_ver, abi, verbose):
7782
cmd = [self.tool_path, '-o', output, '-sdk', self.sdk, '-target',
@@ -95,9 +100,8 @@ def run(self, output, module, swift_ver, abi, verbose):
95100

96101

97102
class DiagnoseConfig:
98-
def __init__(self):
99-
self.tool_path = check_output(['xcrun', '--find',
100-
'swift-api-digester'])
103+
def __init__(self, tool_path):
104+
self.tool_path = get_api_digester_path(tool_path)
101105

102106
def run(self, abi, before, after, output, verbose):
103107
cmd = [self.tool_path, '-diagnose-sdk', '-input-paths', before,
@@ -119,6 +123,12 @@ def main():
119123
''')
120124

121125
basic_group = parser.add_argument_group('Basic')
126+
127+
basic_group.add_argument('--tool-path', default=None, help='''
128+
the path to a swift-api-digester; if not specified, the script will
129+
use the one from the toolchain
130+
''')
131+
122132
basic_group.add_argument('--action', default='', help='''
123133
the action to perform for swift-api-digester
124134
''')
@@ -165,15 +175,15 @@ def main():
165175
fatal_error("Need to specify --target")
166176
if not args.output:
167177
fatal_error("Need to specify --output")
168-
runner = DumpConfig(platform=args.target)
178+
runner = DumpConfig(tool_path=args.tool_path, platform=args.target)
169179
runner.run(output=args.output, module=args.module,
170180
swift_ver=args.swift_version, abi=args.abi, verbose=args.v)
171181
elif args.action == 'diagnose':
172182
if not args.dump_before:
173183
fatal_error("Need to specify --dump-before")
174184
if not args.dump_after:
175185
fatal_error("Need to specify --dump-after")
176-
runner = DiagnoseConfig()
186+
runner = DiagnoseConfig(tool_path=args.tool_path)
177187
runner.run(abi=args.abi, before=args.dump_before,
178188
after=args.dump_after, output=args.output, verbose=args.v)
179189
else:

0 commit comments

Comments
 (0)