Commit 0e69c2d8 authored by cjhopman@chromium.org's avatar cjhopman@chromium.org

Make test apks only dex files not in tested apk

At runtime, the classloader will look for classes in both apk's dex
files. In the standard Android build system, an instrumentation test
apk's dex file does not include the classes included in the tested apk's
dex file.

To do this, when dexing, write a file listing the inputs to the dex
file. When dexing for an instrumentation apk, exclude those files listed
as inputs of the tested apk's dex file.

For proguarded apks, this exclusion will need to happen for proguard
inputs instead of dex inputs, so this change does not cover that case.

BUG=272790
NOTRY=true

Review URL: https://codereview.chromium.org/313273004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276788 0039d316-1c4b-4281-b951-d872f2087c98
parent 64bd0217
......@@ -32,6 +32,7 @@
'proguard_enabled%': 'false',
'proguard_enabled_input_path%': '',
'dex_no_locals%': 0,
'dex_additional_options': [],
},
'inputs': [
'<(DEPTH)/build/android/gyp/util/build_utils.py',
......@@ -41,6 +42,7 @@
],
'outputs': [
'<(output_path)',
'<(output_path).inputs',
],
'action': [
'python', '<(DEPTH)/build/android/gyp/dex.py',
......@@ -49,7 +51,8 @@
'--configuration-name=<(CONFIGURATION_NAME)',
'--proguard-enabled=<(proguard_enabled)',
'--proguard-enabled-input-path=<(proguard_enabled_input_path)',
'--no-locals=<(dex_no_locals)',
'--no-locals=>(dex_no_locals)',
'>@(dex_additional_options)',
'>@(dex_input_paths)',
'>@(dex_generated_input_dirs)',
]
......
......@@ -25,9 +25,9 @@ def DoDex(options, paths):
lambda: build_utils.CheckOutput(dex_cmd, print_stderr=False),
record_path=record_path,
input_paths=paths,
input_strings=dex_cmd)
build_utils.Touch(options.dex_path)
input_strings=dex_cmd,
force=not os.path.exists(options.dex_path))
build_utils.WriteJson(paths, options.dex_path + '.inputs')
def main():
......@@ -44,6 +44,9 @@ def main():
'is enabled.'))
parser.add_option('--no-locals',
help='Exclude locals list from the dex file.')
parser.add_option('--excluded-paths-file',
help='Path to a file containing a list of paths to exclude '
'from the dex file.')
options, paths = parser.parse_args()
......@@ -51,6 +54,10 @@ def main():
and options.configuration_name == 'Release'):
paths = [options.proguard_enabled_input_path]
if options.excluded_paths_file:
exclude_paths = build_utils.ReadJson(options.excluded_paths_file)
paths = [p for p in paths if not p in exclude_paths]
DoDex(options, paths)
......
......@@ -52,6 +52,7 @@
# never_lint - Set to 1 to not run lint on this target.
{
'variables': {
'tested_apk_dex_path%': '/',
'additional_input_paths': [],
'input_jars_paths': [],
'library_dexed_jars_paths': [],
......@@ -151,6 +152,7 @@
'apk_package_native_libs_dir': '<(apk_package_native_libs_dir)',
'unsigned_standalone_apk_path': '<(unsigned_standalone_apk_path)',
'extra_native_libs': [],
'apk_dex_input_paths': [ '>@(library_dexed_jars_paths)' ],
},
# Pass the jar path to the apk's "fake" jar target. This would be better as
# direct_dependent_settings, but a variable set by a direct_dependent_settings
......@@ -158,6 +160,7 @@
'all_dependent_settings': {
'variables': {
'apk_output_jar_path': '<(jar_path)',
'tested_apk_dex_path': '<(dex_path)',
},
},
'conditions': [
......@@ -668,20 +671,37 @@
{
'action_name': 'dex_<(_target_name)',
'variables': {
'conditions': [
['emma_instrument != 0', {
'dex_no_locals': 1,
'dex_input_paths': [ '<(emma_device_jar)' ],
}],
],
'dex_input_paths': [ '>@(library_dexed_jars_paths)' ],
'dex_generated_input_dirs': [ '<(classes_final_dir)' ],
'output_path': '<(dex_path)',
'dex_input_paths': [
'>@(apk_dex_input_paths)',
'<(jar_path)',
],
'proguard_enabled_input_path': '<(obfuscated_jar_path)',
},
'target_conditions': [
['emma_instrument != 0', {
'dex_no_locals': 1,
'dex_input_paths': [
'<(emma_device_jar)'
],
}],
['is_test_apk == 1 and tested_apk_dex_path != "/"', {
'variables': {
'dex_additional_options': [
'--excluded-paths-file', '>(tested_apk_dex_path).inputs'
],
},
'inputs': [
'>(tested_apk_dex_path).inputs',
],
}],
],
'conditions': [
['proguard_enabled == "true"', { 'inputs': [ '<(obfuscate_stamp)' ] },
{ 'inputs': [ '<(instr_stamp)' ] }],
['proguard_enabled == "true"', {
'inputs': [ '<(obfuscate_stamp)' ]
}, {
'inputs': [ '<(instr_stamp)' ]
}],
],
'includes': [ 'android/dex_action.gypi' ],
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment