5"""Prints the lowest locally available SDK version greater than or equal to a
6given minimum sdk version to standard output.
9 python3 find_sdk.py 10.6
17from optparse import OptionParser
20# sdk/build/xcode_links
21ROOT_SRC_DIR = os.path.join(
23 os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
28 Create symlink to Xcode directory at target location, which can be absolute or
29 relative to `ROOT_SRC_DIR`.
33 if not os.path.isabs(dst):
34 dst = os.path.join(ROOT_SRC_DIR, dst)
36 if not os.path.isdir(dst):
39 dst = os.path.join(dst, os.path.basename(src))
42 if os.path.islink(dst):
43 current_src = os.readlink(dst)
44 if current_src == src:
48 sys.stderr.write(
'existing symlink %s points %s; want %s. Removed.' %
49 (dst, current_src, src))
56 """'10.6' => [10, 6]"""
57 return list(
map(int, re.findall(
r'(\d+)', version_str)))
61 parser = OptionParser()
67 help=
"return the sdk argument and warn if it doesn't exist")
74 help=
"user-specified SDK path; bypasses verification")
78 dest=
"print_sdk_path",
80 help=
"Additionally print the path the SDK (appears first).")
82 "--create_symlink_at",
84 dest=
"create_symlink_at",
86 "Create symlink to SDK at given location and return symlink path as SDK "
87 "info instead of the original location.")
88 (options, args) = parser.parse_args()
89 min_sdk_version = args[0]
91 job = subprocess.Popen([
'xcode-select',
'-print-path'],
92 stdout=subprocess.PIPE,
93 stderr=subprocess.STDOUT,
94 universal_newlines=
True)
95 out, err = job.communicate()
96 if job.returncode != 0:
97 print(out, file=sys.stderr)
98 print(err, file=sys.stderr)
99 raise Exception(
'Error %d running xcode-select' % job.returncode)
100 sdk_dir = os.path.join(out.rstrip(),
101 'Platforms/MacOSX.platform/Developer/SDKs')
102 if not os.path.isdir(sdk_dir):
104 'Install Xcode, launch it, accept the license ' +
105 'agreement, and run `sudo xcode-select -s /path/to/Xcode.app` ' +
108 re.findall(
'^MacOSX(\d+\.\d+)\.sdk$', s)
for s
in os.listdir(sdk_dir)
110 sdks = [s[0]
for s
in sdks
if s]
116 raise Exception(
'No %s+ SDK found' % min_sdk_version)
117 best_sdk = sorted(sdks, key=parse_version)[0]
119 if options.verify
and best_sdk != min_sdk_version
and not options.sdk_path:
123This build requires the %s SDK, but it was not found on your system.
125Either install it,
or explicitly set mac_sdk
in your GYP_DEFINES.
128''' % min_sdk_version,
130 return min_sdk_version
132 if options.print_sdk_path:
133 sdk_path = subprocess.check_output(
134 [
'xcodebuild',
'-version',
'-sdk',
'macosx' + best_sdk,
'Path'],
135 universal_newlines=
True).strip()
136 if options.create_symlink_at:
144if __name__ ==
'__main__':
145 if sys.platform !=
'darwin':
146 raise Exception(
"This script only runs on Mac")
def CreateSymlinkForSDKAt(src, dst)
def parse_version(version_str)
def print(*args, **kwargs)
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>