| Index: build/android/gyp/process_resources.py
|
| diff --git a/build/android/gyp/process_resources.py b/build/android/gyp/process_resources.py
|
| index 9bad5c1bcaedece8076a0d357523cc3e1a421d73..64a756048da9dc4d707bc1bc2c4e3c651c33bcc5 100755
|
| --- a/build/android/gyp/process_resources.py
|
| +++ b/build/android/gyp/process_resources.py
|
| @@ -8,6 +8,7 @@
|
|
|
| import optparse
|
| import os
|
| +import re
|
| import shlex
|
| import shutil
|
|
|
| @@ -24,30 +25,73 @@ def ParseArgs():
|
| parser.add_option('--android-sdk-tools',
|
| help='path to the Android SDK build tools folder')
|
| parser.add_option('--R-dir', help='directory to hold generated R.java')
|
| - parser.add_option('--res-dirs',
|
| + parser.add_option('--dependencies-res-dirs',
|
| help='directories containing resources to be packaged')
|
| - parser.add_option('--crunch-input-dir',
|
| - help='directory containing images to be crunched')
|
| + parser.add_option('--resource-dir',
|
| + help='directory containing this target\'s resources.')
|
| parser.add_option('--crunch-output-dir',
|
| help='directory to hold crunched resources')
|
| parser.add_option('--non-constant-id', action='store_true')
|
| parser.add_option('--custom-package', help='Java package for R.java')
|
| parser.add_option('--android-manifest', help='AndroidManifest.xml path')
|
| + parser.add_option('--proguard-file',
|
| + help='Path to proguard.txt generated file')
|
| parser.add_option('--stamp', help='File to touch on success')
|
|
|
| + parser.add_option(
|
| + '--extra-res-packages',
|
| + help='Additional package names to generate R.java files for')
|
| + parser.add_option(
|
| + '--extra-r-text-files',
|
| + help='For each additional package, the R.txt file should contain a '
|
| + 'list of resources to be included in the R.java file in the format '
|
| + 'generated by aapt')
|
| +
|
| (options, args) = parser.parse_args()
|
|
|
| if args:
|
| parser.error('No positional arguments should be given.')
|
|
|
| # Check that required options have been provided.
|
| - required_options = ('android_sdk', 'android_sdk_tools', 'R_dir',
|
| - 'res_dirs', 'crunch_input_dir', 'crunch_output_dir')
|
| + required_options = (
|
| + 'android_sdk',
|
| + 'android_sdk_tools',
|
| + 'android_manifest',
|
| + 'dependencies_res_dirs',
|
| + 'resource_dir',
|
| + 'crunch_output_dir',
|
| + 'R_dir',
|
| + )
|
| build_utils.CheckOptions(options, parser, required=required_options)
|
|
|
| return options
|
|
|
|
|
| +def CreateExtraRJavaFiles(
|
| + r_dir, extra_packages, extra_r_text_files):
|
| + if len(extra_packages) != len(extra_r_text_files):
|
| + raise Exception('--extra-res-packages and --extra-r-text-files'
|
| + 'should have the same length')
|
| +
|
| + java_files = build_utils.FindInDirectory(r_dir, "R.java")
|
| + if len(java_files) != 1:
|
| + return
|
| + r_java_file = java_files[0]
|
| + r_java_contents = open(r_java_file).read()
|
| +
|
| + for package in extra_packages:
|
| + package_r_java_dir = os.path.join(r_dir, *package.split('.'))
|
| + build_utils.MakeDirectory(package_r_java_dir)
|
| + package_r_java_path = os.path.join(package_r_java_dir, 'R.java')
|
| + open(package_r_java_path, 'w').write(
|
| + re.sub(r'package [.\w]*;', 'package %s;' % package, r_java_contents))
|
| + # TODO(cjhopman): These extra package's R.java files should be filtered to
|
| + # only contain the resources listed in their R.txt files. At this point, we
|
| + # have already compiled those other libraries, so doing this would only
|
| + # affect how the code in this .apk target could refer to the resources.
|
| +
|
| +
|
| +
|
| def MoveImagesToNonMdpiFolders(res_root):
|
| """Move images from drawable-*-mdpi-* folders to drawable-* folders.
|
|
|
| @@ -95,6 +139,7 @@ def main():
|
| android_jar = os.path.join(options.android_sdk, 'android.jar')
|
| aapt = os.path.join(options.android_sdk_tools, 'aapt')
|
|
|
| + build_utils.DeleteDirectory(options.R_dir)
|
| build_utils.MakeDirectory(options.R_dir)
|
|
|
| # Generate R.java. This R.java contains non-final constants and is used only
|
| @@ -110,21 +155,32 @@ def main():
|
| '-I', android_jar,
|
| '--output-text-symbols', options.R_dir,
|
| '-J', options.R_dir]
|
| - res_dirs = shlex.split(options.res_dirs)
|
| - for res_dir in res_dirs:
|
| + all_res_dirs = ([options.resource_dir]
|
| + + shlex.split(options.dependencies_res_dirs))
|
| + for res_dir in all_res_dirs:
|
| package_command += ['-S', res_dir]
|
| if options.non_constant_id:
|
| package_command.append('--non-constant-id')
|
| if options.custom_package:
|
| package_command += ['--custom-package', options.custom_package]
|
| + if options.proguard_file:
|
| + package_command += ['-G', options.proguard_file]
|
| +
|
| build_utils.CheckOutput(package_command)
|
|
|
| + if options.extra_res_packages:
|
| + CreateExtraRJavaFiles(
|
| + options.R_dir,
|
| + build_utils.ParseGypList(options.extra_res_packages),
|
| + build_utils.ParseGypList(options.extra_r_text_files))
|
| +
|
| # Crunch image resources. This shrinks png files and is necessary for 9-patch
|
| # images to display correctly.
|
| + build_utils.DeleteDirectory(options.crunch_output_dir)
|
| build_utils.MakeDirectory(options.crunch_output_dir)
|
| aapt_cmd = [aapt,
|
| 'crunch',
|
| - '-S', options.crunch_input_dir,
|
| + '-S', options.resource_dir,
|
| '-C', options.crunch_output_dir]
|
| build_utils.CheckOutput(aapt_cmd, fail_func=DidCrunchFail)
|
|
|
|
|