Commit 5111ff4b authored by David 'Digit' Turner's avatar David 'Digit' Turner Committed by Commit Bot

android: Add android_generated_resources GN template

This CL adds a new GN template to specify a set of Android
resource files generated by another target's action. The
generated files must be stored by the action into a zip
archive, with a layout similar to standard Android res/ folder
(but note that the archive should not have a top-level res/
directory).

+ Update java_strings_grd(), java_strings_grd_prebuilt()
  and jinja_template_resources() to use it.

BUG=846633
R=agrieve@chromium.org, estevenson@chromium.org, jbudorick@chromium.org

Change-Id: Ibb0ec100d0922ac1ec3155f4577f40136f233b0b
Reviewed-on: https://chromium-review.googlesource.com/1104355
Commit-Queue: David Turner <digit@chromium.org>
Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Reviewed-by: default avataragrieve <agrieve@chromium.org>
Reviewed-by: default avatarEric Stevenson <estevenson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568402}
parent 5ddb3dc6
...@@ -643,6 +643,68 @@ if (enable_java_templates) { ...@@ -643,6 +643,68 @@ if (enable_java_templates) {
} }
} }
# Declare a target for a set of Android resources generated at build
# time and stored in a single zip archive. The content of the archive
# should match the layout of a regular Android res/ folder (but the
# archive should not include a top-level res/ directory).
#
# Note that there is no associated .srcjar, R.txt or package name
# associated with this target.
#
# Variables:
# generated_resources_zip: Generated zip archive path.
# generating_target_name: Name of the target generating
# generated_resources_zip. This rule will check that it is part
# of its outputs.
# deps: Specifies the dependencies of this target. Any Android resources
# listed here will be also be included *after* this one when compiling
# all resources for a final apk or junit binary. This is useful to
# ensure that the resources of the current target override those of the
# dependency as well (and would not work if you have these deps to the
# generating target's dependencies).
#
# Example
# _zip_archive = "$target_gen_dir/${target_name}.resources_zip"
#
# action("my_resources__create_zip") {
# _depfile = "$target_gen_dir/${target_name}.d"
# script = "//build/path/to/create_my_resources_zip.py"
# args = [
# "--depfile", rebase_path(_depfile, root_build_dir),
# "--output-zip", rebase_path(_zip_archive, root_build_dir),
# ]
# inputs = []
# outputs = _zip_archive
# depfile = _depfile
# }
#
# android_generated_resources("my_resources") {
# generated_resources_zip = _zip_archive
# generating_target_name = ":my_resources__create_zip"
# }
#
template("android_generated_resources") {
forward_variables_from(invoker, [ "testonly" ])
_build_config = "$target_gen_dir/${target_name}.build_config"
write_build_config("${target_name}__build_config") {
build_config = _build_config
resources_zip = invoker.generated_resources_zip
type = "android_resources"
if (defined(invoker.deps)) {
possible_config_deps = invoker.deps
}
}
group(target_name) {
public_deps = [
":${target_name}__build_config",
invoker.generating_target_name,
]
}
}
# Declare a target for processing Android resources as Jinja templates. # Declare a target for processing Android resources as Jinja templates.
# #
# This takes an Android resource directory where each resource is a Jinja # This takes an Android resource directory where each resource is a Jinja
...@@ -671,18 +733,10 @@ if (enable_java_templates) { ...@@ -671,18 +733,10 @@ if (enable_java_templates) {
# directory or they will not be available to tester bots. # directory or they will not be available to tester bots.
_resources_zip_rebased_path = rebase_path(target_gen_dir, root_gen_dir) _resources_zip_rebased_path = rebase_path(target_gen_dir, root_gen_dir)
_resources_zip = "${root_out_dir}/resource_zips/${_resources_zip_rebased_path}/${target_name}.resources.zip" _resources_zip = "${root_out_dir}/resource_zips/${_resources_zip_rebased_path}/${target_name}.resources.zip"
_build_config = "$target_gen_dir/$target_name.build_config"
write_build_config("${target_name}__build_config") { _generating_target_name = "${target_name}__template"
build_config = _build_config
resources_zip = _resources_zip
type = "android_resources"
if (defined(invoker.deps)) {
possible_config_deps = invoker.deps
}
}
action("${target_name}__template") { action(_generating_target_name) {
forward_variables_from(invoker, [ "deps" ]) forward_variables_from(invoker, [ "deps" ])
inputs = invoker.resources inputs = invoker.resources
script = "//build/android/gyp/jinja_template.py" script = "//build/android/gyp/jinja_template.py"
...@@ -708,11 +762,10 @@ if (enable_java_templates) { ...@@ -708,11 +762,10 @@ if (enable_java_templates) {
} }
} }
group(target_name) { android_generated_resources(target_name) {
public_deps = [ forward_variables_from(invoker, [ "deps" ])
":${target_name}__build_config", generating_target_name = ":$_generating_target_name"
":${target_name}__template", generated_resources_zip = _resources_zip
]
} }
} }
...@@ -988,13 +1041,6 @@ if (enable_java_templates) { ...@@ -988,13 +1041,6 @@ if (enable_java_templates) {
# directory or they will not be available to tester bots. # directory or they will not be available to tester bots.
_resources_zip_rebased_path = rebase_path(target_gen_dir, root_gen_dir) _resources_zip_rebased_path = rebase_path(target_gen_dir, root_gen_dir)
_resources_zip = "${root_out_dir}/resource_zips/${_resources_zip_rebased_path}/${target_name}.resources.zip" _resources_zip = "${root_out_dir}/resource_zips/${_resources_zip_rebased_path}/${target_name}.resources.zip"
_build_config = "$target_gen_dir/$target_name.build_config"
write_build_config("${target_name}__build_config") {
type = "android_resources"
build_config = _build_config
resources_zip = _resources_zip
}
_grit_target_name = "${target_name}__grit" _grit_target_name = "${target_name}__grit"
_grit_output_dir = "$target_gen_dir/${target_name}_grit_output" _grit_output_dir = "$target_gen_dir/${target_name}_grit_output"
...@@ -1015,7 +1061,9 @@ if (enable_java_templates) { ...@@ -1015,7 +1061,9 @@ if (enable_java_templates) {
outputs = invoker.outputs outputs = invoker.outputs
} }
zip(target_name) { _zip_target_name = "${target_name}__zip"
zip(_zip_target_name) {
base_dir = _grit_output_dir base_dir = _grit_output_dir
# This needs to get outputs from grit's internal target, not the final # This needs to get outputs from grit's internal target, not the final
...@@ -1026,6 +1074,11 @@ if (enable_java_templates) { ...@@ -1026,6 +1074,11 @@ if (enable_java_templates) {
":$_grit_target_name", ":$_grit_target_name",
] ]
} }
android_generated_resources(target_name) {
generating_target_name = ":$_zip_target_name"
generated_resources_zip = _resources_zip
}
} }
# Declare a target that packages strings.xml generated from a grd file. # Declare a target that packages strings.xml generated from a grd file.
...@@ -1051,28 +1104,24 @@ if (enable_java_templates) { ...@@ -1051,28 +1104,24 @@ if (enable_java_templates) {
# directory or they will not be available to tester bots. # directory or they will not be available to tester bots.
_resources_zip_rebased_path = rebase_path(target_gen_dir, root_gen_dir) _resources_zip_rebased_path = rebase_path(target_gen_dir, root_gen_dir)
_resources_zip = "${root_out_dir}/resource_zips/${_resources_zip_rebased_path}/${target_name}.resources.zip" _resources_zip = "${root_out_dir}/resource_zips/${_resources_zip_rebased_path}/${target_name}.resources.zip"
_build_config = "$target_gen_dir/$target_name.build_config"
_build_config_target_name = "${target_name}__build_config"
write_build_config(_build_config_target_name) { _zip_target_name = "${target_name}__zip"
type = "android_resources"
build_config = _build_config
resources_zip = _resources_zip
}
zip(target_name) { zip(_zip_target_name) {
forward_variables_from(invoker, [ "visibility" ]) forward_variables_from(invoker, [ "visibility" ])
base_dir = invoker.grit_output_dir base_dir = invoker.grit_output_dir
inputs = rebase_path(invoker.generated_files, ".", base_dir) inputs = rebase_path(invoker.generated_files, ".", base_dir)
output = _resources_zip output = _resources_zip
deps = [
":$_build_config_target_name",
]
if (defined(invoker.deps)) { if (defined(invoker.deps)) {
deps += invoker.deps deps = invoker.deps
} }
} }
android_generated_resources(target_name) {
generating_target_name = ":$_zip_target_name"
generated_resources_zip = _resources_zip
}
} }
# Declare a Java executable target # Declare a Java executable target
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment