Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Side by Side Diff: build/android/gyp/apkbuilder.py

Issue 1435333008: GN: asset_location -> android_assets() for html_viewer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaswe Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/config/android/internal_rules.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2015 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2015 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Adds the code parts to a resource APK.""" 7 """Adds the code parts to a resource APK."""
8 8
9 import argparse 9 import argparse
10 import itertools 10 import itertools
(...skipping 13 matching lines...) Expand all
24 '.3gpp2', '.amr', '.awb', '.wma', '.wmv') 24 '.3gpp2', '.amr', '.awb', '.wma', '.wmv')
25 25
26 26
27 def _ParseArgs(args): 27 def _ParseArgs(args):
28 parser = argparse.ArgumentParser() 28 parser = argparse.ArgumentParser()
29 build_utils.AddDepfileOption(parser) 29 build_utils.AddDepfileOption(parser)
30 parser.add_argument('--assets', 30 parser.add_argument('--assets',
31 help='GYP-list of files to add as assets in the form ' 31 help='GYP-list of files to add as assets in the form '
32 '"srcPath:zipPath", where ":zipPath" is optional.', 32 '"srcPath:zipPath", where ":zipPath" is optional.',
33 default='[]') 33 default='[]')
34 parser.add_argument('--write-asset-list',
35 action='store_true',
36 help='Whether to create an assets/assets_list file.')
34 parser.add_argument('--uncompressed-assets', 37 parser.add_argument('--uncompressed-assets',
35 help='Same as --assets, except disables compression.', 38 help='Same as --assets, except disables compression.',
36 default='[]') 39 default='[]')
37 parser.add_argument('--resource-apk', 40 parser.add_argument('--resource-apk',
38 help='An .ap_ file built using aapt', 41 help='An .ap_ file built using aapt',
39 required=True) 42 required=True)
40 parser.add_argument('--output-apk', 43 parser.add_argument('--output-apk',
41 help='Path to the output file', 44 help='Path to the output file',
42 required=True) 45 required=True)
43 parser.add_argument('--dex-file', 46 parser.add_argument('--dex-file',
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 try: 106 try:
104 apk.getinfo(apk_path) 107 apk.getinfo(apk_path)
105 # Should never happen since write_build_config.py handles merging. 108 # Should never happen since write_build_config.py handles merging.
106 raise Exception('Multiple targets specified the asset path: %s' % 109 raise Exception('Multiple targets specified the asset path: %s' %
107 apk_path) 110 apk_path)
108 except KeyError: 111 except KeyError:
109 build_utils.AddToZipHermetic(apk, apk_path, src_path=src_path, 112 build_utils.AddToZipHermetic(apk, apk_path, src_path=src_path,
110 compress=compress) 113 compress=compress)
111 114
112 115
116 def _CreateAssetsList(paths):
117 """Returns a newline-separated list of asset paths for the given paths."""
118 return '\n'.join(_SplitAssetPath(p)[1] for p in sorted(paths)) + '\n'
119
120
113 def main(args): 121 def main(args):
114 args = build_utils.ExpandFileArgs(args) 122 args = build_utils.ExpandFileArgs(args)
115 options = _ParseArgs(args) 123 options = _ParseArgs(args)
116 124
117 native_libs = [] 125 native_libs = []
118 if options.native_libs_dir: 126 if options.native_libs_dir:
119 native_libs = _ListSubPaths(options.native_libs_dir) 127 native_libs = _ListSubPaths(options.native_libs_dir)
120 128
121 input_paths = [options.resource_apk, __file__] + native_libs 129 input_paths = [options.resource_apk, __file__] + native_libs
122 if options.dex_file: 130 if options.dex_file:
(...skipping 12 matching lines...) Expand all
135 def on_stale_md5(): 143 def on_stale_md5():
136 tmp_apk = options.output_apk + '.tmp' 144 tmp_apk = options.output_apk + '.tmp'
137 try: 145 try:
138 # Use a temp file to avoid creating an output if anything goes wrong. 146 # Use a temp file to avoid creating an output if anything goes wrong.
139 shutil.copyfile(options.resource_apk, tmp_apk) 147 shutil.copyfile(options.resource_apk, tmp_apk)
140 148
141 # TODO(agrieve): It would be more efficient to combine this step 149 # TODO(agrieve): It would be more efficient to combine this step
142 # with finalize_apk(), which sometimes aligns and uncompresses the 150 # with finalize_apk(), which sometimes aligns and uncompresses the
143 # native libraries. 151 # native libraries.
144 with zipfile.ZipFile(tmp_apk, 'a', zipfile.ZIP_DEFLATED) as apk: 152 with zipfile.ZipFile(tmp_apk, 'a', zipfile.ZIP_DEFLATED) as apk:
153 if options.write_asset_list:
154 data = _CreateAssetsList(
155 itertools.chain(options.assets, options.uncompressed_assets))
156 build_utils.AddToZipHermetic(apk, 'assets/assets_list', data=data)
157
145 _AddAssets(apk, options.assets, disable_compression=False) 158 _AddAssets(apk, options.assets, disable_compression=False)
146 _AddAssets(apk, options.uncompressed_assets, disable_compression=True) 159 _AddAssets(apk, options.uncompressed_assets, disable_compression=True)
160
147 for path in native_libs: 161 for path in native_libs:
148 basename = os.path.basename(path) 162 basename = os.path.basename(path)
149 apk_path = 'lib/%s/%s' % (options.android_abi, basename) 163 apk_path = 'lib/%s/%s' % (options.android_abi, basename)
150 build_utils.AddToZipHermetic(apk, apk_path, src_path=path) 164 build_utils.AddToZipHermetic(apk, apk_path, src_path=path)
151 165
152 for name in options.native_lib_placeholders: 166 for name in options.native_lib_placeholders:
153 # Make it non-empty so that its checksum is non-zero and is not 167 # Make it non-empty so that its checksum is non-zero and is not
154 # ignored by md5_check. 168 # ignored by md5_check.
155 apk_path = 'lib/%s/%s.so' % (options.android_abi, name) 169 apk_path = 'lib/%s/%s.so' % (options.android_abi, name)
156 build_utils.AddToZipHermetic(apk, apk_path, data=':)') 170 build_utils.AddToZipHermetic(apk, apk_path, data=':)')
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 build_utils.CallAndWriteDepfileIfStale( 202 build_utils.CallAndWriteDepfileIfStale(
189 on_stale_md5, 203 on_stale_md5,
190 options, 204 options,
191 input_paths=input_paths, 205 input_paths=input_paths,
192 input_strings=input_strings, 206 input_strings=input_strings,
193 output_paths=[options.output_apk]) 207 output_paths=[options.output_apk])
194 208
195 209
196 if __name__ == '__main__': 210 if __name__ == '__main__':
197 main(sys.argv[1:]) 211 main(sys.argv[1:])
OLDNEW
« no previous file with comments | « no previous file | build/config/android/internal_rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698