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

Side by Side Diff: build/android/gyp/write_build_config.py

Issue 2668203005: Reland allow JUnit3/4 tests within the same apk to be run by test_runner (Closed)
Patch Set: Change pickle version Created 3 years, 10 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 | build/android/lint/suppressions.xml » ('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 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 44
45 class AndroidManifest(object): 45 class AndroidManifest(object):
46 def __init__(self, path): 46 def __init__(self, path):
47 self.path = path 47 self.path = path
48 dom = xml.dom.minidom.parse(path) 48 dom = xml.dom.minidom.parse(path)
49 manifests = dom.getElementsByTagName('manifest') 49 manifests = dom.getElementsByTagName('manifest')
50 assert len(manifests) == 1 50 assert len(manifests) == 1
51 self.manifest = manifests[0] 51 self.manifest = manifests[0]
52 52
53 def GetInstrumentation(self): 53 def GetInstrumentationElements(self):
54 instrumentation_els = self.manifest.getElementsByTagName('instrumentation') 54 instrumentation_els = self.manifest.getElementsByTagName('instrumentation')
55 if len(instrumentation_els) == 0: 55 if len(instrumentation_els) == 0:
56 return None 56 return None
57 if len(instrumentation_els) != 1: 57 return instrumentation_els
58 raise Exception(
59 'More than one <instrumentation> element found in %s' % self.path)
60 return instrumentation_els[0]
61 58
62 def CheckInstrumentation(self, expected_package): 59 def CheckInstrumentationElements(self, expected_package):
63 instr = self.GetInstrumentation() 60 instrs = self.GetInstrumentationElements()
64 if not instr: 61 if not instrs:
65 raise Exception('No <instrumentation> elements found in %s' % self.path) 62 raise Exception('No <instrumentation> elements found in %s' % self.path)
66 instrumented_package = instr.getAttributeNS( 63 for instr in instrs:
67 'http://schemas.android.com/apk/res/android', 'targetPackage') 64 instrumented_package = instr.getAttributeNS(
68 if instrumented_package != expected_package: 65 'http://schemas.android.com/apk/res/android', 'targetPackage')
69 raise Exception( 66 if instrumented_package != expected_package:
70 'Wrong instrumented package. Expected %s, got %s' 67 raise Exception(
71 % (expected_package, instrumented_package)) 68 'Wrong instrumented package. Expected %s, got %s'
69 % (expected_package, instrumented_package))
72 70
73 def GetPackageName(self): 71 def GetPackageName(self):
74 return self.manifest.getAttribute('package') 72 return self.manifest.getAttribute('package')
75 73
76 74
77 dep_config_cache = {} 75 dep_config_cache = {}
78 def GetDepConfig(path): 76 def GetDepConfig(path):
79 if not path in dep_config_cache: 77 if not path in dep_config_cache:
80 dep_config_cache[path] = build_utils.ReadJson(path)['deps_info'] 78 dep_config_cache[path] = build_utils.ReadJson(path)['deps_info']
81 return dep_config_cache[path] 79 return dep_config_cache[path]
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 # With ProGuard: Each library's .jar file is fed into ProGuard, which outputs 569 # With ProGuard: Each library's .jar file is fed into ProGuard, which outputs
572 # a single .jar, which is then dexed into a classes.dex. A test apk includes 570 # a single .jar, which is then dexed into a classes.dex. A test apk includes
573 # all jar files from the program and the tests because having them separate 571 # all jar files from the program and the tests because having them separate
574 # doesn't work with ProGuard's whole-program optimizations. Although the 572 # doesn't work with ProGuard's whole-program optimizations. Although the
575 # apk-under-test still has all of its code in its classes.dex, none of it is 573 # apk-under-test still has all of its code in its classes.dex, none of it is
576 # used at runtime because the copy of it within the test apk takes precidence. 574 # used at runtime because the copy of it within the test apk takes precidence.
577 if options.type == 'android_apk' and options.tested_apk_config: 575 if options.type == 'android_apk' and options.tested_apk_config:
578 tested_apk_config = GetDepConfig(options.tested_apk_config) 576 tested_apk_config = GetDepConfig(options.tested_apk_config)
579 577
580 expected_tested_package = tested_apk_config['package_name'] 578 expected_tested_package = tested_apk_config['package_name']
581 AndroidManifest(options.android_manifest).CheckInstrumentation( 579 AndroidManifest(options.android_manifest).CheckInstrumentationElements(
582 expected_tested_package) 580 expected_tested_package)
583 if options.proguard_enabled: 581 if options.proguard_enabled:
584 # Add all tested classes to the test's classpath to ensure that the test's 582 # Add all tested classes to the test's classpath to ensure that the test's
585 # java code is a superset of the tested apk's java code 583 # java code is a superset of the tested apk's java code
586 java_full_classpath += [ 584 java_full_classpath += [
587 jar for jar in tested_apk_config['java']['full_classpath'] 585 jar for jar in tested_apk_config['java']['full_classpath']
588 if jar not in java_full_classpath] 586 if jar not in java_full_classpath]
589 587
590 if tested_apk_config['proguard_enabled']: 588 if tested_apk_config['proguard_enabled']:
591 assert options.proguard_enabled, ('proguard must be enabled for ' 589 assert options.proguard_enabled, ('proguard must be enabled for '
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 644
647 config['dist_jar'] = { 645 config['dist_jar'] = {
648 'dependency_jars': dependency_jars, 646 'dependency_jars': dependency_jars,
649 'all_interface_jars': all_interface_jars, 647 'all_interface_jars': all_interface_jars,
650 } 648 }
651 649
652 if options.type == 'android_apk': 650 if options.type == 'android_apk':
653 dependency_jars = [c['jar_path'] for c in all_library_deps] 651 dependency_jars = [c['jar_path'] for c in all_library_deps]
654 manifest = AndroidManifest(options.android_manifest) 652 manifest = AndroidManifest(options.android_manifest)
655 deps_info['package_name'] = manifest.GetPackageName() 653 deps_info['package_name'] = manifest.GetPackageName()
656 if not options.tested_apk_config and manifest.GetInstrumentation(): 654 if not options.tested_apk_config and manifest.GetInstrumentationElements():
657 # This must then have instrumentation only for itself. 655 # This must then have instrumentation only for itself.
658 manifest.CheckInstrumentation(manifest.GetPackageName()) 656 manifest.CheckInstrumentationElements(manifest.GetPackageName())
659 657
660 library_paths = [] 658 library_paths = []
661 java_libraries_list = None 659 java_libraries_list = None
662 runtime_deps_files = build_utils.ParseGnList( 660 runtime_deps_files = build_utils.ParseGnList(
663 options.shared_libraries_runtime_deps or '[]') 661 options.shared_libraries_runtime_deps or '[]')
664 if runtime_deps_files: 662 if runtime_deps_files:
665 library_paths = _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files) 663 library_paths = _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files)
666 java_libraries_list = _CreateJavaLibrariesList(library_paths) 664 java_libraries_list = _CreateJavaLibrariesList(library_paths)
667 665
668 secondary_abi_library_paths = [] 666 secondary_abi_library_paths = []
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 deps_info['java_resources_jar'] = options.java_resources_jar_path 702 deps_info['java_resources_jar'] = options.java_resources_jar_path
705 703
706 build_utils.WriteJson(config, options.build_config, only_if_changed=True) 704 build_utils.WriteJson(config, options.build_config, only_if_changed=True)
707 705
708 if options.depfile: 706 if options.depfile:
709 build_utils.WriteDepfile(options.depfile, options.build_config, all_inputs) 707 build_utils.WriteDepfile(options.depfile, options.build_config, all_inputs)
710 708
711 709
712 if __name__ == '__main__': 710 if __name__ == '__main__':
713 sys.exit(main(sys.argv[1:])) 711 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | build/android/lint/suppressions.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698