| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 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 """Process Android resources to generate R.java, and prepare for packaging. | 7 """Process Android resources to generate R.java, and prepare for packaging. |
| 8 | 8 |
| 9 This will crunch images and generate v14 compatible resources | 9 This will crunch images and generate v14 compatible resources |
| 10 (see generate_v14_compatible_resources.py). | 10 (see generate_v14_compatible_resources.py). |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 for root, _, files in os.walk(d): | 148 for root, _, files in os.walk(d): |
| 149 for f in files: | 149 for f in files: |
| 150 archive_path = os.path.join(os.path.relpath(root, d), f) | 150 archive_path = os.path.join(os.path.relpath(root, d), f) |
| 151 path = os.path.join(root, f) | 151 path = os.path.join(root, f) |
| 152 files_to_zip[archive_path] = path | 152 files_to_zip[archive_path] = path |
| 153 with zipfile.ZipFile(zip_path, 'w') as outzip: | 153 with zipfile.ZipFile(zip_path, 'w') as outzip: |
| 154 for archive_path, path in files_to_zip.iteritems(): | 154 for archive_path, path in files_to_zip.iteritems(): |
| 155 outzip.write(path, archive_path) | 155 outzip.write(path, archive_path) |
| 156 | 156 |
| 157 | 157 |
| 158 def CombineZips(zip_files, output_path): |
| 159 # When packaging resources, if the top-level directories in the zip file are |
| 160 # of the form 0, 1, ..., then each subdirectory will be passed to aapt as a |
| 161 # resources directory. While some resources just clobber others (image files, |
| 162 # etc), other resources (particularly .xml files) need to be more |
| 163 # intelligently merged. That merging is left up to aapt. |
| 164 with zipfile.ZipFile(output_path, 'w') as outzip: |
| 165 for i, z in enumerate(zip_files): |
| 166 with zipfile.ZipFile(z, 'r') as inzip: |
| 167 for name in inzip.namelist(): |
| 168 new_name = '%d/%s' % (i, name) |
| 169 outzip.writestr(new_name, inzip.read(name)) |
| 170 |
| 171 |
| 158 def main(): | 172 def main(): |
| 159 args = build_utils.ExpandFileArgs(sys.argv[1:]) | 173 args = build_utils.ExpandFileArgs(sys.argv[1:]) |
| 160 | 174 |
| 161 options = ParseArgs(args) | 175 options = ParseArgs(args) |
| 162 android_jar = os.path.join(options.android_sdk, 'android.jar') | 176 android_jar = os.path.join(options.android_sdk, 'android.jar') |
| 163 aapt = os.path.join(options.android_sdk_tools, 'aapt') | 177 aapt = os.path.join(options.android_sdk_tools, 'aapt') |
| 164 | 178 |
| 165 input_files = [] | 179 input_files = [] |
| 166 | 180 |
| 167 with build_utils.TempDir() as temp_dir: | 181 with build_utils.TempDir() as temp_dir: |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 zip_resource_dirs.append(crunch_dir) | 255 zip_resource_dirs.append(crunch_dir) |
| 242 aapt_cmd = [aapt, | 256 aapt_cmd = [aapt, |
| 243 'crunch', | 257 'crunch', |
| 244 '-C', crunch_dir, | 258 '-C', crunch_dir, |
| 245 '-S', d] | 259 '-S', d] |
| 246 build_utils.CheckOutput(aapt_cmd, fail_func=DidCrunchFail) | 260 build_utils.CheckOutput(aapt_cmd, fail_func=DidCrunchFail) |
| 247 | 261 |
| 248 ZipResources(zip_resource_dirs, options.resource_zip_out) | 262 ZipResources(zip_resource_dirs, options.resource_zip_out) |
| 249 | 263 |
| 250 if options.all_resources_zip_out: | 264 if options.all_resources_zip_out: |
| 251 ZipResources( | 265 CombineZips([options.resource_zip_out] + dep_zips, |
| 252 zip_resource_dirs + dep_subdirs, options.all_resources_zip_out) | 266 options.all_resources_zip_out) |
| 253 | 267 |
| 254 if options.R_dir: | 268 if options.R_dir: |
| 255 build_utils.DeleteDirectory(options.R_dir) | 269 build_utils.DeleteDirectory(options.R_dir) |
| 256 shutil.copytree(gen_dir, options.R_dir) | 270 shutil.copytree(gen_dir, options.R_dir) |
| 257 else: | 271 else: |
| 258 build_utils.ZipDir(options.srcjar_out, gen_dir) | 272 build_utils.ZipDir(options.srcjar_out, gen_dir) |
| 259 | 273 |
| 260 if options.depfile: | 274 if options.depfile: |
| 261 input_files += build_utils.GetPythonDependencies() | 275 input_files += build_utils.GetPythonDependencies() |
| 262 build_utils.WriteDepfile(options.depfile, input_files) | 276 build_utils.WriteDepfile(options.depfile, input_files) |
| 263 | 277 |
| 264 if options.stamp: | 278 if options.stamp: |
| 265 build_utils.Touch(options.stamp) | 279 build_utils.Touch(options.stamp) |
| 266 | 280 |
| 267 | 281 |
| 268 if __name__ == '__main__': | 282 if __name__ == '__main__': |
| 269 main() | 283 main() |
| OLD | NEW |