Commit 3f954b32 authored by Brandon Mousseau's avatar Brandon Mousseau Committed by Commit Bot

Add asset merging support to android_aar_prebuilt

This change extends android_aar_prebuilt to support including any assets
in the aar file in the output. Currently, if the source aar file
contains any files in the assets subdirectory, the target must define
the ignore_assets flag. This change now optionally allows the user to
instead supply the extract_assets flag so that the assets will be copied
to the output instead.

If assets are included in the source aar, then either ignore_assets or
extract_assets, but not both, must be set.

Assets will be copied to the output target with the same directory
structure as the input aar file.

Bug: 643966
Change-Id: Ibf66543fd9e9dc8db7221234b82c1d860f7f2724
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2350340
Auto-Submit: Brandon Mousseau <bmoose@google.com>
Commit-Queue: Brandon Mousseau <bmoose@google.com>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797544}
parent c3093147
...@@ -4101,6 +4101,9 @@ if (enable_java_templates) { ...@@ -4101,6 +4101,9 @@ if (enable_java_templates) {
# ignore_proguard_configs: Whether to ignore proguard configs. # ignore_proguard_configs: Whether to ignore proguard configs.
# strip_resources: Whether to ignore android resources found in the .aar. # strip_resources: Whether to ignore android resources found in the .aar.
# custom_package: Java package for generated R.java files. # custom_package: Java package for generated R.java files.
# extract_assets: Whether to extract and include assets found in the .aar.
# If the file contains assets, either extract_assets or ignore_assets
# must be set.
# extract_native_libraries: Whether to extract .so files found in the .aar. # extract_native_libraries: Whether to extract .so files found in the .aar.
# If the file contains .so, either extract_native_libraries or # If the file contains .so, either extract_native_libraries or
# ignore_native_libraries must be set. # ignore_native_libraries must be set.
...@@ -4128,6 +4131,7 @@ if (enable_java_templates) { ...@@ -4128,6 +4131,7 @@ if (enable_java_templates) {
_unpack_target_name = "${_target_name_without_java_or_junit}__unpack_aar" _unpack_target_name = "${_target_name_without_java_or_junit}__unpack_aar"
_ignore_aidl = defined(invoker.ignore_aidl) && invoker.ignore_aidl _ignore_aidl = defined(invoker.ignore_aidl) && invoker.ignore_aidl
_ignore_assets = defined(invoker.ignore_assets) && invoker.ignore_assets _ignore_assets = defined(invoker.ignore_assets) && invoker.ignore_assets
_extract_assets = defined(invoker.extract_assets) && invoker.extract_assets
_ignore_manifest = _ignore_manifest =
defined(invoker.ignore_manifest) && invoker.ignore_manifest defined(invoker.ignore_manifest) && invoker.ignore_manifest
_ignore_native_libraries = defined(invoker.ignore_native_libraries) && _ignore_native_libraries = defined(invoker.ignore_native_libraries) &&
...@@ -4158,14 +4162,12 @@ if (enable_java_templates) { ...@@ -4158,14 +4162,12 @@ if (enable_java_templates) {
# rm -r out/tmp # rm -r out/tmp
_scanned_files = read_file(_info_path, "scope") _scanned_files = read_file(_info_path, "scope")
_contains_scanned_assets = _scanned_files.assets != []
assert(_ignore_aidl || _scanned_files.aidl == [], assert(_ignore_aidl || _scanned_files.aidl == [],
"android_aar_prebuilt() aidl not yet supported." + "android_aar_prebuilt() aidl not yet supported." +
" Implement or use ignore_aidl = true." + " Implement or use ignore_aidl = true." +
" http://crbug.com/644439") " http://crbug.com/644439")
assert(_ignore_assets || _scanned_files.assets == [],
"android_aar_prebuilt() assets not yet supported." +
" Implement or use ignore_assets = true." +
" http://crbug.com/643966")
assert( assert(
!_scanned_files.has_native_libraries || !_scanned_files.has_native_libraries ||
(_ignore_native_libraries || _extract_native_libraries), (_ignore_native_libraries || _extract_native_libraries),
...@@ -4174,6 +4176,11 @@ if (enable_java_templates) { ...@@ -4174,6 +4176,11 @@ if (enable_java_templates) {
assert( assert(
!(_ignore_native_libraries && _extract_native_libraries), !(_ignore_native_libraries && _extract_native_libraries),
"ignore_native_libraries and extract_native_libraries cannot both be set.") "ignore_native_libraries and extract_native_libraries cannot both be set.")
assert(!_contains_scanned_assets || (_ignore_assets || _extract_assets),
"android_aar_prebuilt() contains asset files." +
" Please set ignore_assets or extract_assets.")
assert(!(_ignore_assets && _extract_assets),
"ignore_assets and extract_assets cannot both be set.")
assert(!_scanned_files.has_native_libraries || assert(!_scanned_files.has_native_libraries ||
_scanned_files.native_libraries != []) _scanned_files.native_libraries != [])
assert(_scanned_files.has_classes_jar || _scanned_files.subjars == []) assert(_scanned_files.has_classes_jar || _scanned_files.subjars == [])
...@@ -4231,6 +4238,11 @@ if (enable_java_templates) { ...@@ -4231,6 +4238,11 @@ if (enable_java_templates) {
rebase_path(_scanned_files.native_libraries, "", _output_path), rebase_path(_scanned_files.native_libraries, "", _output_path),
"abspath") "abspath")
} }
if (_extract_assets && _contains_scanned_assets) {
outputs +=
get_path_info(rebase_path(_scanned_files.assets, "", _output_path),
"abspath")
}
} }
_has_unignored_resources = _has_unignored_resources =
...@@ -4284,6 +4296,26 @@ if (enable_java_templates) { ...@@ -4284,6 +4296,26 @@ if (enable_java_templates) {
not_needed(invoker, [ "strip_drawables" ]) not_needed(invoker, [ "strip_drawables" ])
} }
_should_extract_assets = _extract_assets && _contains_scanned_assets
# Create the android_assets target for assets
if (_should_extract_assets) {
_assets_target_name = "${target_name}__assets"
android_assets(_assets_target_name) {
forward_variables_from(invoker, [ "testonly" ])
renaming_sources = []
renaming_destinations = []
foreach(_asset_file, _scanned_files.assets) {
_original_path =
get_path_info(rebase_path(_asset_file, "", _output_path),
"abspath")
_updated_path = string_replace(_asset_file, "assets/", "", 1)
renaming_sources += [ _original_path ]
renaming_destinations += [ _updated_path ]
}
}
}
# Create android_java_prebuilt target for classes.jar. # Create android_java_prebuilt target for classes.jar.
if (_scanned_files.has_classes_jar) { if (_scanned_files.has_classes_jar) {
_java_library_vars = [ _java_library_vars = [
...@@ -4373,6 +4405,9 @@ if (enable_java_templates) { ...@@ -4373,6 +4405,9 @@ if (enable_java_templates) {
if (defined(_res_target_name)) { if (defined(_res_target_name)) {
deps += [ ":$_res_target_name" ] deps += [ ":$_res_target_name" ]
} }
if (defined(_assets_target_name)) {
deps += [ ":$_assets_target_name" ]
}
} }
} }
......
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