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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 'webrtc/sdk/android:libwebrtc', | 43 'webrtc/sdk/android:libwebrtc', |
44 'webrtc/sdk/android:libjingle_peerconnection_so', | 44 'webrtc/sdk/android:libjingle_peerconnection_so', |
45 ] | 45 ] |
46 | 46 |
47 sys.path.append(os.path.join(SCRIPT_DIR, '..', 'libs')) | 47 sys.path.append(os.path.join(SCRIPT_DIR, '..', 'libs')) |
48 from generate_licenses import LicenseBuilder | 48 from generate_licenses import LicenseBuilder |
49 | 49 |
50 | 50 |
51 def _ParseArgs(): | 51 def _ParseArgs(): |
52 parser = argparse.ArgumentParser(description='libwebrtc.aar generator.') | 52 parser = argparse.ArgumentParser(description='libwebrtc.aar generator.') |
| 53 parser.add_argument('--build-dir', |
| 54 help='Build dir. By default will create and use temporary dir.') |
53 parser.add_argument('--output', default='libwebrtc.aar', | 55 parser.add_argument('--output', default='libwebrtc.aar', |
54 help='Output file of the script.') | 56 help='Output file of the script.') |
55 parser.add_argument('--arch', default=DEFAULT_ARCHS, nargs='*', | 57 parser.add_argument('--arch', default=DEFAULT_ARCHS, nargs='*', |
56 help='Architectures to build. Defaults to %(default)s.') | 58 help='Architectures to build. Defaults to %(default)s.') |
57 parser.add_argument('--use-goma', action='store_true', default=False, | 59 parser.add_argument('--use-goma', action='store_true', default=False, |
58 help='Use goma.') | 60 help='Use goma.') |
59 parser.add_argument('--verbose', action='store_true', default=False, | 61 parser.add_argument('--verbose', action='store_true', default=False, |
60 help='Debug logging.') | 62 help='Debug logging.') |
61 parser.add_argument('--extra-gn-args', default=[], nargs='*', | 63 parser.add_argument('--extra-gn-args', default=[], nargs='*', |
62 help='Additional GN args to be used during Ninja generation.') | 64 help='Additional GN args to be used during Ninja generation.') |
(...skipping 17 matching lines...) Expand all Loading... |
80 def _EncodeForGN(value): | 82 def _EncodeForGN(value): |
81 """Encodes value as a GN literal.""" | 83 """Encodes value as a GN literal.""" |
82 if type(value) is str: | 84 if type(value) is str: |
83 return '"' + value + '"' | 85 return '"' + value + '"' |
84 elif type(value) is bool: | 86 elif type(value) is bool: |
85 return repr(value).lower() | 87 return repr(value).lower() |
86 else: | 88 else: |
87 return repr(value) | 89 return repr(value) |
88 | 90 |
89 | 91 |
90 def _GetOutputDirectory(tmp_dir, arch): | 92 def _GetOutputDirectory(build_dir, arch): |
91 """Returns the GN output directory for the target architecture.""" | 93 """Returns the GN output directory for the target architecture.""" |
92 return os.path.join(tmp_dir, arch) | 94 return os.path.join(build_dir, arch) |
93 | 95 |
94 | 96 |
95 def _GetTargetCpu(arch): | 97 def _GetTargetCpu(arch): |
96 """Returns target_cpu for the GN build with the given architecture.""" | 98 """Returns target_cpu for the GN build with the given architecture.""" |
97 if arch in ['armeabi', 'armeabi-v7a']: | 99 if arch in ['armeabi', 'armeabi-v7a']: |
98 return 'arm' | 100 return 'arm' |
99 elif arch == 'arm64-v8a': | 101 elif arch == 'arm64-v8a': |
100 return 'arm64' | 102 return 'arm64' |
101 elif arch == 'x86': | 103 elif arch == 'x86': |
102 return 'x86' | 104 return 'x86' |
103 elif arch == 'x86_64': | 105 elif arch == 'x86_64': |
104 return 'x64' | 106 return 'x64' |
105 else: | 107 else: |
106 raise Exception('Unknown arch: ' + arch) | 108 raise Exception('Unknown arch: ' + arch) |
107 | 109 |
108 | 110 |
109 def _GetArmVersion(arch): | 111 def _GetArmVersion(arch): |
110 """Returns arm_version for the GN build with the given architecture.""" | 112 """Returns arm_version for the GN build with the given architecture.""" |
111 if arch == 'armeabi': | 113 if arch == 'armeabi': |
112 return 6 | 114 return 6 |
113 elif arch == 'armeabi-v7a': | 115 elif arch == 'armeabi-v7a': |
114 return 7 | 116 return 7 |
115 elif arch in ['arm64-v8a', 'x86', 'x86_64']: | 117 elif arch in ['arm64-v8a', 'x86', 'x86_64']: |
116 return None | 118 return None |
117 else: | 119 else: |
118 raise Exception('Unknown arch: ' + arch) | 120 raise Exception('Unknown arch: ' + arch) |
119 | 121 |
120 | 122 |
121 def Build(tmp_dir, arch, use_goma, extra_gn_args): | 123 def Build(build_dir, arch, use_goma, extra_gn_args): |
122 """Generates target architecture using GN and builds it using ninja.""" | 124 """Generates target architecture using GN and builds it using ninja.""" |
123 logging.info('Building: %s', arch) | 125 logging.info('Building: %s', arch) |
124 output_directory = _GetOutputDirectory(tmp_dir, arch) | 126 output_directory = _GetOutputDirectory(build_dir, arch) |
125 gn_args = { | 127 gn_args = { |
126 'target_os': 'android', | 128 'target_os': 'android', |
127 'is_debug': False, | 129 'is_debug': False, |
128 'is_component_build': False, | 130 'is_component_build': False, |
129 'rtc_include_tests': False, | 131 'rtc_include_tests': False, |
130 'target_cpu': _GetTargetCpu(arch), | 132 'target_cpu': _GetTargetCpu(arch), |
131 'use_goma': use_goma | 133 'use_goma': use_goma |
132 } | 134 } |
133 arm_version = _GetArmVersion(arch) | 135 arm_version = _GetArmVersion(arch) |
134 if arm_version: | 136 if arm_version: |
135 gn_args['arm_version'] = arm_version | 137 gn_args['arm_version'] = arm_version |
136 gn_args_str = '--args=' + ' '.join([ | 138 gn_args_str = '--args=' + ' '.join([ |
137 k + '=' + _EncodeForGN(v) for k, v in gn_args.items()] + extra_gn_args) | 139 k + '=' + _EncodeForGN(v) for k, v in gn_args.items()] + extra_gn_args) |
138 | 140 |
139 _RunGN(['gen', output_directory, gn_args_str]) | 141 _RunGN(['gen', output_directory, gn_args_str]) |
140 | 142 |
141 ninja_args = TARGETS[:] | 143 ninja_args = TARGETS[:] |
142 if use_goma: | 144 if use_goma: |
143 ninja_args.extend(['-j', '200']) | 145 ninja_args.extend(['-j', '200']) |
144 _RunNinja(output_directory, ninja_args) | 146 _RunNinja(output_directory, ninja_args) |
145 | 147 |
146 | 148 |
147 def CollectCommon(aar_file, tmp_dir, arch): | 149 def CollectCommon(aar_file, build_dir, arch): |
148 """Collects architecture independent files into the .aar-archive.""" | 150 """Collects architecture independent files into the .aar-archive.""" |
149 logging.info('Collecting common files.') | 151 logging.info('Collecting common files.') |
150 output_directory = _GetOutputDirectory(tmp_dir, arch) | 152 output_directory = _GetOutputDirectory(build_dir, arch) |
151 aar_file.write(MANIFEST_FILE, 'AndroidManifest.xml') | 153 aar_file.write(MANIFEST_FILE, 'AndroidManifest.xml') |
152 aar_file.write(os.path.join(output_directory, JAR_FILE), 'classes.jar') | 154 aar_file.write(os.path.join(output_directory, JAR_FILE), 'classes.jar') |
153 | 155 |
154 | 156 |
155 def Collect(aar_file, tmp_dir, arch): | 157 def Collect(aar_file, build_dir, arch): |
156 """Collects architecture specific files into the .aar-archive.""" | 158 """Collects architecture specific files into the .aar-archive.""" |
157 logging.info('Collecting: %s', arch) | 159 logging.info('Collecting: %s', arch) |
158 output_directory = _GetOutputDirectory(tmp_dir, arch) | 160 output_directory = _GetOutputDirectory(build_dir, arch) |
159 | 161 |
160 abi_dir = os.path.join('jni', arch) | 162 abi_dir = os.path.join('jni', arch) |
161 for so_file in NEEDED_SO_FILES: | 163 for so_file in NEEDED_SO_FILES: |
162 aar_file.write(os.path.join(output_directory, so_file), | 164 aar_file.write(os.path.join(output_directory, so_file), |
163 os.path.join(abi_dir, so_file)) | 165 os.path.join(abi_dir, so_file)) |
164 | 166 |
165 | 167 |
166 def GenerateLicenses(output_dir, tmp_dir, archs): | 168 def GenerateLicenses(output_dir, build_dir, archs): |
167 builder = LicenseBuilder( | 169 builder = LicenseBuilder( |
168 [_GetOutputDirectory(tmp_dir, arch) for arch in archs], TARGETS) | 170 [_GetOutputDirectory(build_dir, arch) for arch in archs], TARGETS) |
169 builder.GenerateLicenseText(output_dir) | 171 builder.GenerateLicenseText(output_dir) |
170 | 172 |
171 | 173 |
172 def main(): | 174 def main(): |
173 args = _ParseArgs() | 175 args = _ParseArgs() |
174 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) | 176 logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) |
175 | 177 |
176 tmp_dir = tempfile.mkdtemp() | 178 build_dir = args.build_dir if args.build_dir else tempfile.mkdtemp() |
177 | 179 |
178 for arch in args.arch: | 180 for arch in args.arch: |
179 Build(tmp_dir, arch, args.use_goma, args.extra_gn_args) | 181 Build(build_dir, arch, args.use_goma, args.extra_gn_args) |
180 | 182 |
181 with zipfile.ZipFile(args.output, 'w') as aar_file: | 183 with zipfile.ZipFile(args.output, 'w') as aar_file: |
182 # Architecture doesn't matter here, arbitrarily using the first one. | 184 # Architecture doesn't matter here, arbitrarily using the first one. |
183 CollectCommon(aar_file, tmp_dir, args.arch[0]) | 185 CollectCommon(aar_file, build_dir, args.arch[0]) |
184 for arch in args.arch: | 186 for arch in args.arch: |
185 Collect(aar_file, tmp_dir, arch) | 187 Collect(aar_file, build_dir, arch) |
186 | 188 |
187 license_dir = os.path.dirname(os.path.realpath(args.output)) | 189 license_dir = os.path.dirname(os.path.realpath(args.output)) |
188 GenerateLicenses(license_dir, tmp_dir, args.arch) | 190 GenerateLicenses(license_dir, build_dir, args.arch) |
189 | 191 |
190 shutil.rmtree(tmp_dir, True) | 192 if not args.build_dir: |
| 193 shutil.rmtree(build_dir, True) |
191 | 194 |
192 | 195 |
193 if __name__ == '__main__': | 196 if __name__ == '__main__': |
194 sys.exit(main()) | 197 sys.exit(main()) |
OLD | NEW |