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 28 matching lines...) Expand all Loading... | |
| 39 JAR_FILE = 'lib.java/webrtc/sdk/android/libwebrtc.jar' | 39 JAR_FILE = 'lib.java/webrtc/sdk/android/libwebrtc.jar' |
| 40 MANIFEST_FILE = 'webrtc/sdk/android/AndroidManifest.xml' | 40 MANIFEST_FILE = 'webrtc/sdk/android/AndroidManifest.xml' |
| 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('--build-dir', | |
| 50 help='Build dir. By default will create and use temporary dir.') | |
| 49 parser.add_argument('--output', default='libwebrtc.aar', | 51 parser.add_argument('--output', default='libwebrtc.aar', |
| 50 help='Output file of the script.') | 52 help='Output file of the script.') |
| 51 parser.add_argument('--arch', default=DEFAULT_ARCHS, nargs='*', | 53 parser.add_argument('--arch', default=DEFAULT_ARCHS, nargs='*', |
| 52 help='Architectures to build. Defaults to %(default)s.') | 54 help='Architectures to build. Defaults to %(default)s.') |
| 53 parser.add_argument('--use-goma', action='store_true', default=False, | 55 parser.add_argument('--use-goma', action='store_true', default=False, |
| 54 help='Use goma.') | 56 help='Use goma.') |
| 55 parser.add_argument('--verbose', action='store_true', default=False, | 57 parser.add_argument('--verbose', action='store_true', default=False, |
| 56 help='Debug logging.') | 58 help='Debug logging.') |
| 57 parser.add_argument('--extra-gn-args', default=[], nargs='*', | 59 parser.add_argument('--extra-gn-args', default=[], nargs='*', |
| 58 help='Additional GN args to be used during Ninja generation.') | 60 help='Additional GN args to be used during Ninja generation.') |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 76 def _EncodeForGN(value): | 78 def _EncodeForGN(value): |
| 77 """Encodes value as a GN literal.""" | 79 """Encodes value as a GN literal.""" |
| 78 if type(value) is str: | 80 if type(value) is str: |
| 79 return '"' + value + '"' | 81 return '"' + value + '"' |
| 80 elif type(value) is bool: | 82 elif type(value) is bool: |
| 81 return repr(value).lower() | 83 return repr(value).lower() |
| 82 else: | 84 else: |
| 83 return repr(value) | 85 return repr(value) |
| 84 | 86 |
| 85 | 87 |
| 86 def _GetOutputDirectory(tmp_dir, arch): | 88 def _GetOutputDirectory(tmp_dir, arch): |
|
sakal
2017/08/31 10:29:42
nit: I think we should rename rest of the tmp_dir
| |
| 87 """Returns the GN output directory for the target architecture.""" | 89 """Returns the GN output directory for the target architecture.""" |
| 88 return os.path.join(tmp_dir, arch) | 90 return os.path.join(tmp_dir, arch) |
| 89 | 91 |
| 90 | 92 |
| 91 def _GetTargetCpu(arch): | 93 def _GetTargetCpu(arch): |
| 92 """Returns target_cpu for the GN build with the given architecture.""" | 94 """Returns target_cpu for the GN build with the given architecture.""" |
| 93 if arch in ['armeabi', 'armeabi-v7a']: | 95 if arch in ['armeabi', 'armeabi-v7a']: |
| 94 return 'arm' | 96 return 'arm' |
| 95 elif arch == 'arm64-v8a': | 97 elif arch == 'arm64-v8a': |
| 96 return 'arm64' | 98 return 'arm64' |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 abi_dir = os.path.join('jni', arch) | 157 abi_dir = os.path.join('jni', arch) |
| 156 for so_file in NEEDED_SO_FILES: | 158 for so_file in NEEDED_SO_FILES: |
| 157 aar_file.write(os.path.join(output_directory, so_file), | 159 aar_file.write(os.path.join(output_directory, so_file), |
| 158 os.path.join(abi_dir, so_file)) | 160 os.path.join(abi_dir, so_file)) |
| 159 | 161 |
| 160 | 162 |
| 161 def main(): | 163 def main(): |
| 162 args = _ParseArgs() | 164 args = _ParseArgs() |
| 163 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) | 165 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) |
| 164 | 166 |
| 165 tmp_dir = tempfile.mkdtemp() | 167 build_dir = args.build_dir if args.build_dir else tempfile.mkdtemp() |
| 166 | 168 |
| 167 for arch in args.arch: | 169 for arch in args.arch: |
| 168 Build(tmp_dir, arch, args.use_goma, args.extra_gn_args) | 170 Build(build_dir, arch, args.use_goma, args.extra_gn_args) |
| 169 | 171 |
| 170 with zipfile.ZipFile(args.output, 'w') as aar_file: | 172 with zipfile.ZipFile(args.output, 'w') as aar_file: |
| 171 # Architecture doesn't matter here, arbitrarily using the first one. | 173 # Architecture doesn't matter here, arbitrarily using the first one. |
| 172 CollectCommon(aar_file, tmp_dir, args.arch[0]) | 174 CollectCommon(aar_file, build_dir, args.arch[0]) |
| 173 for arch in args.arch: | 175 for arch in args.arch: |
| 174 Collect(aar_file, tmp_dir, arch) | 176 Collect(aar_file, build_dir, arch) |
| 175 | 177 |
| 176 shutil.rmtree(tmp_dir, True) | 178 if not args.build_dir: |
| 179 shutil.rmtree(build_dir, True) | |
| 177 | 180 |
| 178 | 181 |
| 179 if __name__ == '__main__': | 182 if __name__ == '__main__': |
| 180 sys.exit(main()) | 183 sys.exit(main()) |
| OLD | NEW |