Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: tools_webrtc/android/build_aar.py

Issue 3011613002: License generation script for build_aar.py. (Closed)
Patch Set: Specify GN working directory. Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools_webrtc/ios/build_ios_libs.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 16 matching lines...) Expand all
27 import argparse 27 import argparse
28 import logging 28 import logging
29 import os 29 import os
30 import shutil 30 import shutil
31 import subprocess 31 import subprocess
32 import sys 32 import sys
33 import tempfile 33 import tempfile
34 import zipfile 34 import zipfile
35 35
36 36
37 SCRIPT_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
37 DEFAULT_ARCHS = ['armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'] 38 DEFAULT_ARCHS = ['armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64']
38 NEEDED_SO_FILES = ['libjingle_peerconnection_so.so'] 39 NEEDED_SO_FILES = ['libjingle_peerconnection_so.so']
39 JAR_FILE = 'lib.java/webrtc/sdk/android/libwebrtc.jar' 40 JAR_FILE = 'lib.java/webrtc/sdk/android/libwebrtc.jar'
40 MANIFEST_FILE = 'webrtc/sdk/android/AndroidManifest.xml' 41 MANIFEST_FILE = 'webrtc/sdk/android/AndroidManifest.xml'
41 TARGETS = [ 42 TARGETS = [
42 'webrtc/sdk/android:libwebrtc', 43 'webrtc/sdk/android:libwebrtc',
43 'webrtc/sdk/android:libjingle_peerconnection_so', 44 'webrtc/sdk/android:libjingle_peerconnection_so',
44 ] 45 ]
45 46
47 sys.path.append(os.path.join(SCRIPT_DIR, '..', 'libs'))
48 from generate_licenses import LicenseBuilder
49
46 50
47 def _ParseArgs(): 51 def _ParseArgs():
48 parser = argparse.ArgumentParser(description='libwebrtc.aar generator.') 52 parser = argparse.ArgumentParser(description='libwebrtc.aar generator.')
49 parser.add_argument('--output', default='libwebrtc.aar', 53 parser.add_argument('--output', default='libwebrtc.aar',
50 help='Output file of the script.') 54 help='Output file of the script.')
51 parser.add_argument('--arch', default=DEFAULT_ARCHS, nargs='*', 55 parser.add_argument('--arch', default=DEFAULT_ARCHS, nargs='*',
52 help='Architectures to build. Defaults to %(default)s.') 56 help='Architectures to build. Defaults to %(default)s.')
53 parser.add_argument('--use-goma', action='store_true', default=False, 57 parser.add_argument('--use-goma', action='store_true', default=False,
54 help='Use goma.') 58 help='Use goma.')
55 parser.add_argument('--verbose', action='store_true', default=False, 59 parser.add_argument('--verbose', action='store_true', default=False,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 119
116 120
117 def Build(tmp_dir, arch, use_goma, extra_gn_args): 121 def Build(tmp_dir, arch, use_goma, extra_gn_args):
118 """Generates target architecture using GN and builds it using ninja.""" 122 """Generates target architecture using GN and builds it using ninja."""
119 logging.info('Building: %s', arch) 123 logging.info('Building: %s', arch)
120 output_directory = _GetOutputDirectory(tmp_dir, arch) 124 output_directory = _GetOutputDirectory(tmp_dir, arch)
121 gn_args = { 125 gn_args = {
122 'target_os': 'android', 126 'target_os': 'android',
123 'is_debug': False, 127 'is_debug': False,
124 'is_component_build': False, 128 'is_component_build': False,
129 'rtc_include_tests': False,
125 'target_cpu': _GetTargetCpu(arch), 130 'target_cpu': _GetTargetCpu(arch),
126 'use_goma': use_goma 131 'use_goma': use_goma
127 } 132 }
128 arm_version = _GetArmVersion(arch) 133 arm_version = _GetArmVersion(arch)
129 if arm_version: 134 if arm_version:
130 gn_args['arm_version'] = arm_version 135 gn_args['arm_version'] = arm_version
131 gn_args_str = '--args=' + ' '.join([ 136 gn_args_str = '--args=' + ' '.join([
132 k + '=' + _EncodeForGN(v) for k, v in gn_args.items()] + extra_gn_args) 137 k + '=' + _EncodeForGN(v) for k, v in gn_args.items()] + extra_gn_args)
133 138
134 _RunGN(['gen', output_directory, gn_args_str]) 139 _RunGN(['gen', output_directory, gn_args_str])
135 140
136 ninja_args = TARGETS 141 ninja_args = TARGETS[:]
137 if use_goma: 142 if use_goma:
138 ninja_args.extend(['-j', '200']) 143 ninja_args.extend(['-j', '200'])
139 _RunNinja(output_directory, ninja_args) 144 _RunNinja(output_directory, ninja_args)
140 145
141 146
142 def CollectCommon(aar_file, tmp_dir, arch): 147 def CollectCommon(aar_file, tmp_dir, arch):
143 """Collects architecture independent files into the .aar-archive.""" 148 """Collects architecture independent files into the .aar-archive."""
144 logging.info('Collecting common files.') 149 logging.info('Collecting common files.')
145 output_directory = _GetOutputDirectory(tmp_dir, arch) 150 output_directory = _GetOutputDirectory(tmp_dir, arch)
146 aar_file.write(MANIFEST_FILE, 'AndroidManifest.xml') 151 aar_file.write(MANIFEST_FILE, 'AndroidManifest.xml')
147 aar_file.write(os.path.join(output_directory, JAR_FILE), 'classes.jar') 152 aar_file.write(os.path.join(output_directory, JAR_FILE), 'classes.jar')
148 153
149 154
150 def Collect(aar_file, tmp_dir, arch): 155 def Collect(aar_file, tmp_dir, arch):
151 """Collects architecture specific files into the .aar-archive.""" 156 """Collects architecture specific files into the .aar-archive."""
152 logging.info('Collecting: %s', arch) 157 logging.info('Collecting: %s', arch)
153 output_directory = _GetOutputDirectory(tmp_dir, arch) 158 output_directory = _GetOutputDirectory(tmp_dir, arch)
154 159
155 abi_dir = os.path.join('jni', arch) 160 abi_dir = os.path.join('jni', arch)
156 for so_file in NEEDED_SO_FILES: 161 for so_file in NEEDED_SO_FILES:
157 aar_file.write(os.path.join(output_directory, so_file), 162 aar_file.write(os.path.join(output_directory, so_file),
158 os.path.join(abi_dir, so_file)) 163 os.path.join(abi_dir, so_file))
159 164
160 165
166 def GenerateLicenses(output_dir, tmp_dir, archs):
167 builder = LicenseBuilder(
168 [_GetOutputDirectory(tmp_dir, arch) for arch in archs], TARGETS)
169 builder.GenerateLicenseText(output_dir)
170
171
161 def main(): 172 def main():
162 args = _ParseArgs() 173 args = _ParseArgs()
163 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) 174 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
164 175
165 tmp_dir = tempfile.mkdtemp() 176 tmp_dir = tempfile.mkdtemp()
166 177
167 for arch in args.arch: 178 for arch in args.arch:
168 Build(tmp_dir, arch, args.use_goma, args.extra_gn_args) 179 Build(tmp_dir, arch, args.use_goma, args.extra_gn_args)
169 180
170 with zipfile.ZipFile(args.output, 'w') as aar_file: 181 with zipfile.ZipFile(args.output, 'w') as aar_file:
171 # Architecture doesn't matter here, arbitrarily using the first one. 182 # Architecture doesn't matter here, arbitrarily using the first one.
172 CollectCommon(aar_file, tmp_dir, args.arch[0]) 183 CollectCommon(aar_file, tmp_dir, args.arch[0])
173 for arch in args.arch: 184 for arch in args.arch:
174 Collect(aar_file, tmp_dir, arch) 185 Collect(aar_file, tmp_dir, arch)
175 186
187 license_dir = os.path.dirname(os.path.realpath(args.output))
188 GenerateLicenses(license_dir, tmp_dir, args.arch)
189
176 shutil.rmtree(tmp_dir, True) 190 shutil.rmtree(tmp_dir, True)
177 191
178 192
179 if __name__ == '__main__': 193 if __name__ == '__main__':
180 sys.exit(main()) 194 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | tools_webrtc/ios/build_ios_libs.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698