Commit 52f78b16 authored by David 'Digit' Turner's avatar David 'Digit' Turner Committed by Commit Bot

android: build: Add extra native libraries to APK .build_config

This CL augments the .build_config file of APK with a new
entry at native['extra_shared_libraries'] that list extra
shared libraries that can be packaged into the final APK
(but which may be processed differently from the list
in native['libraries'].

This entry will be used later when building an App Bundle
module that depends on the APK's .build_config.

This is required because the full list of native libraries
is determined by a set of complex rules performed by the
android_apk() rule, which would be difficult to replicate
in a different one without lots of code duplication, or
making android_apk() even more complicated that it currently
is.

+ Add a flag in the APK's .build_config file telling it whether
  the libraries are stored uncompressed (and page-aligned)
  in the APK. This will allow reproducing the same
  compression setting when generating the bundle later.

BUG=820459
R=agrieve@chromium.org, estevenson@chromium.org, yfriedman@chromium.org


Change-Id: I7a4fa94e68370dbc167c1f9729d152f4692fdaff
Reviewed-on: https://chromium-review.googlesource.com/1047865
Commit-Queue: David Turner <digit@chromium.org>
Reviewed-by: default avataragrieve <agrieve@chromium.org>
Reviewed-by: default avatarEric Stevenson <estevenson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561464}
parent 54209cdb
...@@ -76,9 +76,10 @@ def _ParseArgs(args): ...@@ -76,9 +76,10 @@ def _ParseArgs(args):
help='GYP-list of native library placeholders to add ' help='GYP-list of native library placeholders to add '
'for the secondary ABI', 'for the secondary ABI',
default='[]') default='[]')
parser.add_argument('--uncompress-shared-libraries', parser.add_argument('--uncompress-shared-libraries', default='False',
action='store_true', choices=['true', 'True', 'false', 'False'],
help='Uncompress shared libraries') help='Whether to uncompress native shared libraries. Argument must be '
'a boolean value.')
parser.add_argument('--apksigner-path', required=True, parser.add_argument('--apksigner-path', required=True,
help='Path to the apksigner executable.') help='Path to the apksigner executable.')
parser.add_argument('--zipalign-path', required=True, parser.add_argument('--zipalign-path', required=True,
...@@ -107,6 +108,8 @@ def _ParseArgs(args): ...@@ -107,6 +108,8 @@ def _ParseArgs(args):
secondary_libs.extend(build_utils.ParseGnList(gyp_list)) secondary_libs.extend(build_utils.ParseGnList(gyp_list))
options.secondary_native_libs = secondary_libs options.secondary_native_libs = secondary_libs
options.uncompress_shared_libraries = \
options.uncompress_shared_libraries in [ 'true', 'True' ]
if not options.android_abi and (options.native_libs or if not options.android_abi and (options.native_libs or
options.native_lib_placeholders): options.native_lib_placeholders):
...@@ -245,7 +248,7 @@ def main(args): ...@@ -245,7 +248,7 @@ def main(args):
input_strings = [options.android_abi, input_strings = [options.android_abi,
options.native_lib_placeholders, options.native_lib_placeholders,
options.secondary_native_lib_placeholders, options.secondary_native_lib_placeholders,
options.uncompress_shared_libraries] str(options.uncompress_shared_libraries)]
if options.secondary_android_abi: if options.secondary_android_abi:
input_strings.append(options.secondary_android_abi) input_strings.append(options.secondary_android_abi)
......
...@@ -367,6 +367,15 @@ Empty if only a single ABI is supported. ...@@ -367,6 +367,15 @@ Empty if only a single ABI is supported.
* `native['secondary_abi_java_libraries_list']` * `native['secondary_abi_java_libraries_list']`
The same list as `native['second_abi_libraries']` as a Java source string. The same list as `native['second_abi_libraries']` as a Java source string.
* `native['uncompress_shared_libraries']`
A boolean indicating whether native libraries are stored uncompressed in the
APK.
* `native['extra_shared_libraries']`
A list of native libraries to store within the APK, in addition to those from
`native['libraries']`. These correspond to things like the Chromium linker
or instrumentation libraries.
* `assets` * `assets`
A list of assets stored compressed in the APK. Each entry has the format A list of assets stored compressed in the APK. Each entry has the format
`<source-path>:<destination-path>`, where `<source-path>` is relative to `<source-path>:<destination-path>`, where `<source-path>` is relative to
...@@ -820,7 +829,12 @@ def main(argv): ...@@ -820,7 +829,12 @@ def main(argv):
action='store_true', default=False, action='store_true', default=False,
help='Whether relocation packing was applied using the ' help='Whether relocation packing was applied using the '
'Android relocation_packer tool.') 'Android relocation_packer tool.')
parser.add_option('--uncompress-shared-libraries', default=False,
action='store_true',
help='Whether to store native libraries uncompressed')
parser.add_option('--extra-shared-libraries',
help='GN-list of paths to extra native libraries stored '
'in the APK.')
# apk options # apk options
parser.add_option('--apk-path', help='Path to the target\'s apk output.') parser.add_option('--apk-path', help='Path to the target\'s apk output.')
parser.add_option('--incremental-apk-path', parser.add_option('--incremental-apk-path',
...@@ -886,6 +900,11 @@ def main(argv): ...@@ -886,6 +900,11 @@ def main(argv):
raise Exception('--apk-proto-resources can only be used with ' raise Exception('--apk-proto-resources can only be used with '
'--type=android_apk') '--type=android_apk')
if options.uncompress_shared_libraries:
if options.type != 'android_apk':
raise Exception('--uncompressed-shared-libraries can only be used '
'with --type=android_apk')
if options.jar_path and options.supports_android and not options.dex_path: if options.jar_path and options.supports_android and not options.dex_path:
raise Exception('java_library that supports Android requires a dex path.') raise Exception('java_library that supports Android requires a dex path.')
if any(getattr(options, x) for x in jar_path_options): if any(getattr(options, x) for x in jar_path_options):
...@@ -1280,12 +1299,17 @@ def main(argv): ...@@ -1280,12 +1299,17 @@ def main(argv):
secondary_abi_java_libraries_list = _CreateJavaLibrariesList( secondary_abi_java_libraries_list = _CreateJavaLibrariesList(
secondary_abi_library_paths) secondary_abi_library_paths)
extra_shared_libraries = build_utils.ParseGnList(
options.extra_shared_libraries)
all_inputs.extend(runtime_deps_files) all_inputs.extend(runtime_deps_files)
config['native'] = { config['native'] = {
'libraries': library_paths, 'libraries': library_paths,
'secondary_abi_libraries': secondary_abi_library_paths, 'secondary_abi_libraries': secondary_abi_library_paths,
'java_libraries_list': java_libraries_list, 'java_libraries_list': java_libraries_list,
'secondary_abi_java_libraries_list': secondary_abi_java_libraries_list, 'secondary_abi_java_libraries_list': secondary_abi_java_libraries_list,
'uncompress_shared_libraries': options.uncompress_shared_libraries,
'extra_shared_libraries': extra_shared_libraries,
} }
config['assets'], config['uncompressed_assets'], locale_paks = ( config['assets'], config['uncompressed_assets'], locale_paks = (
_MergeAssets(deps.All('android_assets'))) _MergeAssets(deps.All('android_assets')))
......
...@@ -274,6 +274,12 @@ template("write_build_config") { ...@@ -274,6 +274,12 @@ template("write_build_config") {
] ]
} }
if (defined(invoker.extra_shared_libraries)) {
_rebased_extra_shared_libraries =
rebase_path(invoker.extra_shared_libraries, root_build_dir)
args += [ "--extra-shared-libraries=$_rebased_extra_shared_libraries" ]
}
if (defined(invoker.secondary_abi_shared_libraries_runtime_deps_file)) { if (defined(invoker.secondary_abi_shared_libraries_runtime_deps_file)) {
# Don't list secondary_abi_shared_libraries_runtime_deps_file as an # Don't list secondary_abi_shared_libraries_runtime_deps_file as an
# input in order to avoid having to depend on the runtime_deps target. # input in order to avoid having to depend on the runtime_deps target.
...@@ -285,6 +291,11 @@ template("write_build_config") { ...@@ -285,6 +291,11 @@ template("write_build_config") {
] ]
} }
if (defined(invoker.uncompress_shared_libraries) &&
invoker.uncompress_shared_libraries) {
args += [ "--uncompress-shared-libraries" ]
}
if (defined(invoker.apk_path)) { if (defined(invoker.apk_path)) {
_rebased_apk_path = rebase_path(invoker.apk_path, root_build_dir) _rebased_apk_path = rebase_path(invoker.apk_path, root_build_dir)
_rebased_incremental_apk_path = _rebased_incremental_apk_path =
...@@ -2089,6 +2100,8 @@ if (enable_java_templates) { ...@@ -2089,6 +2100,8 @@ if (enable_java_templates) {
# Creates a signed and aligned .apk. # Creates a signed and aligned .apk.
# #
# Variables # Variables
# apk_name: (optional) APK name (without .apk suffix). If provided, will
# be used to generate .info files later used by the supersize tool.
# assets_build_config: Path to android_apk .build_config containing merged # assets_build_config: Path to android_apk .build_config containing merged
# asset information. # asset information.
# deps: Specifies the dependencies of this target. # deps: Specifies the dependencies of this target.
...@@ -2101,11 +2114,17 @@ if (enable_java_templates) { ...@@ -2101,11 +2114,17 @@ if (enable_java_templates) {
# the apk for the secondary ABI (optional). # the apk for the secondary ABI (optional).
# native_libs: List of native libraries. # native_libs: List of native libraries.
# native_libs_filearg: @FileArg() of additionally native libraries. # native_libs_filearg: @FileArg() of additionally native libraries.
# secondary_abi_native_libs: (optional) List of native libraries for
# secondary ABI.
# secondary_abi_native_libs_filearg: (optiona). @FileArg() of additional
# secondary ABI native libs.
# write_asset_list: Adds an extra file to the assets, which contains a list of # write_asset_list: Adds an extra file to the assets, which contains a list of
# all other asset files. # all other asset files.
# keystore_path: Path to keystore to use for signing. # keystore_path: Path to keystore to use for signing.
# keystore_name: Key alias to use. # keystore_name: Key alias to use.
# keystore_password: Keystore password. # keystore_password: Keystore password.
# uncompress_shared_libraries: (optional, default false) Whether to store
# native libraries inside the APK uncompressed and page-aligned.
template("package_apk") { template("package_apk") {
action(target_name) { action(target_name) {
forward_variables_from(invoker, forward_variables_from(invoker,
...@@ -2242,7 +2261,7 @@ if (enable_java_templates) { ...@@ -2242,7 +2261,7 @@ if (enable_java_templates) {
if (defined(invoker.uncompress_shared_libraries) && if (defined(invoker.uncompress_shared_libraries) &&
invoker.uncompress_shared_libraries) { invoker.uncompress_shared_libraries) {
args += [ "--uncompress-shared-libraries" ] args += [ "--uncompress-shared-libraries=True" ]
} }
} }
} }
...@@ -2722,9 +2741,12 @@ if (enable_java_templates) { ...@@ -2722,9 +2741,12 @@ if (enable_java_templates) {
# system does not support compressed relocations in native shared # system does not support compressed relocations in native shared
# libraries. # libraries.
# shared_libraries_runtime_deps_file: Optional. Path to a file listing the # shared_libraries_runtime_deps_file: Optional. Path to a file listing the
# native shared libraries required at runtime by # native shared libraries required at runtime by the APK.
# secondary_abi_shared_libraries_runtime_deps_file: # secondary_abi_shared_libraries_runtime_deps_file:
# # extra_shared_libraries: Optional list of extra native libraries to
# be stored in the APK.
# uncompress_shared_libraries: Optional. True to store native shared
# libraries uncompressed and page-aligned.
# #
# For 'java_binary' and 'junit_binary' targets only. Ignored by others: # For 'java_binary' and 'junit_binary' targets only. Ignored by others:
# #
...@@ -2910,13 +2932,15 @@ if (enable_java_templates) { ...@@ -2910,13 +2932,15 @@ if (enable_java_templates) {
"android_manifest_dep", "android_manifest_dep",
"apk_path", "apk_path",
"apk_under_test", "apk_under_test",
"extra_shared_libraries",
"incremental_allowed", "incremental_allowed",
"incremental_apk_path", "incremental_apk_path",
"incremental_install_json_path", "incremental_install_json_path",
"non_native_packed_relocations", "non_native_packed_relocations",
"proto_resources_path", "proto_resources_path",
"shared_libraries_runtime_deps_file",
"secondary_abi_shared_libraries_runtime_deps_file", "secondary_abi_shared_libraries_runtime_deps_file",
"shared_libraries_runtime_deps_file",
"uncompress_shared_libraries",
]) ])
} }
build_config = _build_config build_config = _build_config
......
...@@ -2232,6 +2232,18 @@ if (enable_java_templates) { ...@@ -2232,6 +2232,18 @@ if (enable_java_templates) {
_srcjar_deps += [ ":${_template_name}__native_libraries_java" ] _srcjar_deps += [ ":${_template_name}__native_libraries_java" ]
} }
_extra_native_libs = _sanitizer_runtimes
_extra_native_libs_deps = []
assert(_extra_native_libs_deps == []) # Mark as used.
if (_native_libs_deps != []) {
if (_use_chromium_linker) {
_extra_native_libs +=
[ "$root_shlib_dir/libchromium_android_linker$shlib_extension" ]
_extra_native_libs_deps +=
[ "//base/android/linker:chromium_android_linker" ]
}
}
if (_generate_buildconfig_java) { if (_generate_buildconfig_java) {
generate_build_config_srcjar("${_template_name}__build_config_java") { generate_build_config_srcjar("${_template_name}__build_config_java") {
forward_variables_from(invoker, [ "firebase_app_id" ]) forward_variables_from(invoker, [ "firebase_app_id" ])
...@@ -2262,6 +2274,7 @@ if (enable_java_templates) { ...@@ -2262,6 +2274,7 @@ if (enable_java_templates) {
"java_files", "java_files",
"no_build_hooks", "no_build_hooks",
"javac_args", "javac_args",
"uncompress_shared_libraries",
]) ])
type = "android_apk" type = "android_apk"
main_target_name = _template_name main_target_name = _template_name
...@@ -2305,6 +2318,8 @@ if (enable_java_templates) { ...@@ -2305,6 +2318,8 @@ if (enable_java_templates) {
secondary_abi_shared_libraries_runtime_deps_file = secondary_abi_shared_libraries_runtime_deps_file =
_secondary_abi_runtime_deps_file _secondary_abi_runtime_deps_file
} }
extra_shared_libraries = _extra_native_libs
} }
# TODO(cjhopman): This is only ever needed to calculate the list of tests to # TODO(cjhopman): This is only ever needed to calculate the list of tests to
...@@ -2463,18 +2478,8 @@ if (enable_java_templates) { ...@@ -2463,18 +2478,8 @@ if (enable_java_templates) {
} }
} }
_extra_native_libs = _sanitizer_runtimes
_extra_native_libs_deps = []
assert(_extra_native_libs_deps == []) # Mark as used.
_extra_native_libs_even_when_incremental = [] _extra_native_libs_even_when_incremental = []
if (_native_libs_deps != []) { if (_native_libs_deps != []) {
if (_use_chromium_linker) {
_extra_native_libs +=
[ "$root_shlib_dir/libchromium_android_linker$shlib_extension" ]
_extra_native_libs_deps +=
[ "//base/android/linker:chromium_android_linker" ]
}
_create_stack_script_rule_name = "${_template_name}__stack_script" _create_stack_script_rule_name = "${_template_name}__stack_script"
_final_deps += [ ":${_create_stack_script_rule_name}" ] _final_deps += [ ":${_create_stack_script_rule_name}" ]
stack_script(_create_stack_script_rule_name) { stack_script(_create_stack_script_rule_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