Chromium Code Reviews| 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 30 matching lines...) Expand all Loading... | |
| 41 TARGETS = [ | 41 TARGETS = [ |
| 42 'webrtc/sdk/android:libwebrtc', | 42 'webrtc/sdk/android:libwebrtc', |
| 43 'webrtc/sdk/android:libjingle_peerconnection_so', | 43 'webrtc/sdk/android:libjingle_peerconnection_so', |
| 44 ] | 44 ] |
| 45 | 45 |
| 46 | 46 |
| 47 def _ParseArgs(): | 47 def _ParseArgs(): |
| 48 parser = argparse.ArgumentParser(description='libwebrtc.aar generator.') | 48 parser = argparse.ArgumentParser(description='libwebrtc.aar generator.') |
| 49 parser.add_argument('--output', default='libwebrtc.aar', | 49 parser.add_argument('--output', default='libwebrtc.aar', |
| 50 help='Output file of the script.') | 50 help='Output file of the script.') |
| 51 parser.add_argument('--arch', action='append', default=[], | 51 parser.add_argument('--arch', action='append', default=DEFAULT_ARCHS, |
|
kjellander_webrtc
2017/02/06 14:44:12
I fixed this for you.
sakal
2017/02/06 14:52:57
Nice if this works but I think I tested this alrea
kjellander_webrtc
2017/02/07 08:02:58
You're right (I didn't test it properly). action n
| |
| 52 help='Architectures to build. Defaults to ' + str(DEFAULT_ARCHS)) | 52 help='Architectures to build. Defaults to %(default)s.') |
| 53 parser.add_argument('--use-goma', action='store_true', default=False, | 53 parser.add_argument('--use-goma', action='store_true', default=False, |
| 54 help='Use goma.') | 54 help='Use goma.') |
| 55 parser.add_argument('--verbose', action='store_true', default=False, | 55 parser.add_argument('--verbose', action='store_true', default=False, |
| 56 help='Debug logging.') | 56 help='Debug logging.') |
| 57 parser.add_argument('--extra-gn-args', action='append', default=[], | |
| 58 help='Additional GN args to be used during Ninja generation.') | |
| 57 return parser.parse_args() | 59 return parser.parse_args() |
| 58 | 60 |
| 59 | 61 |
| 60 def _RunGN(args): | 62 def _RunGN(args): |
| 61 cmd = ['gn'] | 63 cmd = ['gn'] |
| 62 cmd.extend(args) | 64 cmd.extend(args) |
| 63 logging.debug('Running: %r', cmd) | 65 logging.debug('Running: %r', cmd) |
| 64 subprocess.check_call(cmd) | 66 subprocess.check_call(cmd) |
| 65 | 67 |
| 66 | 68 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 if arch == 'armeabi': | 103 if arch == 'armeabi': |
| 102 return 6 | 104 return 6 |
| 103 elif arch == 'armeabi-v7a': | 105 elif arch == 'armeabi-v7a': |
| 104 return 7 | 106 return 7 |
| 105 elif arch == 'x86': | 107 elif arch == 'x86': |
| 106 return None | 108 return None |
| 107 else: | 109 else: |
| 108 raise Exception('Unknown arch: ' + arch) | 110 raise Exception('Unknown arch: ' + arch) |
| 109 | 111 |
| 110 | 112 |
| 111 def Build(tmp_dir, arch, use_goma): | 113 def Build(tmp_dir, arch, use_goma, extra_gn_args): |
| 112 """Generates target architecture using GN and builds it using ninja.""" | 114 """Generates target architecture using GN and builds it using ninja.""" |
| 113 logging.info('Building: %s', arch) | 115 logging.info('Building: %s', arch) |
| 114 output_directory = _GetOutputDirectory(tmp_dir, arch) | 116 output_directory = _GetOutputDirectory(tmp_dir, arch) |
| 115 gn_args = { | 117 gn_args = { |
| 116 'target_os': 'android', | 118 'target_os': 'android', |
| 117 'is_debug': False, | 119 'is_debug': False, |
| 118 'is_component_build': False, | 120 'is_component_build': False, |
| 119 'target_cpu': _GetTargetCpu(arch), | 121 'target_cpu': _GetTargetCpu(arch), |
| 120 'use_goma': use_goma | 122 'use_goma': use_goma |
| 121 } | 123 } |
| 122 arm_version = _GetArmVersion(arch) | 124 arm_version = _GetArmVersion(arch) |
| 123 if arm_version: | 125 if arm_version: |
| 124 gn_args['arm_version'] = arm_version | 126 gn_args['arm_version'] = arm_version |
| 125 gn_args_str = '--args=' + ' '.join([ | 127 gn_args_str = '--args=' + ' '.join([ |
| 126 k + '=' + _EncodeForGN(v) for k, v in gn_args.items()]) | 128 k + '=' + _EncodeForGN(v) for k, v in gn_args.items()] + extra_gn_args) |
| 127 | 129 |
| 128 _RunGN(['gen', output_directory, gn_args_str]) | 130 _RunGN(['gen', output_directory, gn_args_str]) |
| 129 | 131 |
| 130 ninja_args = TARGETS | 132 ninja_args = TARGETS |
| 131 if use_goma: | 133 if use_goma: |
| 132 ninja_args.extend(['-j', '1024']) | 134 ninja_args.extend(['-j', '1024']) |
| 133 _RunNinja(output_directory, ninja_args) | 135 _RunNinja(output_directory, ninja_args) |
| 134 | 136 |
| 135 | 137 |
| 136 def CollectCommon(aar_file, tmp_dir, arch): | 138 def CollectCommon(aar_file, tmp_dir, arch): |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 147 output_directory = _GetOutputDirectory(tmp_dir, arch) | 149 output_directory = _GetOutputDirectory(tmp_dir, arch) |
| 148 | 150 |
| 149 abi_dir = os.path.join('jni', arch) | 151 abi_dir = os.path.join('jni', arch) |
| 150 for so_file in NEEDED_SO_FILES: | 152 for so_file in NEEDED_SO_FILES: |
| 151 aar_file.write(os.path.join(output_directory, so_file), | 153 aar_file.write(os.path.join(output_directory, so_file), |
| 152 os.path.join(abi_dir, so_file)) | 154 os.path.join(abi_dir, so_file)) |
| 153 | 155 |
| 154 | 156 |
| 155 def main(): | 157 def main(): |
| 156 args = _ParseArgs() | 158 args = _ParseArgs() |
| 157 if not args.arch: | |
| 158 args.arch = DEFAULT_ARCHS | |
| 159 | |
| 160 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) | 159 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) |
| 161 | 160 |
| 162 tmp_dir = tempfile.mkdtemp() | 161 tmp_dir = tempfile.mkdtemp() |
| 163 | 162 |
| 164 for arch in args.arch: | 163 for arch in args.arch: |
| 165 Build(tmp_dir, arch, args.use_goma) | 164 Build(tmp_dir, arch, args.use_goma, args.extra_gn_args) |
| 166 | 165 |
| 167 with zipfile.ZipFile(args.output, 'w') as aar_file: | 166 with zipfile.ZipFile(args.output, 'w') as aar_file: |
| 168 # Architecture doesn't matter here, arbitrarily using the first one. | 167 # Architecture doesn't matter here, arbitrarily using the first one. |
| 169 CollectCommon(aar_file, tmp_dir, args.arch[0]) | 168 CollectCommon(aar_file, tmp_dir, args.arch[0]) |
| 170 for arch in args.arch: | 169 for arch in args.arch: |
| 171 Collect(aar_file, tmp_dir, arch) | 170 Collect(aar_file, tmp_dir, arch) |
| 172 | 171 |
| 173 shutil.rmtree(tmp_dir, True) | 172 shutil.rmtree(tmp_dir, True) |
| 174 | 173 |
| 175 | 174 |
| 176 if __name__ == '__main__': | 175 if __name__ == '__main__': |
| 177 sys.exit(main()) | 176 sys.exit(main()) |
| OLD | NEW |