| 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 5fc8955b226801258a5e4f8ac64beb7f133bf66c..1b4379d3b97eb2e1e40780d41584f0953684f345 100755
 | 
| --- a/build/android/gyp/write_build_config.py
 | 
| +++ b/build/android/gyp/write_build_config.py
 | 
| @@ -29,11 +29,43 @@ 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(
 | 
| +          'More than one <instrumentation> element found in %s' % self.path)
 | 
| +    return instrumentation_els[0]
 | 
| +
 | 
| +  def CheckInstrumentation(self, expected_package):
 | 
| +    instr = self.GetInstrumentation()
 | 
| +    if not instr:
 | 
| +      raise Exception('No <instrumentation> elements found in %s' % self.path)
 | 
| +    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):
 | 
| @@ -88,6 +120,10 @@ def main(argv):
 | 
|    parser.add_option('--native-libs', help='List of top-level native libs.')
 | 
|    parser.add_option('--readelf-path', help='Path to toolchain\'s readelf.')
 | 
|  
 | 
| +  parser.add_option('--tested-apk-config',
 | 
| +      help='Path to the build config of the tested apk (for an instrumentation '
 | 
| +      'test apk).')
 | 
| +
 | 
|    options, args = parser.parse_args(argv)
 | 
|  
 | 
|    if args:
 | 
| @@ -154,7 +190,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
 | 
| @@ -172,7 +207,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]
 | 
| @@ -216,14 +250,31 @@ def main(argv):
 | 
|      config['resources']['extra_package_names'] = [
 | 
|          c['package_name'] for c in all_resources_deps if 'package_name' in c]
 | 
|  
 | 
| +  if options.type in ['android_apk', 'deps_dex']:
 | 
| +    deps_dex_files = [c['dex_path'] for c in all_library_deps]
 | 
| +
 | 
| +  # 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:
 | 
| +    tested_apk_config_paths = GetAllDepsConfigsInOrder(
 | 
| +        [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]
 | 
| +
 | 
| +    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
 | 
| -    dex_deps_files = [c['dex_path'] for c in all_library_deps]
 | 
| -    dex_config['dependency_dex_files'] = dex_deps_files
 | 
| +    dex_config['dependency_dex_files'] = deps_dex_files
 | 
|  
 | 
|    if options.type == 'android_apk':
 | 
|      config['dist_jar'] = {
 | 
| @@ -231,6 +282,11 @@ def main(argv):
 | 
|          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 = []
 | 
| 
 |