Make process_resources.py more configurable
This allows more configuration of the aapt call from within gyp. This is primarily to support differences that are required to use process_resources.py for java_apk.gypi. BUG=158821 Review URL: https://chromiumcodereview.appspot.com/12516019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@190055 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
build
@ -10,9 +10,7 @@ import optparse
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from pylib import build_utils
|
||||||
BUILD_ANDROID_DIR = os.path.dirname(__file__)
|
|
||||||
|
|
||||||
|
|
||||||
def ParseArgs():
|
def ParseArgs():
|
||||||
"""Parses command line options.
|
"""Parses command line options.
|
||||||
@ -24,11 +22,15 @@ def ParseArgs():
|
|||||||
parser.add_option('--android-sdk', help='path to the Android SDK folder')
|
parser.add_option('--android-sdk', help='path to the Android SDK folder')
|
||||||
parser.add_option('--android-sdk-tools',
|
parser.add_option('--android-sdk-tools',
|
||||||
help='path to the Android SDK platform tools folder')
|
help='path to the Android SDK platform tools folder')
|
||||||
parser.add_option('--R-package', help='Java package for generated R.java')
|
|
||||||
parser.add_option('--R-dir', help='directory to hold generated R.java')
|
parser.add_option('--R-dir', help='directory to hold generated R.java')
|
||||||
parser.add_option('--res-dir', help='directory containing resources')
|
parser.add_option('--res-dir', help='directory containing resources')
|
||||||
parser.add_option('--out-res-dir',
|
parser.add_option('--out-res-dir',
|
||||||
help='directory to hold crunched resources')
|
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('--stamp', help='File to touch on success')
|
||||||
|
|
||||||
# This is part of a temporary fix for crbug.com/177552.
|
# This is part of a temporary fix for crbug.com/177552.
|
||||||
# TODO(newt): remove this once crbug.com/177552 is fixed in ninja.
|
# TODO(newt): remove this once crbug.com/177552 is fixed in ninja.
|
||||||
parser.add_option('--ignore', help='this argument is ignored')
|
parser.add_option('--ignore', help='this argument is ignored')
|
||||||
@ -38,7 +40,7 @@ def ParseArgs():
|
|||||||
parser.error('No positional arguments should be given.')
|
parser.error('No positional arguments should be given.')
|
||||||
|
|
||||||
# Check that required options have been provided.
|
# Check that required options have been provided.
|
||||||
required_options = ('android_sdk', 'android_sdk_tools', 'R_package',
|
required_options = ('android_sdk', 'android_sdk_tools',
|
||||||
'R_dir', 'res_dir', 'out_res_dir')
|
'R_dir', 'res_dir', 'out_res_dir')
|
||||||
for option_name in required_options:
|
for option_name in required_options:
|
||||||
if getattr(options, option_name) is None:
|
if getattr(options, option_name) is None:
|
||||||
@ -51,7 +53,8 @@ def main():
|
|||||||
options = ParseArgs()
|
options = ParseArgs()
|
||||||
android_jar = os.path.join(options.android_sdk, 'android.jar')
|
android_jar = os.path.join(options.android_sdk, 'android.jar')
|
||||||
aapt = os.path.join(options.android_sdk_tools, 'aapt')
|
aapt = os.path.join(options.android_sdk_tools, 'aapt')
|
||||||
dummy_manifest = os.path.join(BUILD_ANDROID_DIR, 'AndroidManifest.xml')
|
|
||||||
|
build_utils.MakeDirectory(options.R_dir)
|
||||||
|
|
||||||
# Generate R.java. This R.java contains non-final constants and is used only
|
# 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
|
# while compiling the library jar (e.g. chromium_content.jar). When building
|
||||||
@ -61,9 +64,7 @@ def main():
|
|||||||
package_command = [aapt,
|
package_command = [aapt,
|
||||||
'package',
|
'package',
|
||||||
'-m',
|
'-m',
|
||||||
'--non-constant-id',
|
'-M', options.android_manifest,
|
||||||
'--custom-package', options.R_package,
|
|
||||||
'-M', dummy_manifest,
|
|
||||||
'-S', options.res_dir,
|
'-S', options.res_dir,
|
||||||
'--auto-add-overlay',
|
'--auto-add-overlay',
|
||||||
'-I', android_jar,
|
'-I', android_jar,
|
||||||
@ -72,6 +73,10 @@ def main():
|
|||||||
# If strings.xml was generated from a grd file, it will be in out_res_dir.
|
# If strings.xml was generated from a grd file, it will be in out_res_dir.
|
||||||
if os.path.isdir(options.out_res_dir):
|
if os.path.isdir(options.out_res_dir):
|
||||||
package_command += ['-S', options.out_res_dir]
|
package_command += ['-S', options.out_res_dir]
|
||||||
|
if options.non_constant_id:
|
||||||
|
package_command.append('--non-constant-id')
|
||||||
|
if options.custom_package:
|
||||||
|
package_command += ['--custom-package', options.custom_package]
|
||||||
subprocess.check_call(package_command)
|
subprocess.check_call(package_command)
|
||||||
|
|
||||||
# Crunch image resources. This shrinks png files and is necessary for 9-patch
|
# Crunch image resources. This shrinks png files and is necessary for 9-patch
|
||||||
@ -81,6 +86,8 @@ def main():
|
|||||||
'-S', options.res_dir,
|
'-S', options.res_dir,
|
||||||
'-C', options.out_res_dir])
|
'-C', options.out_res_dir])
|
||||||
|
|
||||||
|
build_utils.Touch(options.stamp)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -47,16 +47,16 @@
|
|||||||
'<(DEPTH)/build/build_output_dirs_android.gyp:build_output_dirs'
|
'<(DEPTH)/build/build_output_dirs_android.gyp:build_output_dirs'
|
||||||
],
|
],
|
||||||
'variables': {
|
'variables': {
|
||||||
'input_jars_paths': [ '<(android_sdk_jar)' ],
|
'android_jar': '<(android_sdk)/android.jar',
|
||||||
|
'input_jars_paths': [ '<(android_jar)' ],
|
||||||
'additional_src_dirs': [],
|
'additional_src_dirs': [],
|
||||||
'javac_includes': [],
|
'javac_includes': [],
|
||||||
'jar_name': '<(_target_name).jar',
|
'jar_name': '<(_target_name).jar',
|
||||||
'jar_path': '<(PRODUCT_DIR)/lib.java/<(jar_name)',
|
'jar_path': '<(PRODUCT_DIR)/lib.java/<(jar_name)',
|
||||||
'excluded_classes': [ '*/R.class', '*/R##*.class' ],
|
'excluded_classes': [ '*/R.class', '*/R##*.class' ],
|
||||||
'additional_input_paths': ['>@(additional_R_files)'],
|
'additional_input_paths': [],
|
||||||
'generated_src_dirs': ['>@(generated_R_dirs)'],
|
'generated_src_dirs': ['>@(generated_R_dirs)'],
|
||||||
'generated_R_dirs': [],
|
'generated_R_dirs': [],
|
||||||
'additional_R_files': [],
|
|
||||||
'has_java_resources%': 0,
|
'has_java_resources%': 0,
|
||||||
'java_strings_grd%': '',
|
'java_strings_grd%': '',
|
||||||
'intermediate_dir': '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)',
|
'intermediate_dir': '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)',
|
||||||
@ -76,19 +76,20 @@
|
|||||||
'res_dir': '<(java_in_dir)/res',
|
'res_dir': '<(java_in_dir)/res',
|
||||||
'out_res_dir': '<(intermediate_dir)/res',
|
'out_res_dir': '<(intermediate_dir)/res',
|
||||||
'R_dir': '<(intermediate_dir)/java_R',
|
'R_dir': '<(intermediate_dir)/java_R',
|
||||||
'R_file': '<(R_dir)/<(R_package_relpath)/R.java',
|
|
||||||
'R_text_file': '<(R_dir)/R.txt',
|
'R_text_file': '<(R_dir)/R.txt',
|
||||||
|
'R_stamp': '<(intermediate_dir)/resources.stamp',
|
||||||
'generated_src_dirs': ['<(R_dir)'],
|
'generated_src_dirs': ['<(R_dir)'],
|
||||||
'additional_input_paths': ['<(R_file)'],
|
'additional_input_paths': ['<(R_stamp)'],
|
||||||
# grit_grd_file is used by grit_action.gypi, included below.
|
# grit_grd_file is used by grit_action.gypi, included below.
|
||||||
'grit_grd_file': '<(java_in_dir)/strings/<(java_strings_grd)',
|
'grit_grd_file': '<(java_in_dir)/strings/<(java_strings_grd)',
|
||||||
|
'resource_input_paths': [],
|
||||||
},
|
},
|
||||||
'all_dependent_settings': {
|
'all_dependent_settings': {
|
||||||
'variables': {
|
'variables': {
|
||||||
# Dependent jars include this target's R.java file via
|
# Dependent jars include this target's R.java file via
|
||||||
# generated_R_dirs and additional_R_files.
|
# generated_R_dirs and additional_R_files.
|
||||||
'generated_R_dirs': ['<(R_dir)'],
|
'generated_R_dirs': ['<(R_dir)'],
|
||||||
'additional_R_files': ['<(R_file)'],
|
'additional_input_paths': ['<(R_stamp)'],
|
||||||
'additional_R_text_files': ['<(R_text_file)'],
|
'additional_R_text_files': ['<(R_text_file)'],
|
||||||
|
|
||||||
# Dependent APKs include this target's resources via
|
# Dependent APKs include this target's resources via
|
||||||
@ -99,6 +100,14 @@
|
|||||||
},
|
},
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['java_strings_grd != ""', {
|
['java_strings_grd != ""', {
|
||||||
|
'variables': {
|
||||||
|
'resource_input_paths': [
|
||||||
|
# TODO(newt): replace this with .../values/strings.xml once
|
||||||
|
# the English strings.xml is generated as well? That would be
|
||||||
|
# simpler and faster and should be equivalent.
|
||||||
|
'<!@pymod_do_main(grit_info <@(grit_defines) --outputs "<(out_res_dir)" <(grit_grd_file))',
|
||||||
|
],
|
||||||
|
},
|
||||||
'actions': [
|
'actions': [
|
||||||
{
|
{
|
||||||
'action_name': 'generate_localized_strings_xml',
|
'action_name': 'generate_localized_strings_xml',
|
||||||
@ -117,36 +126,34 @@
|
|||||||
{
|
{
|
||||||
'action_name': 'process_resources',
|
'action_name': 'process_resources',
|
||||||
'message': 'processing resources for <(_target_name)',
|
'message': 'processing resources for <(_target_name)',
|
||||||
'conditions': [
|
'variables': {
|
||||||
['java_strings_grd != ""', {
|
'android_manifest': '<(DEPTH)/build/android/AndroidManifest.xml',
|
||||||
'inputs': [
|
},
|
||||||
# TODO(newt): replace this with .../values/strings.xml once
|
|
||||||
# the English strings.xml is generated as well? That would be
|
|
||||||
# simpler and faster and should be equivalent.
|
|
||||||
'<!@pymod_do_main(grit_info <@(grit_defines) --outputs "<(out_res_dir)" <(grit_grd_file))',
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
],
|
|
||||||
'inputs': [
|
'inputs': [
|
||||||
|
'<(DEPTH)/build/android/pylib/build_utils.py',
|
||||||
'<(DEPTH)/build/android/process_resources.py',
|
'<(DEPTH)/build/android/process_resources.py',
|
||||||
'<!@(find <(res_dir) -type f)',
|
'<!@(find <(res_dir) -type f)',
|
||||||
|
'<@(resource_input_paths)',
|
||||||
],
|
],
|
||||||
'outputs': [
|
'outputs': [
|
||||||
'<(R_file)',
|
'<(R_stamp)',
|
||||||
],
|
],
|
||||||
'action': [
|
'action': [
|
||||||
'<(DEPTH)/build/android/process_resources.py',
|
'<(DEPTH)/build/android/process_resources.py',
|
||||||
'--android-sdk', '<(android_sdk)',
|
'--android-sdk', '<(android_sdk)',
|
||||||
'--android-sdk-tools', '<(android_sdk_tools)',
|
'--android-sdk-tools', '<(android_sdk_tools)',
|
||||||
'--R-package', '<(R_package)',
|
|
||||||
'--R-dir', '<(R_dir)',
|
'--R-dir', '<(R_dir)',
|
||||||
'--res-dir', '<(res_dir)',
|
'--res-dir', '<(res_dir)',
|
||||||
'--out-res-dir', '<(out_res_dir)',
|
'--out-res-dir', '<(out_res_dir)',
|
||||||
|
'--android-manifest', '<(android_manifest)',
|
||||||
|
'--non-constant-id',
|
||||||
|
'--custom-package', '<(R_package)',
|
||||||
|
'--stamp', '<(R_stamp)',
|
||||||
|
|
||||||
# Add list of inputs to the command line, so if inputs change
|
# Add list of inputs to the command line, so if inputs change
|
||||||
# (e.g. if a resource if removed), the command will be re-run.
|
# (e.g. if a resource if removed), the command will be re-run.
|
||||||
# TODO(newt): remove this once crbug.com/177552 is fixed in ninja.
|
# TODO(newt): remove this once crbug.com/177552 is fixed in ninja.
|
||||||
'--ignore', '>(_inputs)',
|
'--ignore=>!(echo \'>(_inputs)\' | md5sum)',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
Reference in New Issue
Block a user