OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 3 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
4 # | 4 # |
5 # Use of this source code is governed by a BSD-style license | 5 # Use of this source code is governed by a BSD-style license |
6 # that can be found in the LICENSE file in the root of the source | 6 # that can be found in the LICENSE file in the root of the source |
7 # tree. An additional intellectual property rights grant can be found | 7 # tree. An additional intellectual property rights grant can be found |
8 # in the file PATENTS. All contributing project authors may | 8 # in the file PATENTS. All contributing project authors may |
9 # be found in the AUTHORS file in the root of the source tree. | 9 # be found in the AUTHORS file in the root of the source tree. |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... | |
24 | 24 |
25 | 25 |
26 os.environ['PATH'] = '/usr/libexec' + os.pathsep + os.environ['PATH'] | 26 os.environ['PATH'] = '/usr/libexec' + os.pathsep + os.environ['PATH'] |
27 | 27 |
28 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 28 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
29 WEBRTC_BASE_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, '..', '..')) | 29 WEBRTC_BASE_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, '..', '..')) |
30 SDK_OUTPUT_DIR = os.path.join(WEBRTC_BASE_DIR, 'out_ios_libs') | 30 SDK_OUTPUT_DIR = os.path.join(WEBRTC_BASE_DIR, 'out_ios_libs') |
31 SDK_LIB_NAME = 'librtc_sdk_objc.a' | 31 SDK_LIB_NAME = 'librtc_sdk_objc.a' |
32 SDK_FRAMEWORK_NAME = 'WebRTC.framework' | 32 SDK_FRAMEWORK_NAME = 'WebRTC.framework' |
33 | 33 |
34 ENABLED_ARCHITECTURES = ['arm', 'arm64', 'x64'] | 34 DEFAULT_ARCHS = ['arm64', 'arm', 'x64', 'x86'] |
35 IOS_DEPLOYMENT_TARGET = '8.0' | 35 IOS_DEPLOYMENT_TARGET = '8.0' |
36 LIBVPX_BUILD_VP9 = False | 36 LIBVPX_BUILD_VP9 = False |
37 CUSTOM_GN_OPTS = [] # example: ['some_option=foo bar', 'other_option=true'] | 37 CUSTOM_GN_OPTS = [] # example: ['some_option=foo bar', 'other_option=true'] |
38 | 38 |
39 | 39 |
40 def _ParseArgs(): | 40 def _ParseArgs(): |
41 parser = argparse.ArgumentParser(description=__doc__) | 41 parser = argparse.ArgumentParser(description=__doc__) |
42 parser.add_argument('-b', '--build_type', default='framework', | 42 parser.add_argument('-b', '--build_type', default='framework', |
43 choices=['framework', 'static_only'], | 43 choices=['framework', 'static_only'], |
44 help='The build type. Can be "framework" or "static_only". ' | 44 help='The build type. Can be "framework" or "static_only". ' |
45 'Defaults to "framework".') | 45 'Defaults to "framework".') |
46 parser.add_argument('--build_config', default='release', | 46 parser.add_argument('--build_config', default='release', |
47 choices=['debug', 'release'], | 47 choices=['debug', 'release'], |
48 help='The build config. Can be "debug" or "release". ' | 48 help='The build config. Can be "debug" or "release". ' |
49 'Defaults to "release".') | 49 'Defaults to "release".') |
50 parser.add_argument('--arch', default=DEFAULT_ARCHS, nargs='+', | |
51 help='Architectures to build. Defaults to %(default)s.') | |
50 parser.add_argument('-c', '--clean', action='store_true', default=False, | 52 parser.add_argument('-c', '--clean', action='store_true', default=False, |
51 help='Removes the previously generated build output, if any.') | 53 help='Removes the previously generated build output, if any.') |
52 parser.add_argument('-o', '--output-dir', default=SDK_OUTPUT_DIR, | 54 parser.add_argument('-o', '--output-dir', default=SDK_OUTPUT_DIR, |
53 help='Specifies a directory to output the build artifacts to. ' | 55 help='Specifies a directory to output the build artifacts to. ' |
54 'If specified together with -c, deletes the dir.') | 56 'If specified together with -c, deletes the dir.') |
55 parser.add_argument('-r', '--revision', type=int, default=0, | 57 parser.add_argument('-r', '--revision', type=int, default=0, |
56 help='Specifies a revision number to embed if building the framework.') | 58 help='Specifies a revision number to embed if building the framework.') |
57 parser.add_argument('-e', '--bitcode', action='store_true', default=False, | 59 parser.add_argument('-e', '--bitcode', action='store_true', default=False, |
58 help='Compile with bitcode.') | 60 help='Compile with bitcode.') |
59 parser.add_argument('--verbose', action='store_true', default=False, | 61 parser.add_argument('--verbose', action='store_true', default=False, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 | 130 |
129 def main(): | 131 def main(): |
130 args = _ParseArgs() | 132 args = _ParseArgs() |
131 | 133 |
132 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) | 134 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) |
133 | 135 |
134 if args.clean: | 136 if args.clean: |
135 _CleanArtifacts(args.output_dir) | 137 _CleanArtifacts(args.output_dir) |
136 return 0 | 138 return 0 |
137 | 139 |
140 architectures = list(args.arch) | |
kthelgason
2017/02/09 12:27:53
Maybe make sure that the list only contains archit
oprypin_webrtc
2017/02/09 12:39:47
How can I determine what makes sense? Limit it onl
kjellander_webrtc
2017/02/09 13:24:04
There are only those four today, so you could vali
kthelgason
2017/02/09 13:36:13
Yeah, I was thinking something like:
architectures
oprypin_webrtc
2017/02/11 21:37:00
Done.
| |
141 # Ignoring x86 except for static libraries for now because of a GN build issue | |
142 # where the generated dynamic framework has the wrong architectures. | |
143 if 'x86' in architectures and args.build_type != 'static_only': | |
144 architectures.remove('x86') | |
145 | |
138 # Build all architectures. | 146 # Build all architectures. |
139 for arch in ENABLED_ARCHITECTURES: | 147 for arch in architectures: |
140 BuildWebRTC(args.output_dir, arch, args.build_config, args.build_type, | 148 BuildWebRTC(args.output_dir, arch, args.build_config, args.build_type, |
141 IOS_DEPLOYMENT_TARGET, LIBVPX_BUILD_VP9, args.bitcode, | 149 IOS_DEPLOYMENT_TARGET, LIBVPX_BUILD_VP9, args.bitcode, |
142 CUSTOM_GN_OPTS) | 150 CUSTOM_GN_OPTS) |
143 | 151 |
144 # Ignoring x86 except for static libraries for now because of a GN build issue | |
145 # where the generated dynamic framework has the wrong architectures. | |
146 | |
147 # Create FAT archive. | 152 # Create FAT archive. |
148 if args.build_type == 'static_only': | 153 if args.build_type == 'static_only': |
149 BuildWebRTC(args.output_dir, 'x86', args.build_config, args.build_type, | 154 lib_paths = [os.path.join(args.output_dir, arch + '_libs', SDK_LIB_NAME) |
150 IOS_DEPLOYMENT_TARGET, LIBVPX_BUILD_VP9, args.bitcode, | 155 for arch in architectures] |
151 CUSTOM_GN_OPTS) | 156 out_lib_path = os.path.join(args.output_dir, SDK_LIB_NAME) |
152 | |
153 arm_lib_path = os.path.join(args.output_dir, 'arm_libs', SDK_LIB_NAME) | |
154 arm64_lib_path = os.path.join(args.output_dir, 'arm64_libs', SDK_LIB_NAME) | |
155 x64_lib_path = os.path.join(args.output_dir, 'x64_libs', SDK_LIB_NAME) | |
156 x86_lib_path = os.path.join(args.output_dir, 'x86_libs', SDK_LIB_NAME) | |
157 | |
158 # Combine the slices. | 157 # Combine the slices. |
159 cmd = ['lipo', arm_lib_path, arm64_lib_path, x64_lib_path, x86_lib_path, | 158 cmd = ['lipo'] + lib_paths + ['-create', '-output', out_lib_path] |
160 '-create', '-output', os.path.join(args.output_dir, SDK_LIB_NAME)] | |
161 _RunCommand(cmd) | 159 _RunCommand(cmd) |
162 | 160 |
163 elif args.build_type == 'framework': | 161 elif args.build_type == 'framework': |
164 arm_lib_path = os.path.join(args.output_dir, 'arm_libs') | 162 lib_paths = [os.path.join(args.output_dir, arch + '_libs') |
165 arm64_lib_path = os.path.join(args.output_dir, 'arm64_libs') | 163 for arch in architectures] |
166 x64_lib_path = os.path.join(args.output_dir, 'x64_libs') | |
167 | 164 |
168 # Combine the slices. | 165 # Combine the slices. |
169 dylib_path = os.path.join(SDK_FRAMEWORK_NAME, 'WebRTC') | 166 dylib_path = os.path.join(SDK_FRAMEWORK_NAME, 'WebRTC') |
167 # Dylibs will be combined, all other files are the same across archs. | |
170 # Use distutils instead of shutil to support merging folders. | 168 # Use distutils instead of shutil to support merging folders. |
171 distutils.dir_util.copy_tree( | 169 distutils.dir_util.copy_tree( |
172 os.path.join(arm64_lib_path, SDK_FRAMEWORK_NAME), | 170 os.path.join(lib_paths[0], SDK_FRAMEWORK_NAME), |
173 os.path.join(args.output_dir, SDK_FRAMEWORK_NAME)) | 171 os.path.join(args.output_dir, SDK_FRAMEWORK_NAME)) |
174 try: | 172 try: |
175 os.remove(os.path.join(args.output_dir, dylib_path)) | 173 os.remove(os.path.join(args.output_dir, dylib_path)) |
176 except OSError: | 174 except OSError: |
177 pass | 175 pass |
178 logging.info('Merging framework slices.') | 176 logging.info('Merging framework slices.') |
179 cmd = ['lipo', os.path.join(arm_lib_path, dylib_path), | 177 dylib_paths = [os.path.join(path, dylib_path) for path in lib_paths] |
180 os.path.join(arm64_lib_path, dylib_path), | 178 out_dylib_path = os.path.join(args.output_dir, dylib_path) |
181 os.path.join(x64_lib_path, dylib_path), | 179 cmd = ['lipo'] + dylib_paths + ['-create', '-output', out_dylib_path] |
182 '-create', '-output', os.path.join(args.output_dir, dylib_path)] | |
183 _RunCommand(cmd) | 180 _RunCommand(cmd) |
184 | 181 |
185 # Merge the dSYM slices. | 182 # Merge the dSYM slices. |
186 dsym_path = os.path.join('WebRTC.dSYM', 'Contents', 'Resources', 'DWARF', | 183 dsym_path = os.path.join('WebRTC.dSYM', 'Contents', 'Resources', 'DWARF', |
187 'WebRTC') | 184 'WebRTC') |
188 distutils.dir_util.copy_tree(os.path.join(arm64_lib_path, 'WebRTC.dSYM'), | 185 distutils.dir_util.copy_tree(os.path.join(lib_paths[0], 'WebRTC.dSYM'), |
189 os.path.join(args.output_dir, 'WebRTC.dSYM')) | 186 os.path.join(args.output_dir, 'WebRTC.dSYM')) |
190 try: | 187 try: |
191 os.remove(os.path.join(args.output_dir, dsym_path)) | 188 os.remove(os.path.join(args.output_dir, dsym_path)) |
192 except OSError: | 189 except OSError: |
193 pass | 190 pass |
194 logging.info('Merging dSYM slices.') | 191 logging.info('Merging dSYM slices.') |
195 cmd = ['lipo', os.path.join(arm_lib_path, dsym_path), | 192 dsym_paths = [os.path.join(path, dsym_path) for path in lib_paths] |
196 os.path.join(arm64_lib_path, dsym_path), | 193 out_dsym_path = os.path.join(args.output_dir, dsym_path) |
197 os.path.join(x64_lib_path, dsym_path), | 194 cmd = ['lipo'] + dsym_paths + ['-create', '-output', out_dsym_path] |
198 '-create', '-output', os.path.join(args.output_dir, dsym_path)] | |
199 _RunCommand(cmd) | 195 _RunCommand(cmd) |
200 | 196 |
201 # Modify the version number. | 197 # Modify the version number. |
202 # Format should be <Branch cut MXX>.<Hotfix #>.<Rev #>. | 198 # Format should be <Branch cut MXX>.<Hotfix #>.<Rev #>. |
203 # e.g. 55.0.14986 means branch cut 55, no hotfixes, and revision 14986. | 199 # e.g. 55.0.14986 means branch cut 55, no hotfixes, and revision 14986. |
204 infoplist_path = os.path.join(args.output_dir, SDK_FRAMEWORK_NAME, | 200 infoplist_path = os.path.join(args.output_dir, SDK_FRAMEWORK_NAME, |
205 'Info.plist') | 201 'Info.plist') |
206 cmd = ['PlistBuddy', '-c', | 202 cmd = ['PlistBuddy', '-c', |
207 'Print :CFBundleShortVersionString', infoplist_path] | 203 'Print :CFBundleShortVersionString', infoplist_path] |
208 major_minor = subprocess.check_output(cmd).strip() | 204 major_minor = subprocess.check_output(cmd).strip() |
209 version_number = '%s.%s' % (major_minor, args.revision) | 205 version_number = '%s.%s' % (major_minor, args.revision) |
210 logging.info('Substituting revision number: %s', version_number) | 206 logging.info('Substituting revision number: %s', version_number) |
211 cmd = ['PlistBuddy', '-c', | 207 cmd = ['PlistBuddy', '-c', |
212 'Set :CFBundleVersion ' + version_number, infoplist_path] | 208 'Set :CFBundleVersion ' + version_number, infoplist_path] |
213 _RunCommand(cmd) | 209 _RunCommand(cmd) |
214 _RunCommand(['plutil', '-convert', 'binary1', infoplist_path]) | 210 _RunCommand(['plutil', '-convert', 'binary1', infoplist_path]) |
215 | 211 |
216 logging.info('Done.') | 212 logging.info('Done.') |
217 return 0 | 213 return 0 |
218 | 214 |
219 | 215 |
220 if __name__ == '__main__': | 216 if __name__ == '__main__': |
221 sys.exit(main()) | 217 sys.exit(main()) |
OLD | NEW |