Index: build/android/gyp/process_resources.py |
diff --git a/build/android/gyp/process_resources.py b/build/android/gyp/process_resources.py |
index ec19f5943f91a8082f163c3a964f04dc8f6839e5..f368d0d6c6009f3fee4a99ee2bb0696c50706ec4 100755 |
--- a/build/android/gyp/process_resources.py |
+++ b/build/android/gyp/process_resources.py |
@@ -13,19 +13,22 @@ This will crunch images and generate v14 compatible resources |
import optparse |
import os |
import re |
+import shutil |
+import sys |
import zipfile |
import generate_v14_compatible_resources |
from util import build_utils |
-def ParseArgs(): |
+def ParseArgs(args): |
"""Parses command line options. |
Returns: |
An options object as from optparse.OptionsParser.parse_args() |
""" |
parser = optparse.OptionParser() |
+ build_utils.AddDepfileOption(parser) |
parser.add_option('--android-sdk', help='path to the Android SDK folder') |
parser.add_option('--android-sdk-tools', |
@@ -40,10 +43,14 @@ def ParseArgs(): |
parser.add_option('--dependencies-res-zips', |
help='Resources from dependents.') |
- parser.add_option('--R-dir', help='directory to hold generated R.java') |
parser.add_option('--resource-zip-out', |
help='Path for output zipped resources.') |
+ parser.add_option('--R-dir', |
+ help='directory to hold generated R.java.') |
+ parser.add_option('--srcjar-out', |
+ help='Path to srcjar to contain generated R.java.') |
+ |
parser.add_option('--proguard-file', |
help='Path to proguard.txt generated file') |
@@ -65,7 +72,7 @@ def ParseArgs(): |
parser.add_option('--stamp', help='File to touch on success') |
- (options, args) = parser.parse_args() |
+ (options, args) = parser.parse_args(args) |
if args: |
parser.error('No positional arguments should be given.') |
@@ -78,10 +85,12 @@ def ParseArgs(): |
'dependencies_res_zips', |
'resource_dirs', |
'resource_zip_out', |
- 'R_dir', |
) |
build_utils.CheckOptions(options, parser, required=required_options) |
+ if (options.R_dir is None) == (options.srcjar_out is None): |
+ raise Exception('Exactly one of --R-dir or --srcjar-out must be specified.') |
+ |
return options |
@@ -109,10 +118,6 @@ def CreateExtraRJavaFiles( |
# affect how the code in this .apk target could refer to the resources. |
- |
- |
- |
- |
def DidCrunchFail(returncode, stderr): |
"""Determines whether aapt crunch failed from its return code and output. |
@@ -129,13 +134,30 @@ def DidCrunchFail(returncode, stderr): |
return False |
+def ZipResources(resource_dirs, zip_path): |
+ # Python zipfile does not provide a way to replace a file (it just writes |
+ # another file with the same name). So, first collect all the files to put |
+ # in the zip (with proper overriding), and then zip them. |
+ files_to_zip = dict() |
+ for d in resource_dirs: |
+ for root, _, files in os.walk(d): |
+ for f in files: |
+ archive_path = os.path.join(os.path.relpath(root, d), f) |
+ path = os.path.join(root, f) |
+ files_to_zip[archive_path] = path |
+ with zipfile.ZipFile(zip_path, 'w') as outzip: |
+ for archive_path, path in files_to_zip.iteritems(): |
+ outzip.write(path, archive_path) |
+ |
+ |
def main(): |
- options = ParseArgs() |
+ args = build_utils.ExpandFileArgs(sys.argv[1:]) |
+ |
+ options = ParseArgs(args) |
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) |
+ input_files = [] |
with build_utils.TempDir() as temp_dir: |
deps_dir = os.path.join(temp_dir, 'deps') |
@@ -143,6 +165,9 @@ def main(): |
v14_dir = os.path.join(temp_dir, 'v14') |
build_utils.MakeDirectory(v14_dir) |
+ gen_dir = os.path.join(temp_dir, 'gen') |
+ build_utils.MakeDirectory(gen_dir) |
+ |
input_resource_dirs = build_utils.ParseGypList(options.resource_dirs) |
for resource_dir in input_resource_dirs: |
@@ -151,6 +176,16 @@ def main(): |
v14_dir, |
options.v14_verify_only) |
+ dep_zips = build_utils.ParseGypList(options.dependencies_res_zips) |
+ input_files += dep_zips |
+ dep_subdirs = [] |
+ for z in dep_zips: |
+ subdir = os.path.join(deps_dir, os.path.basename(z)) |
+ if os.path.exists(subdir): |
+ raise Exception('Resource zip name conflict: ' + os.path.basename(z)) |
+ build_utils.ExtractAll(z, path=subdir) |
+ dep_subdirs.append(subdir) |
+ |
# Generate R.java. This R.java contains non-final constants and is used only |
# while compiling the library jar (e.g. chromium_content.jar). When building |
# an apk, a new R.java file with the correct resource -> ID mappings will be |
@@ -162,19 +197,14 @@ def main(): |
'-M', options.android_manifest, |
'--auto-add-overlay', |
'-I', android_jar, |
- '--output-text-symbols', options.R_dir, |
- '-J', options.R_dir] |
+ '--output-text-symbols', gen_dir, |
+ '-J', gen_dir] |
for d in input_resource_dirs: |
package_command += ['-S', d] |
- dep_zips = build_utils.ParseGypList(options.dependencies_res_zips) |
- for z in dep_zips: |
- subdir = os.path.join(deps_dir, os.path.basename(z)) |
- if os.path.exists(subdir): |
- raise Exception('Resource zip name conflict: ' + os.path.basename(z)) |
- build_utils.ExtractAll(z, path=subdir) |
- package_command += ['-S', subdir] |
+ for d in dep_subdirs: |
+ package_command += ['-S', d] |
if options.non_constant_id: |
package_command.append('--non-constant-id') |
@@ -186,7 +216,7 @@ def main(): |
if options.extra_res_packages: |
CreateExtraRJavaFiles( |
- options.R_dir, |
+ gen_dir, |
build_utils.ParseGypList(options.extra_res_packages), |
build_utils.ParseGypList(options.extra_r_text_files)) |
@@ -210,22 +240,20 @@ def main(): |
'-S', d] |
build_utils.CheckOutput(aapt_cmd, fail_func=DidCrunchFail) |
- # Python zipfile does not provide a way to replace a file (it just writes |
- # another file with the same name). So, first collect all the files to put |
- # in the zip (with proper overriding), and then zip them. |
- files_to_zip = dict() |
- for d in zip_resource_dirs: |
- for root, _, files in os.walk(d): |
- for f in files: |
- archive_path = os.path.join(os.path.relpath(root, d), f) |
- path = os.path.join(root, f) |
- files_to_zip[archive_path] = path |
- with zipfile.ZipFile(options.resource_zip_out, 'w') as outzip: |
- for archive_path, path in files_to_zip.iteritems(): |
- outzip.write(path, archive_path) |
- |
- if options.stamp: |
- build_utils.Touch(options.stamp) |
+ ZipResources(zip_resource_dirs, options.resource_zip_out) |
+ |
+ if options.R_dir: |
+ build_utils.DeleteDirectory(options.R_dir) |
+ shutil.copytree(gen_dir, options.R_dir) |
+ else: |
+ build_utils.ZipDir(options.srcjar_out, gen_dir) |
+ |
+ if options.depfile: |
+ input_files += build_utils.GetPythonDependencies() |
+ build_utils.WriteDepfile(options.depfile, input_files) |
+ |
+ if options.stamp: |
+ build_utils.Touch(options.stamp) |
if __name__ == '__main__': |