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

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

Issue 1438413004: Port placeholders logic GYP->GN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix assert Created 5 years, 1 month 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 30 matching lines...) Expand all
41 help='Path to the output file', 41 help='Path to the output file',
42 required=True) 42 required=True)
43 parser.add_argument('--dex-file', 43 parser.add_argument('--dex-file',
44 help='Path to the classes.dex to use') 44 help='Path to the classes.dex to use')
45 # TODO(agrieve): Switch this to be a list of files rather than a directory. 45 # TODO(agrieve): Switch this to be a list of files rather than a directory.
46 parser.add_argument('--native-libs-dir', 46 parser.add_argument('--native-libs-dir',
47 help='Directory containing native libraries to include', 47 help='Directory containing native libraries to include',
48 default=[]) 48 default=[])
49 parser.add_argument('--android-abi', 49 parser.add_argument('--android-abi',
50 help='Android architecture to use for native libraries') 50 help='Android architecture to use for native libraries')
51 parser.add_argument('--create-placeholder-lib', 51 parser.add_argument('--native-lib-placeholders',
52 action='store_true', 52 help='GYP-list of native library placeholders to add.',
53 help='Whether to add a dummy library file') 53 default='[]')
54 options = parser.parse_args(args) 54 options = parser.parse_args(args)
55 if not options.android_abi and (options.native_libs_dir or
56 options.create_placeholder_lib):
57 raise Exception('Must specify --android-abi with --native-libs-dir')
58 options.assets = build_utils.ParseGypList(options.assets) 55 options.assets = build_utils.ParseGypList(options.assets)
59 options.uncompressed_assets = build_utils.ParseGypList( 56 options.uncompressed_assets = build_utils.ParseGypList(
60 options.uncompressed_assets) 57 options.uncompressed_assets)
58 options.native_lib_placeholders = build_utils.ParseGypList(
59 options.native_lib_placeholders)
60
61 if not options.android_abi and (options.native_libs_dir or
62 options.native_lib_placeholders):
63 raise Exception('Must specify --android-abi with --native-libs-dir')
61 return options 64 return options
62 65
63 66
64 def _ListSubPaths(path): 67 def _ListSubPaths(path):
65 """Returns a list of full paths to all files in the given path.""" 68 """Returns a list of full paths to all files in the given path."""
66 return [os.path.join(path, name) for name in os.listdir(path)] 69 return [os.path.join(path, name) for name in os.listdir(path)]
67 70
68 71
69 def _SplitAssetPath(path): 72 def _SplitAssetPath(path):
70 """Returns (src, dest) given an asset path in the form src[:dest].""" 73 """Returns (src, dest) given an asset path in the form src[:dest]."""
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 options = _ParseArgs(args) 115 options = _ParseArgs(args)
113 116
114 native_libs = [] 117 native_libs = []
115 if options.native_libs_dir: 118 if options.native_libs_dir:
116 native_libs = _ListSubPaths(options.native_libs_dir) 119 native_libs = _ListSubPaths(options.native_libs_dir)
117 120
118 input_paths = [options.resource_apk, __file__] + native_libs 121 input_paths = [options.resource_apk, __file__] + native_libs
119 if options.dex_file: 122 if options.dex_file:
120 input_paths.append(options.dex_file) 123 input_paths.append(options.dex_file)
121 124
122 input_strings = [options.create_placeholder_lib, options.android_abi] 125 input_strings = [options.android_abi, options.native_lib_placeholders]
123 126
124 for path in itertools.chain(options.assets, options.uncompressed_assets): 127 for path in itertools.chain(options.assets, options.uncompressed_assets):
125 src_path, dest_path = _SplitAssetPath(path) 128 src_path, dest_path = _SplitAssetPath(path)
126 input_paths.append(src_path) 129 input_paths.append(src_path)
127 input_strings.append(dest_path) 130 input_strings.append(dest_path)
128 131
129 def on_stale_md5(): 132 def on_stale_md5():
130 tmp_apk = options.output_apk + '.tmp' 133 tmp_apk = options.output_apk + '.tmp'
131 try: 134 try:
132 # Use a temp file to avoid creating an output if anything goes wrong. 135 # Use a temp file to avoid creating an output if anything goes wrong.
133 shutil.copyfile(options.resource_apk, tmp_apk) 136 shutil.copyfile(options.resource_apk, tmp_apk)
134 137
135 # TODO(agrieve): It would be more efficient to combine this step 138 # TODO(agrieve): It would be more efficient to combine this step
136 # with finalize_apk(), which sometimes aligns and uncompresses the 139 # with finalize_apk(), which sometimes aligns and uncompresses the
137 # native libraries. 140 # native libraries.
138 with zipfile.ZipFile(tmp_apk, 'a', zipfile.ZIP_DEFLATED) as apk: 141 with zipfile.ZipFile(tmp_apk, 'a', zipfile.ZIP_DEFLATED) as apk:
139 _AddAssets(apk, options.assets, disable_compression=False) 142 _AddAssets(apk, options.assets, disable_compression=False)
140 _AddAssets(apk, options.uncompressed_assets, disable_compression=True) 143 _AddAssets(apk, options.uncompressed_assets, disable_compression=True)
141 for path in native_libs: 144 for path in native_libs:
142 basename = os.path.basename(path) 145 basename = os.path.basename(path)
143 apk.write(path, 'lib/%s/%s' % (options.android_abi, basename)) 146 apk.write(path, 'lib/%s/%s' % (options.android_abi, basename))
144 if options.create_placeholder_lib: 147 for name in options.native_lib_placeholders:
145 # Make it non-empty so that its checksum is non-zero and is not 148 # Make it non-empty so that its checksum is non-zero and is not
146 # ignored by md5_check. 149 # ignored by md5_check.
147 apk.writestr('lib/%s/libplaceholder.so' % options.android_abi, ':-)') 150 apk.writestr('lib/%s/%s' % (options.android_abi, name), ':)',
151 zipfile.ZIP_STORED)
148 if options.dex_file: 152 if options.dex_file:
149 apk.write(options.dex_file, 'classes.dex') 153 apk.write(options.dex_file, 'classes.dex')
150 154
151 shutil.move(tmp_apk, options.output_apk) 155 shutil.move(tmp_apk, options.output_apk)
152 finally: 156 finally:
153 if os.path.exists(tmp_apk): 157 if os.path.exists(tmp_apk):
154 os.unlink(tmp_apk) 158 os.unlink(tmp_apk)
155 159
156 build_utils.CallAndWriteDepfileIfStale( 160 build_utils.CallAndWriteDepfileIfStale(
157 on_stale_md5, 161 on_stale_md5,
158 options, 162 options,
159 input_paths=input_paths, 163 input_paths=input_paths,
160 input_strings=input_strings, 164 input_strings=input_strings,
161 output_paths=[options.output_apk]) 165 output_paths=[options.output_apk])
162 166
163 167
164 if __name__ == '__main__': 168 if __name__ == '__main__':
165 main(sys.argv[1:]) 169 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