Chromium Code Reviews| Index: build/android/gyp/dex.py |
| diff --git a/build/android/gyp/dex.py b/build/android/gyp/dex.py |
| index c26d23a61166627dba6c0acddd189301dd35c18a..c25d1883351b63c6117903cc51802c1687b292d8 100755 |
| --- a/build/android/gyp/dex.py |
| +++ b/build/android/gyp/dex.py |
| @@ -4,21 +4,70 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| +import logging |
| import optparse |
| import os |
| import sys |
| +import tempfile |
| +import zipfile |
| from util import build_utils |
| from util import md5_check |
| def DoDex(options, paths): |
| + if options.multi_dex and options.main_dex_list_paths: |
|
Yaron
2015/08/13 20:12:10
Nit: I think it's cleaner to move this all to the
jbudorick
2015/08/14 21:01:21
done
|
| + DoMultiDex(options, paths) |
| + else: |
| + if options.multi_dex: |
| + logging.warning('--multi-dex is unused without --main-dex-list-paths') |
| + elif options.main_dex_list_paths: |
| + logging.warning('--main-dex-list-paths is unused without --multi-dex') |
| + _DoDexImpl([], options, paths) |
| + |
| + |
| +def DoMultiDex(options, paths): |
| + main_dex_list = [] |
| + main_dex_list_files = build_utils.ParseGypList(options.main_dex_list_paths) |
| + for m in main_dex_list_files: |
| + with open(m) as main_dex_list_file: |
| + for l in main_dex_list_file: |
|
Yaron
2015/08/13 20:12:10
use a list comprehension?
jbudorick
2015/08/14 21:01:21
derp. done.
|
| + if l: |
| + main_dex_list.append(l) |
| + |
| + with tempfile.NamedTemporaryFile(suffix='.txt') as combined_main_dex_list: |
| + combined_main_dex_list.write('\n'.join(main_dex_list)) |
| + combined_main_dex_list.flush() |
| + |
| + dex_args = [ |
| + '--multi-dex', |
| + '--minimal-main-dex', |
| + '--main-dex-list=%s' % combined_main_dex_list.name |
| + ] |
| + |
| + _DoDexImpl(dex_args, options, paths) |
| + |
| + if options.dex_path.endswith('.zip'): |
| + iz = zipfile.ZipFile(options.dex_path, 'r') |
| + tmp_dex_path = '%s.tmp.zip' % options.dex_path |
| + oz = zipfile.ZipFile(tmp_dex_path, 'w', zipfile.ZIP_DEFLATED) |
| + for i in iz.namelist(): |
| + if i.endswith('.dex'): |
| + oz.writestr(i, iz.read(i)) |
| + os.remove(options.dex_path) |
| + os.rename(tmp_dex_path, options.dex_path) |
| + |
| + |
| +def _DoDexImpl(dex_args, options, paths): |
| dx_binary = os.path.join(options.android_sdk_tools, 'dx') |
| # See http://crbug.com/272064 for context on --force-jumbo. |
| dex_cmd = [dx_binary, '--dex', '--force-jumbo', '--output', options.dex_path] |
| if options.no_locals != '0': |
| dex_cmd.append('--no-locals') |
| + if dex_args: |
| + dex_cmd += dex_args |
| + |
| dex_cmd += paths |
| record_path = '%s.md5.stamp' % options.dex_path |
| @@ -54,9 +103,14 @@ def main(): |
| 'is enabled.')) |
| parser.add_option('--no-locals', |
| help='Exclude locals list from the dex file.') |
| + parser.add_option('--multi-dex', default=False, action='store_true', |
| + help='Create multiple dex files.') |
| parser.add_option('--inputs', help='A list of additional input paths.') |
| parser.add_option('--excluded-paths', |
| help='A list of paths to exclude from the dex file.') |
| + parser.add_option('--main-dex-list-paths', |
| + help='A list of paths containing a list of the classes to ' |
| + 'include in the main dex.') |
| options, paths = parser.parse_args(args) |