diff options
author | cjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-12 20:28:16 +0000 |
---|---|---|
committer | cjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-12 20:28:16 +0000 |
commit | 0e69c2d813691dfe5d2df3b14e84a198377d2c73 (patch) | |
tree | aae3baa52f55bcb7a33191fc798e63d0dbc1ab8f /build | |
parent | 64bd0217b9360b1981491eeeeb3ebab288a69ee2 (diff) | |
download | chromium_src-0e69c2d813691dfe5d2df3b14e84a198377d2c73.zip chromium_src-0e69c2d813691dfe5d2df3b14e84a198377d2c73.tar.gz chromium_src-0e69c2d813691dfe5d2df3b14e84a198377d2c73.tar.bz2 |
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
Diffstat (limited to 'build')
-rw-r--r-- | build/android/dex_action.gypi | 5 | ||||
-rwxr-xr-x | build/android/gyp/dex.py | 13 | ||||
-rw-r--r-- | build/java_apk.gypi | 40 |
3 files changed, 44 insertions, 14 deletions
diff --git a/build/android/dex_action.gypi b/build/android/dex_action.gypi index 7e24d1e..0575e52 100644 --- a/build/android/dex_action.gypi +++ b/build/android/dex_action.gypi @@ -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)', ] diff --git a/build/android/gyp/dex.py b/build/android/gyp/dex.py index b42ab0b..dedbcec 100755 --- a/build/android/gyp/dex.py +++ b/build/android/gyp/dex.py @@ -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) diff --git a/build/java_apk.gypi b/build/java_apk.gypi index 9e2b937..348ce81 100644 --- a/build/java_apk.gypi +++ b/build/java_apk.gypi @@ -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' ], }, |