| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Writes a build_config file. | 7 """Writes a build_config file. |
| 8 | 8 |
| 9 The build_config file for a target is a json file containing information about | 9 The build_config file for a target is a json file containing information about |
| 10 how to build that target based on the target's dependencies. This includes | 10 how to build that target based on the target's dependencies. This includes |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 1. inputs/deps of the action ensure that the files are available the first | 22 1. inputs/deps of the action ensure that the files are available the first |
| 23 time the action runs. | 23 time the action runs. |
| 24 2. Either (a) or (b) | 24 2. Either (a) or (b) |
| 25 a. inputs/deps ensure that the action runs whenever one of the files changes | 25 a. inputs/deps ensure that the action runs whenever one of the files changes |
| 26 b. the files are added to the action's depfile | 26 b. the files are added to the action's depfile |
| 27 """ | 27 """ |
| 28 | 28 |
| 29 import optparse | 29 import optparse |
| 30 import os | 30 import os |
| 31 import sys | 31 import sys |
| 32 import xml.dom.minidom |
| 32 | 33 |
| 33 from util import build_utils | 34 from util import build_utils |
| 34 | 35 |
| 35 import write_ordered_libraries | 36 import write_ordered_libraries |
| 36 | 37 |
| 38 class AndroidManifest(object): |
| 39 def __init__(self, path): |
| 40 self.path = path |
| 41 dom = xml.dom.minidom.parse(path) |
| 42 manifests = dom.getElementsByTagName('manifest') |
| 43 assert len(manifests) == 1 |
| 44 self.manifest = manifests[0] |
| 45 |
| 46 def GetInstrumentation(self): |
| 47 instrumentation_els = self.manifest.getElementsByTagName('instrumentation') |
| 48 if len(instrumentation_els) == 0: |
| 49 return None |
| 50 if len(instrumentation_els) != 1: |
| 51 raise Exception( |
| 52 'More than one <instrumentation> element found in %s' % self.path) |
| 53 return instrumentation_els[0] |
| 54 |
| 55 def CheckInstrumentation(self, expected_package): |
| 56 instr = self.GetInstrumentation() |
| 57 if not instr: |
| 58 raise Exception('No <instrumentation> elements found in %s' % self.path) |
| 59 instrumented_package = instr.getAttributeNS( |
| 60 'http://schemas.android.com/apk/res/android', 'targetPackage') |
| 61 if instrumented_package != expected_package: |
| 62 raise Exception( |
| 63 'Wrong instrumented package. Expected %s, got %s' |
| 64 % (expected_package, instrumented_package)) |
| 65 |
| 66 def GetPackageName(self): |
| 67 return self.manifest.getAttribute('package') |
| 68 |
| 37 | 69 |
| 38 dep_config_cache = {} | 70 dep_config_cache = {} |
| 39 def GetDepConfig(path): | 71 def GetDepConfig(path): |
| 40 if not path in dep_config_cache: | 72 if not path in dep_config_cache: |
| 41 dep_config_cache[path] = build_utils.ReadJson(path)['deps_info'] | 73 dep_config_cache[path] = build_utils.ReadJson(path)['deps_info'] |
| 42 return dep_config_cache[path] | 74 return dep_config_cache[path] |
| 43 | 75 |
| 44 | 76 |
| 45 def DepsOfType(wanted_type, configs): | 77 def DepsOfType(wanted_type, configs): |
| 46 return [c for c in configs if c['type'] == wanted_type] | 78 return [c for c in configs if c['type'] == wanted_type] |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 config = { | 183 config = { |
| 152 'deps_info': { | 184 'deps_info': { |
| 153 'name': os.path.basename(options.build_config), | 185 'name': os.path.basename(options.build_config), |
| 154 'path': options.build_config, | 186 'path': options.build_config, |
| 155 'type': options.type, | 187 'type': options.type, |
| 156 'deps_configs': direct_deps_config_paths, | 188 'deps_configs': direct_deps_config_paths, |
| 157 } | 189 } |
| 158 } | 190 } |
| 159 deps_info = config['deps_info'] | 191 deps_info = config['deps_info'] |
| 160 | 192 |
| 161 | |
| 162 if options.type == 'java_library' and not options.bypass_platform_checks: | 193 if options.type == 'java_library' and not options.bypass_platform_checks: |
| 163 deps_info['requires_android'] = options.requires_android | 194 deps_info['requires_android'] = options.requires_android |
| 164 deps_info['supports_android'] = options.supports_android | 195 deps_info['supports_android'] = options.supports_android |
| 165 | 196 |
| 166 deps_require_android = (all_resources_deps + | 197 deps_require_android = (all_resources_deps + |
| 167 [d['name'] for d in all_library_deps if d['requires_android']]) | 198 [d['name'] for d in all_library_deps if d['requires_android']]) |
| 168 deps_not_support_android = ( | 199 deps_not_support_android = ( |
| 169 [d['name'] for d in all_library_deps if not d['supports_android']]) | 200 [d['name'] for d in all_library_deps if not d['supports_android']]) |
| 170 | 201 |
| 171 if deps_require_android and not options.requires_android: | 202 if deps_require_android and not options.requires_android: |
| 172 raise Exception('Some deps require building for the Android platform: ' + | 203 raise Exception('Some deps require building for the Android platform: ' + |
| 173 str(deps_require_android)) | 204 str(deps_require_android)) |
| 174 | 205 |
| 175 if deps_not_support_android and options.supports_android: | 206 if deps_not_support_android and options.supports_android: |
| 176 raise Exception('Not all deps support the Android platform: ' + | 207 raise Exception('Not all deps support the Android platform: ' + |
| 177 str(deps_not_support_android)) | 208 str(deps_not_support_android)) |
| 178 | 209 |
| 179 | |
| 180 if options.type in ['java_library', 'android_apk']: | 210 if options.type in ['java_library', 'android_apk']: |
| 181 javac_classpath = [c['jar_path'] for c in direct_library_deps] | 211 javac_classpath = [c['jar_path'] for c in direct_library_deps] |
| 182 java_full_classpath = [c['jar_path'] for c in all_library_deps] | 212 java_full_classpath = [c['jar_path'] for c in all_library_deps] |
| 183 deps_info['resources_deps'] = [c['path'] for c in all_resources_deps] | 213 deps_info['resources_deps'] = [c['path'] for c in all_resources_deps] |
| 184 deps_info['jar_path'] = options.jar_path | 214 deps_info['jar_path'] = options.jar_path |
| 185 if options.type == 'android_apk' or options.supports_android: | 215 if options.type == 'android_apk' or options.supports_android: |
| 186 deps_info['dex_path'] = options.dex_path | 216 deps_info['dex_path'] = options.dex_path |
| 187 config['javac'] = { | 217 config['javac'] = { |
| 188 'classpath': javac_classpath, | 218 'classpath': javac_classpath, |
| 189 } | 219 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 # under test. | 257 # under test. |
| 228 if options.type == 'android_apk' and options.tested_apk_config: | 258 if options.type == 'android_apk' and options.tested_apk_config: |
| 229 tested_apk_config_paths = GetAllDepsConfigsInOrder( | 259 tested_apk_config_paths = GetAllDepsConfigsInOrder( |
| 230 [options.tested_apk_config]) | 260 [options.tested_apk_config]) |
| 231 tested_apk_configs = [GetDepConfig(p) for p in tested_apk_config_paths] | 261 tested_apk_configs = [GetDepConfig(p) for p in tested_apk_config_paths] |
| 232 tested_apk_library_deps = DepsOfType('java_library', tested_apk_configs) | 262 tested_apk_library_deps = DepsOfType('java_library', tested_apk_configs) |
| 233 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] | 263 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] |
| 234 deps_dex_files = [ | 264 deps_dex_files = [ |
| 235 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] | 265 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] |
| 236 | 266 |
| 267 tested_apk_config = GetDepConfig(options.tested_apk_config) |
| 268 expected_tested_package = tested_apk_config['package_name'] |
| 269 AndroidManifest(options.android_manifest).CheckInstrumentation( |
| 270 expected_tested_package) |
| 237 | 271 |
| 238 # Dependencies for the final dex file of an apk or a 'deps_dex'. | 272 # Dependencies for the final dex file of an apk or a 'deps_dex'. |
| 239 if options.type in ['android_apk', 'deps_dex']: | 273 if options.type in ['android_apk', 'deps_dex']: |
| 240 config['final_dex'] = {} | 274 config['final_dex'] = {} |
| 241 dex_config = config['final_dex'] | 275 dex_config = config['final_dex'] |
| 242 # TODO(cjhopman): proguard version | 276 # TODO(cjhopman): proguard version |
| 243 dex_config['dependency_dex_files'] = deps_dex_files | 277 dex_config['dependency_dex_files'] = deps_dex_files |
| 244 | 278 |
| 245 | |
| 246 if options.type == 'android_apk': | 279 if options.type == 'android_apk': |
| 247 config['dist_jar'] = { | 280 config['dist_jar'] = { |
| 248 'dependency_jars': [ | 281 'dependency_jars': [ |
| 249 c['jar_path'] for c in all_library_deps | 282 c['jar_path'] for c in all_library_deps |
| 250 ] | 283 ] |
| 251 } | 284 } |
| 285 manifest = AndroidManifest(options.android_manifest) |
| 286 deps_info['package_name'] = manifest.GetPackageName() |
| 287 if not options.tested_apk_config and manifest.GetInstrumentation(): |
| 288 # This must then have instrumentation only for itself. |
| 289 manifest.CheckInstrumentation(manifest.GetPackageName()) |
| 252 | 290 |
| 253 library_paths = [] | 291 library_paths = [] |
| 254 java_libraries_list = [] | 292 java_libraries_list = [] |
| 255 if options.native_libs: | 293 if options.native_libs: |
| 256 libraries = build_utils.ParseGypList(options.native_libs) | 294 libraries = build_utils.ParseGypList(options.native_libs) |
| 257 if libraries: | 295 if libraries: |
| 258 libraries_dir = os.path.dirname(libraries[0]) | 296 libraries_dir = os.path.dirname(libraries[0]) |
| 259 write_ordered_libraries.SetReadelfPath(options.readelf_path) | 297 write_ordered_libraries.SetReadelfPath(options.readelf_path) |
| 260 write_ordered_libraries.SetLibraryDirs([libraries_dir]) | 298 write_ordered_libraries.SetLibraryDirs([libraries_dir]) |
| 261 all_native_library_deps = ( | 299 all_native_library_deps = ( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 276 build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 314 build_utils.WriteJson(config, options.build_config, only_if_changed=True) |
| 277 | 315 |
| 278 if options.depfile: | 316 if options.depfile: |
| 279 build_utils.WriteDepfile( | 317 build_utils.WriteDepfile( |
| 280 options.depfile, | 318 options.depfile, |
| 281 all_deps_config_paths + build_utils.GetPythonDependencies()) | 319 all_deps_config_paths + build_utils.GetPythonDependencies()) |
| 282 | 320 |
| 283 | 321 |
| 284 if __name__ == '__main__': | 322 if __name__ == '__main__': |
| 285 sys.exit(main(sys.argv[1:])) | 323 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |