Commit 8dbd4fb5 authored by agrieve's avatar agrieve Committed by Commit bot

Make android_aar_prebuilt() aware of remaining features

* Fail if it finds a non-trivial AndroidManifest.xml
* Fail if it finds any .so files
* Fail if it finds any assets
* Support proguard.txt

This also tweaks the naming of the sub-jar targets to give them better
target names (which show up in .jar names).

TBR=bshe
BUG=640836

Review-Url: https://codereview.chromium.org/2309643002
Cr-Commit-Position: refs/heads/master@{#417160}
parent 64a891af
...@@ -8,8 +8,11 @@ ...@@ -8,8 +8,11 @@
import argparse import argparse
import os import os
import posixpath
import re
import shutil import shutil
import sys import sys
from xml.etree import ElementTree
import zipfile import zipfile
from util import build_utils from util import build_utils
...@@ -19,6 +22,22 @@ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ...@@ -19,6 +22,22 @@ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__),
import gn_helpers import gn_helpers
def _IsManifestEmpty(manifest_str):
"""Returns whether the given manifest has merge-worthy elements.
E.g.: <activity>, <service>, etc.
"""
doc = ElementTree.fromstring(manifest_str)
for node in doc:
if node.tag == 'application':
if len(node):
return False
elif node.tag != 'uses-sdk':
return False
return True
def main(): def main():
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--input-file', parser.add_argument('--input-file',
...@@ -50,14 +69,39 @@ def main(): ...@@ -50,14 +69,39 @@ def main():
if args.list: if args.list:
data = {} data = {}
data['aidl'] = []
data['assets'] = []
data['resources'] = [] data['resources'] = []
data['jars'] = [] data['subjars'] = []
data['subjar_tuples'] = []
data['has_classes_jar'] = False
data['has_proguard_flags'] = False
data['has_native_libraries'] = False
with zipfile.ZipFile(aar_file) as z: with zipfile.ZipFile(aar_file) as z:
data['is_manifest_empty'] = (
_IsManifestEmpty(z.read('AndroidManifest.xml')))
for name in z.namelist(): for name in z.namelist():
if name.startswith('res/') and not name.endswith('/'): if name.endswith('/'):
continue
if name.startswith('aidl/'):
data['aidl'].append(name)
elif name.startswith('res/'):
data['resources'].append(name) data['resources'].append(name)
if name.endswith('.jar'): elif name.startswith('libs/') and name.endswith('.jar'):
data['jars'].append(name) label = posixpath.basename(name)[:-4]
label = re.sub(r'[^a-zA-Z0-9._]', '_', label)
data['subjars'].append(name)
data['subjar_tuples'].append([label, name])
elif name.startswith('assets/'):
data['assets'].append(name)
elif name.startswith('jni/'):
data['has_native_libraries'] = True
elif name == 'classes.jar':
data['has_classes_jar'] = True
elif name == 'proguard.txt':
data['has_proguard_flags'] = True
print gn_helpers.ToGNString(data) print gn_helpers.ToGNString(data)
......
...@@ -2593,6 +2593,10 @@ if (enable_java_templates) { ...@@ -2593,6 +2593,10 @@ if (enable_java_templates) {
# aar_path: Path to the AAR. # aar_path: Path to the AAR.
# proguard_configs: List of proguard configs to use in final apk step for # proguard_configs: List of proguard configs to use in final apk step for
# any apk that depends on this library. # any apk that depends on this library.
# ignore_aidl: Whether to ignore .aidl files found with the .aar.
# ignore_assets: Whether to ignore assets found in the .aar.
# ignore_manifest: Whether to ignore merging of AndroidManifest.xml.
# ignore_native_libraries: Whether to ignore .so files found in the .aar.
# TODO(jbudorick@): remove this arguments after crbug.com/522043 is fixed. # TODO(jbudorick@): remove this arguments after crbug.com/522043 is fixed.
# requires_android: Whether this target can only be used for compiling Android related targets. # requires_android: Whether this target can only be used for compiling Android related targets.
# #
...@@ -2601,9 +2605,14 @@ if (enable_java_templates) { ...@@ -2601,9 +2605,14 @@ if (enable_java_templates) {
# aar_path = "foo.aar" # aar_path = "foo.aar"
# } # }
template("android_aar_prebuilt") { template("android_aar_prebuilt") {
assert(defined(invoker.aar_path))
_output_path = "${target_gen_dir}/${target_name}" _output_path = "${target_gen_dir}/${target_name}"
_unpack_target_name = "${target_name}__unpack_aar" _unpack_target_name = "${target_name}__unpack_aar"
_ignore_aidl = defined(invoker.ignore_aidl) && invoker.ignore_aidl
_ignore_assets = defined(invoker.ignore_assets) && invoker.ignore_assets
_ignore_manifest =
defined(invoker.ignore_manifest) && invoker.ignore_manifest
_ignore_native_libraries = defined(invoker.ignore_native_libraries) &&
invoker.ignore_native_libraries
# Scan the AAR file and determine the resources and jar files. # Scan the AAR file and determine the resources and jar files.
# Some libraries might not have resources; others might have two jars. # Some libraries might not have resources; others might have two jars.
...@@ -2616,6 +2625,24 @@ if (enable_java_templates) { ...@@ -2616,6 +2625,24 @@ if (enable_java_templates) {
], ],
"scope") "scope")
assert(_ignore_aidl || _scanned_files.aidl == [],
"android_aar_prebuilt() aidl not yet supported." +
" Implement or use ignore_aidl = true." +
" 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(_ignore_native_libraries || !_scanned_files.has_native_libraries,
"android_aar_prebuilt() with .so files is not supported." +
" Use ignore_native_libraries = true to silence this error.")
assert(_ignore_manifest || _scanned_files.is_manifest_empty,
"android_aar_prebuilt() manifest merging not yet supported and" +
" non-trivial AndroidManifest.xml detected." +
" Implement or use ignore_manifest = true." +
" http://crbug.com/643967")
assert(_scanned_files.has_classes_jar || _scanned_files.subjars == [])
action(_unpack_target_name) { action(_unpack_target_name) {
script = "//build/android/gyp/aar.py" # Unzips the AAR script = "//build/android/gyp/aar.py" # Unzips the AAR
args = [ args = [
...@@ -2638,19 +2665,20 @@ if (enable_java_templates) { ...@@ -2638,19 +2665,20 @@ if (enable_java_templates) {
rebase_path(_scanned_files.resources, "", _output_path), rebase_path(_scanned_files.resources, "", _output_path),
"abspath") "abspath")
} }
if (defined(_scanned_files.jars)) { if (_scanned_files.has_classes_jar) {
outputs += outputs += [ "${_output_path}/classes.jar" ]
get_path_info(rebase_path(_scanned_files.jars, "", _output_path), }
"abspath") outputs +=
get_path_info(rebase_path(_scanned_files.subjars, "", _output_path),
"abspath")
if (_scanned_files.has_proguard_flags) {
outputs += [ "${_output_path}/proguard.txt" ]
} }
} }
_resource_targets = []
# Create the android_resources target for resources. # Create the android_resources target for resources.
if (_scanned_files.resources != []) { if (_scanned_files.resources != []) {
_res_target_name = "${target_name}__res" _res_target_name = "${target_name}__res"
_resource_targets += [ ":$_res_target_name" ]
android_resources(_res_target_name) { android_resources(_res_target_name) {
forward_variables_from(invoker, [ "deps" ]) forward_variables_from(invoker, [ "deps" ])
if (!defined(deps)) { if (!defined(deps)) {
...@@ -2667,14 +2695,32 @@ if (enable_java_templates) { ...@@ -2667,14 +2695,32 @@ if (enable_java_templates) {
} }
} }
# Create android_java_prebuilt targets for jar files. # Create android_java_prebuilt target for extra jars within jars/.
_jar_targets = [] _subjar_targets = []
_counter = 0 foreach(_tuple, _scanned_files.subjar_tuples) {
foreach(jar, _scanned_files.jars) { _current_target = "${target_name}__subjar_${_tuple[0]}"
_counter += 1 _subjar_targets += [ ":$_current_target" ]
_current_target = "${target_name}__jar_$_counter"
_jar_targets += [ ":$_current_target" ]
java_prebuilt(_current_target) { java_prebuilt(_current_target) {
forward_variables_from(invoker,
[
"jar_excluded_patterns",
"requires_android",
])
deps = [
":$_unpack_target_name",
]
if (!defined(requires_android)) {
requires_android = true
}
supports_android = true
jar_path = "$_output_path/${_tuple[1]}"
}
}
# Create android_java_prebuilt target for classes.jar.
if (_scanned_files.has_classes_jar) {
_jar_target_name = "${target_name}__classes"
java_prebuilt(_jar_target_name) {
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
"deps", "deps",
...@@ -2686,17 +2732,38 @@ if (enable_java_templates) { ...@@ -2686,17 +2732,38 @@ if (enable_java_templates) {
if (!defined(deps)) { if (!defined(deps)) {
deps = [] deps = []
} }
deps += _resource_targets + [ ":$_unpack_target_name" ] deps += _subjar_targets + [ ":$_unpack_target_name" ]
if (defined(_res_target_name)) {
deps += [ ":$_res_target_name" ]
}
if (!defined(requires_android)) { if (!defined(requires_android)) {
requires_android = true requires_android = true
} }
supports_android = true supports_android = true
jar_path = "${_output_path}/$jar" jar_path = "$_output_path/classes.jar"
if (_scanned_files.has_proguard_flags) {
if (!defined(proguard_configs)) {
proguard_configs = []
}
proguard_configs += [ "$_output_path/proguard.txt" ]
}
} }
} }
java_group(target_name) { java_group(target_name) {
deps = _resource_targets + _jar_targets deps = []
if (defined(_jar_target_name)) {
deps += [ ":$_jar_target_name" ]
# Although subjars are meant to be private, we add them as deps here
# because in practice they seem to contain classes required to be in the
# classpath.
deps += _subjar_targets
}
if (defined(_res_target_name)) {
deps += [ ":$_res_target_name" ]
}
} }
} }
} }
...@@ -65,6 +65,7 @@ android_java_prebuilt("android_support_annotations_java") { ...@@ -65,6 +65,7 @@ android_java_prebuilt("android_support_annotations_java") {
android_aar_prebuilt("android_support_v4_java") { android_aar_prebuilt("android_support_v4_java") {
lib_name = "support-v4" lib_name = "support-v4"
aar_path = "$lib_path/$lib_name/$lib_version/$lib_name-$lib_version.aar" aar_path = "$lib_path/$lib_name/$lib_version/$lib_name-$lib_version.aar"
ignore_aidl = true # We don't appear to need these currently.
} }
android_aar_prebuilt("android_support_v13_java") { android_aar_prebuilt("android_support_v13_java") {
......
...@@ -17,6 +17,8 @@ android_aar_prebuilt("gvr_common_java") { ...@@ -17,6 +17,8 @@ android_aar_prebuilt("gvr_common_java") {
android_aar_prebuilt("gvr_base_java") { android_aar_prebuilt("gvr_base_java") {
aar_path = "src/libraries/base/base.aar" aar_path = "src/libraries/base/base.aar"
proguard_configs = [ "proguard/base.flags" ] proguard_configs = [ "proguard/base.flags" ]
ignore_manifest = true # Ignored because manifest merging is not supported (http://crbug.com/643967)
ignore_native_libraries = true
} }
android_aar_prebuilt("gvr_controller_java") { android_aar_prebuilt("gvr_controller_java") {
......
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