Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
find_sdk Namespace Reference

Functions

 CreateSymlinkForSDKAt (src, dst)
 
 parse_version (version_str)
 
 main ()
 

Variables

 ROOT_SRC_DIR
 

Detailed Description

Prints the lowest locally available SDK version greater than or equal to a
given minimum sdk version to standard output.

Usage:
  python3 find_sdk.py 10.6  # Ignores SDKs < 10.6

Function Documentation

◆ CreateSymlinkForSDKAt()

find_sdk.CreateSymlinkForSDKAt (   src,
  dst 
)
Create symlink to Xcode directory at target location, which can be absolute or
relative to `ROOT_SRC_DIR`.

Definition at line 26 of file find_sdk.py.

26def CreateSymlinkForSDKAt(src, dst):
27 """
28 Create symlink to Xcode directory at target location, which can be absolute or
29 relative to `ROOT_SRC_DIR`.
30 """
31
32 # If `dst` is relative, it is assumed to be relative to src root.
33 if not os.path.isabs(dst):
34 dst = os.path.join(ROOT_SRC_DIR, dst)
35
36 if not os.path.isdir(dst):
37 os.makedirs(dst)
38
39 dst = os.path.join(dst, os.path.basename(src))
40
41 # Update the symlink if exists.
42 if os.path.islink(dst):
43 current_src = os.readlink(dst)
44 if current_src == src:
45 return dst
46
47 os.unlink(dst)
48 sys.stderr.write('existing symlink %s points %s; want %s. Removed.' %
49 (dst, current_src, src))
50
51 os.symlink(src, dst)
52 return dst
53
54

◆ main()

find_sdk.main ( )

Definition at line 60 of file find_sdk.py.

60def main():
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] # [['10.5'], ['10.6']] => ['10.5', '10.6']
111 sdks = [
112 s for s in sdks # ['10.5', '10.6'] => ['10.6']
113 if parse_version(s) >= parse_version(min_sdk_version)
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:
120 print('''
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:
137 print(CreateSymlinkForSDKAt(sdk_path, options.create_symlink_at))
138 else:
139 print(sdk_path)
140
141 return best_sdk
142
143
void print(void *str)
Definition bridge.cpp:126
Definition main.py:1

◆ parse_version()

find_sdk.parse_version (   version_str)
'10.6' => [10, 6]

Definition at line 55 of file find_sdk.py.

55def parse_version(version_str):
56 """'10.6' => [10, 6]"""
57 return list(map(int, re.findall(r'(\d+)', version_str)))
58
59

Variable Documentation

◆ ROOT_SRC_DIR

find_sdk.ROOT_SRC_DIR
Initial value:
1= os.path.join(
2 os.path.dirname(
3 os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))

Definition at line 21 of file find_sdk.py.