| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 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 # pylint: disable=C0301 | 7 # pylint: disable=C0301 |
| 8 """Package resources into an apk. | 8 """Package resources into an apk. |
| 9 | 9 |
| 10 See https://android.googlesource.com/platform/tools/base/+/master/legacy/ant-tas
ks/src/main/java/com/android/ant/AaptExecTask.java | 10 See https://android.googlesource.com/platform/tools/base/+/master/legacy/ant-tas
ks/src/main/java/com/android/ant/AaptExecTask.java |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 build_utils.MakeDirectory(dst_dir) | 81 build_utils.MakeDirectory(dst_dir) |
| 82 for src_file_name in os.listdir(src_dir): | 82 for src_file_name in os.listdir(src_dir): |
| 83 if not src_file_name.endswith('.png'): | 83 if not src_file_name.endswith('.png'): |
| 84 continue | 84 continue |
| 85 src_file = os.path.join(src_dir, src_file_name) | 85 src_file = os.path.join(src_dir, src_file_name) |
| 86 dst_file = os.path.join(dst_dir, src_file_name) | 86 dst_file = os.path.join(dst_dir, src_file_name) |
| 87 assert not os.path.lexists(dst_file) | 87 assert not os.path.lexists(dst_file) |
| 88 shutil.move(src_file, dst_file) | 88 shutil.move(src_file, dst_file) |
| 89 | 89 |
| 90 | 90 |
| 91 def PackageArgsForExtractedZip(d): |
| 92 """Returns the aapt args for an extracted resources zip. |
| 93 |
| 94 A resources zip either contains the resources for a single target or for |
| 95 multiple targets. If it is multiple targets merged into one, the actual |
| 96 resource directories will be contained in the subdirectories 0, 1, 2, ... |
| 97 """ |
| 98 res_dirs = [] |
| 99 subdirs = [os.path.join(d, s) for s in os.listdir(d)] |
| 100 subdirs = sorted([s for s in subdirs if os.path.isdir(s)]) |
| 101 if subdirs and os.path.basename(subdirs[0]) == '0': |
| 102 res_dirs = subdirs |
| 103 else: |
| 104 res_dirs = [d] |
| 105 package_command = [] |
| 106 for d in res_dirs: |
| 107 MoveImagesToNonMdpiFolders(d) |
| 108 package_command += ['-S', d] |
| 109 return package_command |
| 110 |
| 111 |
| 91 def main(): | 112 def main(): |
| 92 options = ParseArgs() | 113 options = ParseArgs() |
| 93 android_jar = os.path.join(options.android_sdk, 'android.jar') | 114 android_jar = os.path.join(options.android_sdk, 'android.jar') |
| 94 aapt = os.path.join(options.android_sdk_tools, 'aapt') | 115 aapt = os.path.join(options.android_sdk_tools, 'aapt') |
| 95 | 116 |
| 96 with build_utils.TempDir() as temp_dir: | 117 with build_utils.TempDir() as temp_dir: |
| 97 package_command = [aapt, | 118 package_command = [aapt, |
| 98 'package', | 119 'package', |
| 99 '--version-code', options.version_code, | 120 '--version-code', options.version_code, |
| 100 '--version-name', options.version_name, | 121 '--version-name', options.version_name, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 113 | 134 |
| 114 if os.path.exists(options.asset_dir): | 135 if os.path.exists(options.asset_dir): |
| 115 package_command += ['-A', options.asset_dir] | 136 package_command += ['-A', options.asset_dir] |
| 116 | 137 |
| 117 dep_zips = build_utils.ParseGypList(options.resource_zips) | 138 dep_zips = build_utils.ParseGypList(options.resource_zips) |
| 118 for z in dep_zips: | 139 for z in dep_zips: |
| 119 subdir = os.path.join(temp_dir, os.path.basename(z)) | 140 subdir = os.path.join(temp_dir, os.path.basename(z)) |
| 120 if os.path.exists(subdir): | 141 if os.path.exists(subdir): |
| 121 raise Exception('Resource zip name conflict: ' + os.path.basename(z)) | 142 raise Exception('Resource zip name conflict: ' + os.path.basename(z)) |
| 122 build_utils.ExtractAll(z, path=subdir) | 143 build_utils.ExtractAll(z, path=subdir) |
| 123 MoveImagesToNonMdpiFolders(subdir) | 144 package_command += PackageArgsForExtractedZip(subdir) |
| 124 package_command += ['-S', subdir] | |
| 125 | 145 |
| 126 if 'Debug' in options.configuration_name: | 146 if 'Debug' in options.configuration_name: |
| 127 package_command += ['--debug-mode'] | 147 package_command += ['--debug-mode'] |
| 128 | 148 |
| 129 build_utils.CheckOutput( | 149 build_utils.CheckOutput( |
| 130 package_command, print_stdout=False, print_stderr=False) | 150 package_command, print_stdout=False, print_stderr=False) |
| 131 | 151 |
| 132 if options.depfile: | 152 if options.depfile: |
| 133 build_utils.WriteDepfile( | 153 build_utils.WriteDepfile( |
| 134 options.depfile, | 154 options.depfile, |
| 135 build_utils.GetPythonDependencies()) | 155 build_utils.GetPythonDependencies()) |
| 136 | 156 |
| 137 | 157 |
| 138 if __name__ == '__main__': | 158 if __name__ == '__main__': |
| 139 main() | 159 main() |
| OLD | NEW |