61 parser = OptionParser()
62 parser.add_option(
63 "--verify",
64 action="store_true",
65 dest="verify",
66 default=False,
67 help="return the sdk argument and warn if it doesn't exist")
68 parser.add_option(
69 "--sdk_path",
70 action="store",
71 type="string",
72 dest="sdk_path",
73 default="",
74 help="user-specified SDK path; bypasses verification")
75 parser.add_option(
76 "--print_sdk_path",
77 action="store_true",
78 dest="print_sdk_path",
79 default=False,
80 help="Additionally print the path the SDK (appears first).")
81 parser.add_option(
82 "--create_symlink_at",
83 action="store",
84 dest="create_symlink_at",
85 help=
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]
90
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):
103 raise Exception(
104 'Install Xcode, launch it, accept the license ' +
105 'agreement, and run `sudo xcode-select -s /path/to/Xcode.app` ' +
106 'to continue.')
107 sdks = [
108 re.findall('^MacOSX(\d+\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)
109 ]
110 sdks = [s[0] for s in sdks if s]
111 sdks = [
112 s for s in sdks
114 ]
115 if not sdks:
116 raise Exception('No %s+ SDK found' % min_sdk_version)
117 best_sdk = sorted(sdks, key=parse_version)[0]
118
119 if options.verify and best_sdk != min_sdk_version and not options.sdk_path:
121 vvvvvvv
122
123This build requires the %s SDK, but it was not found on your system.
124
125Either install it, or explicitly set mac_sdk in your GYP_DEFINES.
126
127 ^^^^^^^'
128''' % min_sdk_version,
129 file=sys.stderr)
130 return min_sdk_version
131
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:
138 else:
140
141 return best_sdk
142
143
def parse_version(version_str)
def print(*args, **kwargs)