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 = ENABLED_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 | 37 |
38 | 38 |
39 def _ParseArgs(): | 39 def _ParseArgs(): |
40 parser = argparse.ArgumentParser(description=__doc__) | 40 parser = argparse.ArgumentParser(description=__doc__) |
41 parser.add_argument('-b', '--build_type', default='framework', | 41 parser.add_argument('-b', '--build_type', default='framework', |
42 choices=['framework', 'static_only'], | 42 choices=['framework', 'static_only'], |
43 help='The build type. Can be "framework" or "static_only". ' | 43 help='The build type. Can be "framework" or "static_only". ' |
44 'Defaults to "framework".') | 44 'Defaults to "framework".') |
45 parser.add_argument('--build_config', default='release', | 45 parser.add_argument('--build_config', default='release', |
46 choices=['debug', 'release'], | 46 choices=['debug', 'release'], |
47 help='The build config. Can be "debug" or "release". ' | 47 help='The build config. Can be "debug" or "release". ' |
48 'Defaults to "release".') | 48 'Defaults to "release".') |
| 49 parser.add_argument('--arch', nargs='+', default=DEFAULT_ARCHS, |
| 50 choices=ENABLED_ARCHS, |
| 51 help='Architectures to build. Defaults to %(default)s.') |
49 parser.add_argument('-c', '--clean', action='store_true', default=False, | 52 parser.add_argument('-c', '--clean', action='store_true', default=False, |
50 help='Removes the previously generated build output, if any.') | 53 help='Removes the previously generated build output, if any.') |
51 parser.add_argument('-o', '--output-dir', default=SDK_OUTPUT_DIR, | 54 parser.add_argument('-o', '--output-dir', default=SDK_OUTPUT_DIR, |
52 help='Specifies a directory to output the build artifacts to. ' | 55 help='Specifies a directory to output the build artifacts to. ' |
53 'If specified together with -c, deletes the dir.') | 56 'If specified together with -c, deletes the dir.') |
54 parser.add_argument('-r', '--revision', type=int, default=0, | 57 parser.add_argument('-r', '--revision', type=int, default=0, |
55 help='Specifies a revision number to embed if building the framework.') | 58 help='Specifies a revision number to embed if building the framework.') |
56 parser.add_argument('-e', '--bitcode', action='store_true', default=False, | 59 parser.add_argument('-e', '--bitcode', action='store_true', default=False, |
57 help='Compile with bitcode.') | 60 help='Compile with bitcode.') |
58 parser.add_argument('--verbose', action='store_true', default=False, | 61 parser.add_argument('--verbose', action='store_true', default=False, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 134 |
132 def main(): | 135 def main(): |
133 args = _ParseArgs() | 136 args = _ParseArgs() |
134 | 137 |
135 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) | 138 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) |
136 | 139 |
137 if args.clean: | 140 if args.clean: |
138 _CleanArtifacts(args.output_dir) | 141 _CleanArtifacts(args.output_dir) |
139 return 0 | 142 return 0 |
140 | 143 |
| 144 architectures = list(args.arch) |
| 145 # Ignoring x86 except for static libraries for now because of a GN build issue |
| 146 # where the generated dynamic framework has the wrong architectures. |
| 147 if 'x86' in architectures and args.build_type != 'static_only': |
| 148 architectures.remove('x86') |
| 149 |
141 # Build all architectures. | 150 # Build all architectures. |
142 for arch in ENABLED_ARCHITECTURES: | 151 for arch in architectures: |
143 BuildWebRTC(args.output_dir, arch, args.build_config, args.build_type, | 152 BuildWebRTC(args.output_dir, arch, args.build_config, args.build_type, |
144 IOS_DEPLOYMENT_TARGET, LIBVPX_BUILD_VP9, args.bitcode, | 153 IOS_DEPLOYMENT_TARGET, LIBVPX_BUILD_VP9, args.bitcode, |
145 args.use_goma, args.extra_gn_args) | 154 args.use_goma, args.extra_gn_args) |
146 | 155 |
147 # Ignoring x86 except for static libraries for now because of a GN build issue | |
148 # where the generated dynamic framework has the wrong architectures. | |
149 | |
150 # Create FAT archive. | 156 # Create FAT archive. |
151 if args.build_type == 'static_only': | 157 if args.build_type == 'static_only': |
152 BuildWebRTC(args.output_dir, 'x86', args.build_config, args.build_type, | 158 lib_paths = [os.path.join(args.output_dir, arch + '_libs', SDK_LIB_NAME) |
153 IOS_DEPLOYMENT_TARGET, LIBVPX_BUILD_VP9, args.bitcode, | 159 for arch in architectures] |
154 args.use_goma, args.extra_gn_args) | 160 out_lib_path = os.path.join(args.output_dir, SDK_LIB_NAME) |
155 | |
156 arm_lib_path = os.path.join(args.output_dir, 'arm_libs', SDK_LIB_NAME) | |
157 arm64_lib_path = os.path.join(args.output_dir, 'arm64_libs', SDK_LIB_NAME) | |
158 x64_lib_path = os.path.join(args.output_dir, 'x64_libs', SDK_LIB_NAME) | |
159 x86_lib_path = os.path.join(args.output_dir, 'x86_libs', SDK_LIB_NAME) | |
160 | |
161 # Combine the slices. | 161 # Combine the slices. |
162 cmd = ['lipo', arm_lib_path, arm64_lib_path, x64_lib_path, x86_lib_path, | 162 cmd = ['lipo'] + lib_paths + ['-create', '-output', out_lib_path] |
163 '-create', '-output', os.path.join(args.output_dir, SDK_LIB_NAME)] | |
164 _RunCommand(cmd) | 163 _RunCommand(cmd) |
165 | 164 |
166 elif args.build_type == 'framework': | 165 elif args.build_type == 'framework': |
167 arm_lib_path = os.path.join(args.output_dir, 'arm_libs') | 166 lib_paths = [os.path.join(args.output_dir, arch + '_libs') |
168 arm64_lib_path = os.path.join(args.output_dir, 'arm64_libs') | 167 for arch in architectures] |
169 x64_lib_path = os.path.join(args.output_dir, 'x64_libs') | |
170 | 168 |
171 # Combine the slices. | 169 # Combine the slices. |
172 dylib_path = os.path.join(SDK_FRAMEWORK_NAME, 'WebRTC') | 170 dylib_path = os.path.join(SDK_FRAMEWORK_NAME, 'WebRTC') |
| 171 # Dylibs will be combined, all other files are the same across archs. |
173 # Use distutils instead of shutil to support merging folders. | 172 # Use distutils instead of shutil to support merging folders. |
174 distutils.dir_util.copy_tree( | 173 distutils.dir_util.copy_tree( |
175 os.path.join(arm64_lib_path, SDK_FRAMEWORK_NAME), | 174 os.path.join(lib_paths[0], SDK_FRAMEWORK_NAME), |
176 os.path.join(args.output_dir, SDK_FRAMEWORK_NAME)) | 175 os.path.join(args.output_dir, SDK_FRAMEWORK_NAME)) |
177 try: | 176 try: |
178 os.remove(os.path.join(args.output_dir, dylib_path)) | 177 os.remove(os.path.join(args.output_dir, dylib_path)) |
179 except OSError: | 178 except OSError: |
180 pass | 179 pass |
181 logging.info('Merging framework slices.') | 180 logging.info('Merging framework slices.') |
182 cmd = ['lipo', os.path.join(arm_lib_path, dylib_path), | 181 dylib_paths = [os.path.join(path, dylib_path) for path in lib_paths] |
183 os.path.join(arm64_lib_path, dylib_path), | 182 out_dylib_path = os.path.join(args.output_dir, dylib_path) |
184 os.path.join(x64_lib_path, dylib_path), | 183 cmd = ['lipo'] + dylib_paths + ['-create', '-output', out_dylib_path] |
185 '-create', '-output', os.path.join(args.output_dir, dylib_path)] | |
186 _RunCommand(cmd) | 184 _RunCommand(cmd) |
187 | 185 |
188 # Merge the dSYM slices. | 186 # Merge the dSYM slices. |
189 dsym_path = os.path.join('WebRTC.dSYM', 'Contents', 'Resources', 'DWARF', | 187 dsym_path = os.path.join('WebRTC.dSYM', 'Contents', 'Resources', 'DWARF', |
190 'WebRTC') | 188 'WebRTC') |
191 distutils.dir_util.copy_tree(os.path.join(arm64_lib_path, 'WebRTC.dSYM'), | 189 distutils.dir_util.copy_tree(os.path.join(lib_paths[0], 'WebRTC.dSYM'), |
192 os.path.join(args.output_dir, 'WebRTC.dSYM')) | 190 os.path.join(args.output_dir, 'WebRTC.dSYM')) |
193 try: | 191 try: |
194 os.remove(os.path.join(args.output_dir, dsym_path)) | 192 os.remove(os.path.join(args.output_dir, dsym_path)) |
195 except OSError: | 193 except OSError: |
196 pass | 194 pass |
197 logging.info('Merging dSYM slices.') | 195 logging.info('Merging dSYM slices.') |
198 cmd = ['lipo', os.path.join(arm_lib_path, dsym_path), | 196 dsym_paths = [os.path.join(path, dsym_path) for path in lib_paths] |
199 os.path.join(arm64_lib_path, dsym_path), | 197 out_dsym_path = os.path.join(args.output_dir, dsym_path) |
200 os.path.join(x64_lib_path, dsym_path), | 198 cmd = ['lipo'] + dsym_paths + ['-create', '-output', out_dsym_path] |
201 '-create', '-output', os.path.join(args.output_dir, dsym_path)] | |
202 _RunCommand(cmd) | 199 _RunCommand(cmd) |
203 | 200 |
204 # Modify the version number. | 201 # Modify the version number. |
205 # Format should be <Branch cut MXX>.<Hotfix #>.<Rev #>. | 202 # Format should be <Branch cut MXX>.<Hotfix #>.<Rev #>. |
206 # e.g. 55.0.14986 means branch cut 55, no hotfixes, and revision 14986. | 203 # e.g. 55.0.14986 means branch cut 55, no hotfixes, and revision 14986. |
207 infoplist_path = os.path.join(args.output_dir, SDK_FRAMEWORK_NAME, | 204 infoplist_path = os.path.join(args.output_dir, SDK_FRAMEWORK_NAME, |
208 'Info.plist') | 205 'Info.plist') |
209 cmd = ['PlistBuddy', '-c', | 206 cmd = ['PlistBuddy', '-c', |
210 'Print :CFBundleShortVersionString', infoplist_path] | 207 'Print :CFBundleShortVersionString', infoplist_path] |
211 major_minor = subprocess.check_output(cmd).strip() | 208 major_minor = subprocess.check_output(cmd).strip() |
212 version_number = '%s.%s' % (major_minor, args.revision) | 209 version_number = '%s.%s' % (major_minor, args.revision) |
213 logging.info('Substituting revision number: %s', version_number) | 210 logging.info('Substituting revision number: %s', version_number) |
214 cmd = ['PlistBuddy', '-c', | 211 cmd = ['PlistBuddy', '-c', |
215 'Set :CFBundleVersion ' + version_number, infoplist_path] | 212 'Set :CFBundleVersion ' + version_number, infoplist_path] |
216 _RunCommand(cmd) | 213 _RunCommand(cmd) |
217 _RunCommand(['plutil', '-convert', 'binary1', infoplist_path]) | 214 _RunCommand(['plutil', '-convert', 'binary1', infoplist_path]) |
218 | 215 |
219 logging.info('Done.') | 216 logging.info('Done.') |
220 return 0 | 217 return 0 |
221 | 218 |
222 | 219 |
223 if __name__ == '__main__': | 220 if __name__ == '__main__': |
224 sys.exit(main()) | 221 sys.exit(main()) |
OLD | NEW |