Index: build/android/gyp/write_build_config.py |
diff --git a/build/android/gyp/write_build_config.py b/build/android/gyp/write_build_config.py |
index d8f2d741d15b47a066992b1f70f264538bfce34e..9a997599624aa536dac2a9b0a64e070384996767 100755 |
--- a/build/android/gyp/write_build_config.py |
+++ b/build/android/gyp/write_build_config.py |
@@ -29,11 +29,45 @@ Note: If paths to input files are passed in this way, it is important that: |
import optparse |
import os |
import sys |
+import xml.dom.minidom |
from util import build_utils |
import write_ordered_libraries |
+class AndroidManifest(object): |
+ def __init__(self, path): |
+ self.path = path |
+ dom = xml.dom.minidom.parse(path) |
+ manifests = dom.getElementsByTagName('manifest') |
+ assert len(manifests) == 1 |
+ self.manifest = manifests[0] |
+ |
+ def GetInstrumentation(self): |
+ instrumentation_els = self.manifest.getElementsByTagName('instrumentation') |
+ if len(instrumentation_els) == 0: |
+ return None |
+ if len(instrumentation_els) != 1: |
+ raise Exception( |
+ 'Unexpected number of instrumentation nodes in Android manifest (%s):' |
newt (away)
2015/04/23 03:19:18
I'd keep this simple:
"More than one <instrumen
cjhopman
2015/04/24 01:26:21
Done.
|
+ % self.path, *(map(lambda e: e.toprettyxml(), instrumentation_els))) |
+ return instrumentation_els[0] |
+ |
+ def CheckInstrumentation(self, expected_package): |
+ instr = self.GetInstrumentation() |
+ if not instr: |
+ raise Exception( |
+ 'No instrumentation nodes found in Android manifest (%s)' % self.path) |
newt (away)
2015/04/23 03:19:18
s/nodes/elements
node is the parent type of eleme
cjhopman
2015/04/24 01:26:21
Done.
|
+ instrumented_package = instr.getAttributeNS( |
+ 'http://schemas.android.com/apk/res/android', 'targetPackage') |
+ if instrumented_package != expected_package: |
+ raise Exception( |
+ 'Wrong instrumented package. Expected %s, got %s' |
+ % (expected_package, instrumented_package)) |
+ |
+ def GetPackageName(self): |
+ return self.manifest.getAttribute('package') |
+ |
dep_config_cache = {} |
def GetDepConfig(path): |
@@ -158,7 +192,6 @@ def main(argv): |
} |
deps_info = config['deps_info'] |
- |
if options.type == 'java_library' and not options.bypass_platform_checks: |
deps_info['requires_android'] = options.requires_android |
deps_info['supports_android'] = options.supports_android |
@@ -176,7 +209,6 @@ def main(argv): |
raise Exception('Not all deps support the Android platform: ' + |
str(deps_not_support_android)) |
- |
if options.type in ['java_library', 'android_apk']: |
javac_classpath = [c['jar_path'] for c in direct_library_deps] |
java_full_classpath = [c['jar_path'] for c in all_library_deps] |
@@ -220,8 +252,7 @@ def main(argv): |
config['resources']['extra_package_names'] = [ |
c['package_name'] for c in all_resources_deps if 'package_name' in c] |
- |
- deps_dex_files = [c['dex_path'] for c in all_library_deps] |
+ excluded_deps_dex_files = [] |
# An instrumentation test apk should exclude the dex files that are in the apk |
# under test. |
if options.type == 'android_apk' and options.tested_apk_config: |
@@ -229,25 +260,32 @@ def main(argv): |
[options.tested_apk_config]) |
tested_apk_configs = [GetDepConfig(p) for p in tested_apk_config_paths] |
tested_apk_library_deps = DepsOfType('java_library', tested_apk_configs) |
- tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] |
- deps_dex_files = [ |
- p for p in deps_dex_files if not p in tested_apk_deps_dex_files] |
- |
+ excluded_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] |
newt (away)
2015/04/23 03:19:18
Why not just modify deps_dex_files at this point?
cjhopman
2015/04/24 01:26:21
Done.
|
+ tested_apk_config = GetDepConfig(options.tested_apk_config) |
+ expected_tested_package = tested_apk_config['package_name'] |
+ AndroidManifest(options.android_manifest).CheckInstrumentation( |
+ expected_tested_package) |
# Dependencies for the final dex file of an apk or a 'deps_dex'. |
if options.type in ['android_apk', 'deps_dex']: |
config['final_dex'] = {} |
dex_config = config['final_dex'] |
# TODO(cjhopman): proguard version |
+ deps_dex_files = [c['dex_path'] for c in all_library_deps |
+ if not c in excluded_deps_dex_files] |
dex_config['dependency_dex_files'] = deps_dex_files |
- |
if options.type == 'android_apk': |
config['dist_jar'] = { |
'dependency_jars': [ |
c['jar_path'] for c in all_library_deps |
] |
} |
+ manifest = AndroidManifest(options.android_manifest) |
+ deps_info['package_name'] = manifest.GetPackageName() |
+ if not options.tested_apk_config and manifest.GetInstrumentation(): |
+ # This must then have instrumentation only for itself. |
+ manifest.CheckInstrumentation(manifest.GetPackageName()) |
library_paths = [] |
java_libraries_list = [] |