Skip to content

Commit c0672e9

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-next
2 parents 0f36f29 + 0c923e0 commit c0672e9

File tree

7 files changed

+265
-0
lines changed

7 files changed

+265
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
XCTest
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Darwin
2+
Dispatch
3+
MachO
4+
ObjectiveC
5+
libkern
6+
os
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
XCTest
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
XPC
2+
XCTest

utils/api_checker/sdk-module-lists/fixed-modules-watchos.txt

Whitespace-only changes.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/env python -u
2+
3+
import os
4+
import sys
5+
6+
blacklist = ["Kernel", "Ruby", "Tk"]
7+
8+
9+
def get_immediate_subdirectories(a_dir):
10+
return [name for name in os.listdir(a_dir)
11+
if os.path.isdir(os.path.join(a_dir, name))]
12+
13+
14+
def get_frameworks(sdk_path):
15+
frameworks_path = sdk_path + "/System/Library/Frameworks"
16+
names = []
17+
for frame in os.listdir(frameworks_path):
18+
if frame.endswith(".framework"):
19+
header_dir_path = frameworks_path + '/' + frame + '/Headers'
20+
module_dir_path = frameworks_path + '/' + frame + '/Modules'
21+
old_modulemap_path = frameworks_path + '/' + frame + '/module.map'
22+
old_modulemap_private_path = frameworks_path + '/' + frame + \
23+
'/module_private.map'
24+
if not os.path.exists(header_dir_path):
25+
if os.path.exists(module_dir_path):
26+
print >>sys.stderr, header_dir_path, \
27+
" non-existent while 'Modules' exists"
28+
if os.path.exists(old_modulemap_path):
29+
print >>sys.stderr, header_dir_path, \
30+
" non-existent while 'module.map' exists"
31+
if os.path.exists(old_modulemap_private_path):
32+
print >>sys.stderr, header_dir_path, \
33+
" non-existent while 'module_private.map' exists"
34+
continue
35+
36+
if should_exclude_framework(frameworks_path + '/' + frame):
37+
continue
38+
39+
name = frame[:-len(".framework")]
40+
if name in blacklist:
41+
continue
42+
names.append(name)
43+
return names
44+
45+
46+
def should_exclude_framework(frame_path):
47+
module_map_path = frame_path + '/Modules/module.modulemap'
48+
if not os.path.exists(module_map_path):
49+
return False
50+
contents = open(module_map_path).read()
51+
if "requires !swift" in contents:
52+
return True
53+
if "requires unavailable" in contents:
54+
return True
55+
56+
return False
57+
58+
59+
def print_clang_imports(frames, use_hash):
60+
for name in frames:
61+
if use_hash:
62+
print "#import <" + name + "/" + name + ".h>"
63+
else:
64+
print "@import " + name + ";"
65+
66+
67+
def print_swift_imports(frames):
68+
for name in frames:
69+
print "import " + name
70+
71+
72+
def main():
73+
global opts
74+
from optparse import OptionParser
75+
parser = OptionParser("""%prog [options] command
76+
77+
%prog outputs imports
78+
79+
$ %prog -s <sdk-path> -o <output-mode> [--hash]
80+
81+
""")
82+
parser.add_option("-s", "--sdk", help="sdk path",
83+
type=str, dest="sdk", default=None)
84+
parser.add_option("-o", "--output", help="output mode",
85+
type=str, dest="out_mode", default="list")
86+
parser.add_option("--hash", action="store_true", dest="use_hash")
87+
88+
(opts, cmd) = parser.parse_args()
89+
90+
if not opts.sdk:
91+
parser.error("sdk not specified")
92+
93+
if not opts.out_mode:
94+
parser.error(
95+
"output mode not specified: 'clang-import'/'swift-import'/'list'")
96+
97+
frames = get_frameworks(opts.sdk)
98+
if opts.out_mode == "clang-import":
99+
print_clang_imports(frames, opts.use_hash)
100+
elif opts.out_mode == "swift-import":
101+
print_swift_imports(frames)
102+
elif opts.out_mode == "list":
103+
for name in frames:
104+
print name
105+
else:
106+
parser.error(
107+
"output mode not found: 'clang-import'/'swift-import'/'list'")
108+
109+
110+
if __name__ == '__main__':
111+
main()
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
5+
import argparse
6+
import os
7+
import subprocess
8+
import sys
9+
import tempfile
10+
11+
INFER_IMPORT_DIR = \
12+
os.path.dirname(os.path.realpath(__file__)) + '/sdk-module-lists'
13+
14+
INFER_IMPORT_PATH = INFER_IMPORT_DIR + '/infer-imports.py'
15+
16+
17+
def printerr(message):
18+
print(message, file=sys.stderr)
19+
20+
21+
def fatal_error(message):
22+
printerr(message)
23+
sys.exit(1)
24+
25+
26+
def escapeCmdArg(arg):
27+
if '"' in arg or ' ' in arg:
28+
return '"%s"' % arg.replace('"', '\\"')
29+
else:
30+
return arg
31+
32+
33+
def check_call(cmd, cwd=None, env=os.environ, verbose=True, output=None):
34+
if verbose:
35+
print(' '.join([escapeCmdArg(arg) for arg in cmd]))
36+
return subprocess.check_call(cmd, cwd=cwd, env=env,
37+
stderr=subprocess.STDOUT, stdout=output)
38+
39+
40+
def check_output(cmd, verbose=False):
41+
if verbose:
42+
print(' '.join([escapeCmdArg(arg) for arg in cmd]))
43+
return subprocess.check_output(cmd).strip()
44+
45+
46+
def get_sdk_path(platform):
47+
return check_output(['xcrun', '-sdk', platform, '-show-sdk-path'])
48+
49+
50+
def prepare_module_list(platform, file):
51+
check_call([INFER_IMPORT_PATH, '-s', get_sdk_path(platform)], output=file)
52+
with open(INFER_IMPORT_DIR + '/fixed-modules-common.txt', 'r') as extra:
53+
file.write(extra.read())
54+
with open(INFER_IMPORT_DIR + '/fixed-modules-' + platform + '.txt',
55+
'r') as extra:
56+
file.write(extra.read())
57+
58+
59+
class DumpConfig:
60+
def __init__(self, platform):
61+
target_map = {
62+
'iphoneos': 'arm64-apple-ios10.0',
63+
'macosx': 'x86_64-apple-macosx10.11',
64+
'appletvos': 'arm64-apple-tvos10.0',
65+
'watchos': 'armv7k-apple-watchos3.0',
66+
}
67+
self.platform = platform
68+
self.target = target_map[platform]
69+
self.sdk = get_sdk_path(platform)
70+
self.frameworks = [
71+
self.sdk + '/System/Library/Frameworks/',
72+
os.path.realpath(self.sdk + '/../../Library/Frameworks/')]
73+
self.tool_path = check_output(['xcrun', '--find',
74+
'swift-api-digester'])
75+
76+
def run(self, output, module, swift_ver, abi):
77+
cmd = [self.tool_path, '-o', output, '-sdk', self.sdk, '-target',
78+
self.target, '-dump-sdk', '-module-cache-path',
79+
'/tmp/ModuleCache', '-swift-version',
80+
swift_ver, '-abort-on-module-fail']
81+
for path in self.frameworks:
82+
cmd.extend(['-iframework', path])
83+
if abi:
84+
cmd.extend(['-abi'])
85+
if module:
86+
cmd.extend(['-module', module])
87+
check_call(cmd)
88+
else:
89+
with tempfile.NamedTemporaryFile() as tmp:
90+
prepare_module_list(self.platform, tmp)
91+
cmd.extend(['-module-list-file', tmp.name])
92+
check_call(cmd)
93+
94+
95+
def main():
96+
parser = argparse.ArgumentParser(
97+
formatter_class=argparse.RawDescriptionHelpFormatter,
98+
description='''
99+
A convenient wrapper for swift-api-digester.
100+
''')
101+
102+
basic_group = parser.add_argument_group('Basic')
103+
basic_group.add_argument('--action', default='', help='''
104+
the action to perform for swift-api-digester
105+
''')
106+
107+
basic_group.add_argument('--target', default=None, help='''
108+
one of macosx, iphoneos, appletvos, and watchos
109+
''')
110+
111+
basic_group.add_argument('--output', default=None, help='''
112+
the output file of the module baseline should end with .json
113+
''')
114+
115+
basic_group.add_argument('--swift-version', default='4', help='''
116+
Swift version to use; default is 4
117+
''')
118+
119+
basic_group.add_argument('--module', default=None, help='''
120+
name of the module/framework to generate baseline, e.g. Foundation
121+
''')
122+
123+
basic_group.add_argument('--abi',
124+
action='store_true',
125+
help='Whether we are jsonizing for abi')
126+
127+
args = parser.parse_args(sys.argv[1:])
128+
if not args.target:
129+
fatal_error("Need to specify --target")
130+
if not args.output:
131+
fatal_error("Need to specify --output")
132+
133+
if args.action == 'dump':
134+
runner = DumpConfig(platform=args.target)
135+
runner.run(output=args.output, module=args.module,
136+
swift_ver=args.swift_version, abi=args.abi)
137+
elif args.action == 'diagnose':
138+
fatal_error('Not implemented')
139+
else:
140+
fatal_error('Cannot recognize action: ' + args.action)
141+
142+
143+
if __name__ == '__main__':
144+
main()

0 commit comments

Comments
 (0)