Index: build/android/gyp/main_dex_list.py |
diff --git a/build/android/gyp/main_dex_list.py b/build/android/gyp/main_dex_list.py |
index 7f29bfb50d4e235e7c9d3c7bd6ba58548f31a7d8..7388f4abdb53e7dab4aa367603f67935596b7e6c 100755 |
--- a/build/android/gyp/main_dex_list.py |
+++ b/build/android/gyp/main_dex_list.py |
@@ -17,8 +17,9 @@ sys.path.append(os.path.abspath(os.path.join( |
from pylib import constants |
-def main(): |
+def main(args): |
parser = argparse.ArgumentParser() |
+ build_utils.AddDepfileOption(parser) |
parser.add_argument('--android-sdk-tools', required=True, |
help='Android sdk build tools directory.') |
parser.add_argument('--main-dex-rules-path', action='append', default=[], |
@@ -36,11 +37,14 @@ def main(): |
parser.add_argument('--multidex-configuration-path', |
help='A JSON file containing multidex build ' |
'configuration.') |
- parser.add_argument('paths', nargs='+', |
+ parser.add_argument('--inputs', |
+ help='JARs for which a main dex list should be ' |
+ 'generated.') |
+ parser.add_argument('paths', nargs='*', default=[], |
help='JARs for which a main dex list should be ' |
'generated.') |
- args = parser.parse_args() |
+ args = parser.parse_args(build_utils.ExpandFileArgs(args)) |
if args.multidex_configuration_path: |
with open(args.multidex_configuration_path) as multidex_config_file: |
@@ -49,52 +53,86 @@ def main(): |
if not multidex_config.get('enabled', False): |
return 0 |
- with open(args.main_dex_list_path, 'w') as main_dex_list_file: |
+ if args.inputs: |
+ args.paths.extend(build_utils.ParseGypList(args.inputs)) |
+ |
+ shrinked_android_jar = os.path.abspath( |
+ os.path.join(args.android_sdk_tools, 'lib', 'shrinkedAndroid.jar')) |
+ dx_jar = os.path.abspath( |
+ os.path.join(args.android_sdk_tools, 'lib', 'dx.jar')) |
+ rules_file = os.path.abspath( |
+ os.path.join(args.android_sdk_tools, 'mainDexClasses.rules')) |
+ |
+ proguard_cmd = [ |
+ constants.PROGUARD_SCRIPT_PATH, |
+ '-forceprocessing', |
+ '-dontwarn', '-dontoptimize', '-dontobfuscate', '-dontpreverify', |
+ '-libraryjars', shrinked_android_jar, |
+ '-include', rules_file, |
+ ] |
+ for m in args.main_dex_rules_paths: |
+ proguard_cmd.extend(['-include', m]) |
+ |
+ main_dex_list_cmd = [ |
+ 'java', '-cp', dx_jar, |
+ 'com.android.multidex.MainDexListBuilder', |
+ ] |
+ |
+ input_paths = list(args.paths) |
+ input_paths += [ |
+ shrinked_android_jar, |
+ dx_jar, |
+ rules_file, |
+ ] |
+ input_paths += args.main_dex_rules_paths |
+ |
+ input_strings = [ |
+ proguard_cmd, |
+ main_dex_list_cmd, |
+ ] |
+ |
+ output_paths = [ |
+ args.main_dex_list_path, |
+ ] |
+ |
+ build_utils.CallAndWriteDepfileIfStale( |
+ lambda: _OnStaleMd5(proguard_cmd, main_dex_list_cmd, args.paths, |
+ args.main_dex_list_path), |
+ args, |
+ input_paths=input_paths, |
+ input_strings=input_strings, |
+ output_paths=output_paths) |
+ |
+ return 0 |
- shrinked_android_jar = os.path.abspath( |
- os.path.join(args.android_sdk_tools, 'lib', 'shrinkedAndroid.jar')) |
- dx_jar = os.path.abspath( |
- os.path.join(args.android_sdk_tools, 'lib', 'dx.jar')) |
- paths_arg = ':'.join(args.paths) |
- rules_file = os.path.abspath( |
- os.path.join(args.android_sdk_tools, 'mainDexClasses.rules')) |
+def _OnStaleMd5(proguard_cmd, main_dex_list_cmd, paths, main_dex_list_path): |
+ paths_arg = ':'.join(paths) |
+ main_dex_list = '' |
+ try: |
with tempfile.NamedTemporaryFile(suffix='.jar') as temp_jar: |
- proguard_cmd = [ |
- constants.PROGUARD_SCRIPT_PATH, |
- '-forceprocessing', |
- '-dontwarn', '-dontoptimize', '-dontobfuscate', '-dontpreverify', |
+ proguard_cmd += [ |
'-injars', paths_arg, |
- '-outjars', temp_jar.name, |
- '-libraryjars', shrinked_android_jar, |
- '-include', rules_file, |
+ '-outjars', temp_jar.name |
] |
- for m in args.main_dex_rules_paths: |
- proguard_cmd.extend(['-include', m]) |
- |
- main_dex_list = '' |
- try: |
- build_utils.CheckOutput(proguard_cmd, print_stderr=False) |
- |
- java_cmd = [ |
- 'java', '-cp', dx_jar, |
- 'com.android.multidex.MainDexListBuilder', |
- temp_jar.name, paths_arg |
- ] |
- main_dex_list = build_utils.CheckOutput(java_cmd) |
- except build_utils.CalledProcessError as e: |
- if 'output jar is empty' in e.output: |
- pass |
- elif "input doesn't contain any classes" in e.output: |
- pass |
- else: |
- raise |
- |
- main_dex_list_file.write(main_dex_list) |
+ build_utils.CheckOutput(proguard_cmd, print_stderr=False) |
- return 0 |
+ main_dex_list_cmd += [ |
+ temp_jar.name, paths_arg |
+ ] |
+ main_dex_list = build_utils.CheckOutput(main_dex_list_cmd) |
+ except build_utils.CalledProcessError as e: |
+ if 'output jar is empty' in e.output: |
+ pass |
+ elif "input doesn't contain any classes" in e.output: |
+ pass |
+ else: |
+ raise |
+ |
+ with open(main_dex_list_path, 'w') as main_dex_list_file: |
+ main_dex_list_file.write(main_dex_list) |
if __name__ == '__main__': |
- sys.exit(main()) |
+ sys.exit(main(sys.argv[1:])) |