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..fcb889e56b80808223d0758bdd2b742782fda1b4 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,9 +25,9 @@ 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', |
+ parser.add_option('--resource-dir', |
help='directory containing images to be crunched') |
Yaron
2014/05/19 18:33:00
isn't this all resources and not just crunched ima
cjhopman
2014/05/20 20:40:41
Done.
|
parser.add_option('--crunch-output-dir', |
help='directory to hold crunched resources') |
@@ -35,6 +36,15 @@ def ParseArgs(): |
parser.add_option('--android-manifest', help='AndroidManifest.xml path') |
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: |
@@ -43,11 +53,36 @@ def ParseArgs(): |
# Check that required options have been provided. |
required_options = ('android_sdk', 'android_sdk_tools', 'R_dir', |
'res_dirs', 'crunch_input_dir', 'crunch_output_dir') |
- build_utils.CheckOptions(options, parser, required=required_options) |
+ #build_utils.CheckOptions(options, parser, required=required_options) |
Yaron
2014/05/19 18:33:00
?
cjhopman
2014/05/20 20:40:41
Done.
|
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: |
+ raise Exception('couldn\'t find R.java file: ' + ','.join(java_files)) |
+ 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 +130,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) |
Yaron
2014/05/19 18:33:00
So any touched resources causes full reprocessing?
cjhopman
2014/05/20 20:40:41
Really, the only thing in this directory should be
|
build_utils.MakeDirectory(options.R_dir) |
# Generate R.java. This R.java contains non-final constants and is used only |
@@ -110,8 +146,9 @@ 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 = (shlex.split(options.dependencies_res_dirs) |
+ + [options.resource_dir]) |
+ for res_dir in all_res_dirs: |
package_command += ['-S', res_dir] |
if options.non_constant_id: |
package_command.append('--non-constant-id') |
@@ -119,12 +156,18 @@ def main(): |
package_command += ['--custom-package', options.custom_package] |
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.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) |