Chromium Code Reviews| Index: build/android/gyp/apkbuilder.py |
| diff --git a/build/android/gyp/apkbuilder.py b/build/android/gyp/apkbuilder.py |
| index 60bca1d655241c2155299bb97b5bf0306926b432..07fc9a8ffe647d1b5e816c4179e005ebd7ebc64b 100755 |
| --- a/build/android/gyp/apkbuilder.py |
| +++ b/build/android/gyp/apkbuilder.py |
| @@ -80,7 +80,29 @@ def _SplitAssetPath(path): |
| return src_path, dest_path |
| -def _AddAssets(apk, paths, disable_compression=False): |
| +def _ExpandPaths(paths): |
| + """Converts src:dst into tuples and enumerates files within directories. |
| + |
| + Args: |
| + paths: Paths in the form "src_path:dest_path" |
| + |
| + Returns: |
| + A list of (src_path, dest_path) tuples sorted by dest_path (for stable |
| + ordering within output .apk). |
| + """ |
| + ret = [] |
| + for path in paths: |
| + src_path, dest_path = _SplitAssetPath(path) |
| + if os.path.isdir(src_path): |
| + for f in build_utils.FindInDirectory(src_path, '*'): |
| + ret.append((f, os.path.join(dest_path, f[len(src_path) + 1:]))) |
|
pkotwicz
2015/11/17 19:34:25
I think that using os.path.basename() would be cle
agrieve
2015/11/21 01:47:26
It's not adding the past path component, but rathe
|
| + else: |
| + ret.append((src_path, dest_path)) |
| + ret.sort(key=lambda t:t[1]) |
| + return ret |
| + |
| + |
| +def _AddAssets(apk, path_tuples, disable_compression=False): |
| """Adds the given paths to the apk. |
| Args: |
| @@ -91,8 +113,7 @@ def _AddAssets(apk, paths, disable_compression=False): |
| # Group all uncompressed assets together in the hope that it will increase |
| # locality of mmap'ed files. |
| for target_compress in (False, True): |
| - for path in paths: |
| - src_path, dest_path = _SplitAssetPath(path) |
| + for src_path, dest_path in path_tuples: |
| compress = not disable_compression and ( |
| os.path.splitext(src_path)[1] not in _NO_COMPRESS_EXTENSIONS) |
| @@ -108,9 +129,10 @@ def _AddAssets(apk, paths, disable_compression=False): |
| compress=compress) |
| -def _CreateAssetsList(paths): |
| +def _CreateAssetsList(path_tuples): |
| """Returns a newline-separated list of asset paths for the given paths.""" |
| - return '\n'.join(_SplitAssetPath(p)[1] for p in sorted(paths)) + '\n' |
| + dests = sorted(t[1] for t in path_tuples) |
| + return '\n'.join(dests) + '\n' |
| def main(args): |
| @@ -127,8 +149,10 @@ def main(args): |
| input_strings = [options.create_placeholder_lib, options.android_abi] |
| - for path in itertools.chain(options.assets, options.uncompressed_assets): |
| - src_path, dest_path = _SplitAssetPath(path) |
| + _assets = _ExpandPaths(options.assets) |
| + _uncompressed_assets = _ExpandPaths(options.uncompressed_assets) |
| + |
| + for src_path, dest_path in itertools.chain(_assets, _uncompressed_assets): |
| input_paths.append(src_path) |
| input_strings.append(dest_path) |
| @@ -144,11 +168,11 @@ def main(args): |
| with zipfile.ZipFile(tmp_apk, 'a', zipfile.ZIP_DEFLATED) as apk: |
| if options.write_asset_list: |
| data = _CreateAssetsList( |
| - itertools.chain(options.assets, options.uncompressed_assets)) |
| + itertools.chain(_assets, _uncompressed_assets)) |
| build_utils.AddToZipHermetic(apk, 'assets/assets_list', data=data) |
| - _AddAssets(apk, options.assets, disable_compression=False) |
| - _AddAssets(apk, options.uncompressed_assets, disable_compression=True) |
| + _AddAssets(apk, _assets, disable_compression=False) |
| + _AddAssets(apk, _uncompressed_assets, disable_compression=True) |
| for path in native_libs: |
| basename = os.path.basename(path) |