Commit 2ded0b9b authored by agrieve's avatar agrieve Committed by Commit bot

Reland of Make secondary abi work for component build

Reverted in:
https://codereview.chromium.org/2327063002/

Reason for reland:
Now guards non-build import behind enable_java_templates

TBR=michaelbai,machenbach
BUG=622855

Review-Url: https://codereview.chromium.org/2326973003
Cr-Commit-Position: refs/heads/master@{#417597}
parent 4dd6aef3
...@@ -70,7 +70,7 @@ copy("cpplib_unstripped") { ...@@ -70,7 +70,7 @@ copy("cpplib_unstripped") {
action("cpplib_stripped") { action("cpplib_stripped") {
_strip_bin = "${android_tool_prefix}strip" _strip_bin = "${android_tool_prefix}strip"
_soname = "libc++_shared.so" _soname = "libc++_shared.so"
_input_so = "${root_out_dir}/lib.unstripped/${_soname}" _input_so = "${root_shlib_dir}/lib.unstripped/${_soname}"
_output_so = "${root_shlib_dir}/${_soname}" _output_so = "${root_shlib_dir}/${_soname}"
deps = [ deps = [
...@@ -91,9 +91,9 @@ action("cpplib_stripped") { ...@@ -91,9 +91,9 @@ action("cpplib_stripped") {
_output_so, _output_so,
] ]
_rebased_strip_bin = rebase_path(_strip_bin, root_out_dir) _rebased_strip_bin = rebase_path(_strip_bin, root_build_dir)
_rebased_input_so = rebase_path(_input_so, root_out_dir) _rebased_input_so = rebase_path(_input_so, root_build_dir)
_rebased_output_so = rebase_path(_output_so, root_out_dir) _rebased_output_so = rebase_path(_output_so, root_build_dir)
args = [ args = [
_rebased_strip_bin, _rebased_strip_bin,
"--strip-unneeded", "--strip-unneeded",
......
...@@ -209,6 +209,11 @@ def _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files): ...@@ -209,6 +209,11 @@ def _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files):
ret.reverse() ret.reverse()
return ret return ret
def _CreateJavaLibrariesList(library_paths):
""" Create a java literal array with the "base" library names:
e.g. libfoo.so -> foo
"""
return ('{%s}' % ','.join(['"%s"' % s[3:-3] for s in library_paths]))
def main(argv): def main(argv):
parser = optparse.OptionParser() parser = optparse.OptionParser()
...@@ -264,6 +269,9 @@ def main(argv): ...@@ -264,6 +269,9 @@ def main(argv):
parser.add_option('--shared-libraries-runtime-deps', parser.add_option('--shared-libraries-runtime-deps',
help='Path to file containing runtime deps for shared ' help='Path to file containing runtime deps for shared '
'libraries.') 'libraries.')
parser.add_option('--secondary-abi-shared-libraries-runtime-deps',
help='Path to file containing runtime deps for secondary '
'abi shared libraries.')
# 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.')
...@@ -629,15 +637,24 @@ def main(argv): ...@@ -629,15 +637,24 @@ def main(argv):
options.shared_libraries_runtime_deps or '[]') options.shared_libraries_runtime_deps or '[]')
if runtime_deps_files: if runtime_deps_files:
library_paths = _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files) library_paths = _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files)
# Create a java literal array with the "base" library names: java_libraries_list = _CreateJavaLibrariesList(library_paths)
# e.g. libfoo.so -> foo
java_libraries_list = ('{%s}' % ','.join( secondary_abi_library_paths = []
['"%s"' % s[3:-3] for s in library_paths])) secondary_abi_java_libraries_list = None
secondary_abi_runtime_deps_files = build_utils.ParseGnList(
options.secondary_abi_shared_libraries_runtime_deps or '[]')
if secondary_abi_runtime_deps_files:
secondary_abi_library_paths = _ExtractSharedLibsFromRuntimeDeps(
secondary_abi_runtime_deps_files)
secondary_abi_java_libraries_list = _CreateJavaLibrariesList(
secondary_abi_library_paths)
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,
'java_libraries_list': java_libraries_list, 'java_libraries_list': java_libraries_list,
'secondary_abi_java_libraries_list': secondary_abi_java_libraries_list,
} }
config['assets'], config['uncompressed_assets'] = ( config['assets'], config['uncompressed_assets'] = (
_MergeAssets(deps.All('android_assets'))) _MergeAssets(deps.All('android_assets')))
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import("//build_overrides/build.gni") import("//build_overrides/build.gni")
import("//build/config/android/config.gni") import("//build/config/android/config.gni")
import("//build/config/sanitizers/sanitizers.gni") import("//build/config/sanitizers/sanitizers.gni")
import("//third_party/android_platform/config.gni")
assert(is_android) assert(is_android)
...@@ -300,6 +301,17 @@ template("write_build_config") { ...@@ -300,6 +301,17 @@ template("write_build_config") {
] ]
} }
if (defined(invoker.secondary_abi_shared_libraries_runtime_deps_file)) {
# 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.
# See comment in rules.gni for why we do this.
args += [
"--secondary-abi-shared-libraries-runtime-deps",
rebase_path(invoker.secondary_abi_shared_libraries_runtime_deps_file,
root_build_dir),
]
}
if (defined(invoker.proguard_enabled) && invoker.proguard_enabled) { if (defined(invoker.proguard_enabled) && invoker.proguard_enabled) {
args += [ args += [
"--proguard-enabled", "--proguard-enabled",
...@@ -629,6 +641,7 @@ template("test_runner_script") { ...@@ -629,6 +641,7 @@ template("test_runner_script") {
if (enable_java_templates) { if (enable_java_templates) {
import("//build/config/zip.gni") import("//build/config/zip.gni")
import("//third_party/ijar/ijar.gni") import("//third_party/ijar/ijar.gni")
import("//third_party/android_platform/config.gni")
rebased_android_sdk = rebase_path(android_sdk, root_build_dir) rebased_android_sdk = rebase_path(android_sdk, root_build_dir)
rebased_android_sdk_build_tools = rebased_android_sdk_build_tools =
...@@ -1272,8 +1285,16 @@ if (enable_java_templates) { ...@@ -1272,8 +1285,16 @@ if (enable_java_templates) {
if (_native_lib_placeholders != []) { if (_native_lib_placeholders != []) {
args += [ "--native-lib-placeholders=$_native_lib_placeholders" ] args += [ "--native-lib-placeholders=$_native_lib_placeholders" ]
} }
if (defined(invoker.secondary_native_libs) &&
invoker.secondary_native_libs != []) { # TODO (michaelbai): Remove the secondary_native_libs variable.
if (defined(invoker.secondary_abi_native_libs_filearg)) {
assert(defined(android_app_secondary_abi))
args += [
"--secondary-native-libs=${invoker.secondary_abi_native_libs_filearg}",
"--secondary-android-abi=$android_app_secondary_abi",
]
} else if (defined(invoker.secondary_native_libs) &&
invoker.secondary_native_libs != []) {
assert(defined(android_app_secondary_abi)) assert(defined(android_app_secondary_abi))
inputs += invoker.secondary_native_libs inputs += invoker.secondary_native_libs
_secondary_native_libs = rebase_path(invoker.secondary_native_libs) _secondary_native_libs = rebase_path(invoker.secondary_native_libs)
...@@ -1598,6 +1619,7 @@ if (enable_java_templates) { ...@@ -1598,6 +1619,7 @@ if (enable_java_templates) {
"emma_instrument", "emma_instrument",
"native_lib_placeholders", "native_lib_placeholders",
"native_libs_filearg", "native_libs_filearg",
"secondary_abi_native_libs_filearg",
"secondary_native_libs", "secondary_native_libs",
"uncompress_shared_libraries", "uncompress_shared_libraries",
"write_asset_list", "write_asset_list",
...@@ -2640,4 +2662,40 @@ if (enable_java_templates) { ...@@ -2640,4 +2662,40 @@ if (enable_java_templates) {
] ]
} }
} }
template("pack_relocation_section") {
assert(defined(invoker.file_list_json))
assert(defined(invoker.libraries_filearg))
action(target_name) {
forward_variables_from(invoker,
[
"deps",
"public_deps",
"inputs",
"testonly",
])
script = "//build/android/gyp/pack_relocations.py"
depfile = "$target_gen_dir/$target_name.d"
_packed_libraries_dir = "$target_gen_dir/$target_name/packed-libs"
outputs = [
invoker.file_list_json,
]
deps += [ relocation_packer_target ]
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--enable-packing=1",
"--android-pack-relocations",
rebase_path(relocation_packer_exe, root_build_dir),
"--stripped-libraries-dir",
rebase_path(root_build_dir, root_build_dir),
"--packed-libraries-dir",
rebase_path(_packed_libraries_dir, root_build_dir),
"--libraries=${invoker.libraries_filearg}",
"--filelistjson",
rebase_path(invoker.file_list_json, root_build_dir),
]
}
}
} }
...@@ -141,7 +141,6 @@ template("wrapper_script") { ...@@ -141,7 +141,6 @@ template("wrapper_script") {
if (enable_java_templates) { if (enable_java_templates) {
import("//build/config/sanitizers/sanitizers.gni") import("//build/config/sanitizers/sanitizers.gni")
import("//third_party/android_platform/config.gni")
import("//tools/grit/grit_rule.gni") import("//tools/grit/grit_rule.gni")
# Declare a jni target # Declare a jni target
...@@ -1424,6 +1423,9 @@ if (enable_java_templates) { ...@@ -1424,6 +1423,9 @@ if (enable_java_templates) {
# shared_libraries: List shared_library targets to bundle. If these # shared_libraries: List shared_library targets to bundle. If these
# libraries depend on other shared_library targets, those dependencies will # libraries depend on other shared_library targets, those dependencies will
# also be included in the apk (e.g. for is_component_build). # also be included in the apk (e.g. for is_component_build).
# secondary_abi_shared_libraries: secondary abi shared_library targets to
# bundle. If these libraries depend on other shared_library targets, those
# dependencies will also be included in the apk (e.g. for is_component_build).
# native_lib_placeholders: List of placeholder filenames to add to the apk # native_lib_placeholders: List of placeholder filenames to add to the apk
# (optional). # (optional).
# apk_under_test: For an instrumentation test apk, this is the target of the # apk_under_test: For an instrumentation test apk, this is the target of the
...@@ -1438,7 +1440,8 @@ if (enable_java_templates) { ...@@ -1438,7 +1440,8 @@ if (enable_java_templates) {
# requires_sdk_api_level_23: If defined and true, the apk is intended for # requires_sdk_api_level_23: If defined and true, the apk is intended for
# installation only on Android M or later. In these releases the system # installation only on Android M or later. In these releases the system
# linker does relocation unpacking, so we can enable it unconditionally. # linker does relocation unpacking, so we can enable it unconditionally.
# secondary_native_libs: The path of native libraries for secondary app abi. # secondary_native_libs (deprecated): The path of native libraries for secondary
# app abi.
# run_findbugs_override: Forces run_findbugs on or off. If undefined, the # run_findbugs_override: Forces run_findbugs on or off. If undefined, the
# default will use the build arg run_findbugs. # default will use the build arg run_findbugs.
# proguard_jar_path: The path to proguard.jar you wish to use. If undefined, # proguard_jar_path: The path to proguard.jar you wish to use. If undefined,
...@@ -1554,13 +1557,25 @@ if (enable_java_templates) { ...@@ -1554,13 +1557,25 @@ if (enable_java_templates) {
# The dependency that makes the chromium linker, if any is needed. # The dependency that makes the chromium linker, if any is needed.
_native_libs_deps = [] _native_libs_deps = []
_shared_libraries_is_valid =
if (defined(invoker.shared_libraries) && invoker.shared_libraries != []) { defined(invoker.shared_libraries) && invoker.shared_libraries != []
_native_libs_deps += invoker.shared_libraries _secondary_abi_native_libs_deps = []
assert(_secondary_abi_native_libs_deps == []) # mark as used.
if (is_component_build || is_asan) { _secondary_abi_shared_libraries_is_valid =
defined(invoker.secondary_abi_shared_libraries) &&
invoker.secondary_abi_shared_libraries != []
if (is_component_build || is_asan) {
if (_shared_libraries_is_valid) {
_native_libs_deps += [ "//build/android:cpplib_stripped" ] _native_libs_deps += [ "//build/android:cpplib_stripped" ]
} }
if (_secondary_abi_shared_libraries_is_valid) {
_secondary_abi_native_libs_deps += [ "//build/android:cpplib_stripped($android_secondary_abi_toolchain)" ]
}
}
if (_shared_libraries_is_valid) {
_native_libs_deps += invoker.shared_libraries
# To determine the filenames of all dependent shared libraries, write the # To determine the filenames of all dependent shared libraries, write the
# runtime deps of |shared_libraries| to a file during "gn gen". # runtime deps of |shared_libraries| to a file during "gn gen".
...@@ -1583,6 +1598,21 @@ if (enable_java_templates) { ...@@ -1583,6 +1598,21 @@ if (enable_java_templates) {
} }
} }
if (_secondary_abi_shared_libraries_is_valid) {
_secondary_abi_native_libs_deps += invoker.secondary_abi_shared_libraries
# To determine the filenames of all dependent shared libraries, write the
# runtime deps of |shared_libraries| to a file during "gn gen".
# write_build_config.py will then grep this file for *.so to obtain the
# complete list.
_secondary_abi_runtime_deps_file =
"$target_gen_dir/${_template_name}.secondary.abi.native.runtimedeps"
group("${_template_name}_secondary_abi__runtime_deps") {
deps = _secondary_abi_native_libs_deps
write_runtime_deps = _secondary_abi_runtime_deps_file
}
}
if (defined(invoker.deps)) { if (defined(invoker.deps)) {
set_sources_assignment_filter([ "*manifest*" ]) set_sources_assignment_filter([ "*manifest*" ])
sources = invoker.deps sources = invoker.deps
...@@ -1661,6 +1691,10 @@ if (enable_java_templates) { ...@@ -1661,6 +1691,10 @@ if (enable_java_templates) {
if (_native_libs_deps != []) { if (_native_libs_deps != []) {
shared_libraries_runtime_deps_file = _runtime_deps_file shared_libraries_runtime_deps_file = _runtime_deps_file
} }
if (_secondary_abi_native_libs_deps != []) {
secondary_abi_shared_libraries_runtime_deps_file =
_secondary_abi_runtime_deps_file
}
} }
_final_deps = [] _final_deps = []
...@@ -1928,51 +1962,62 @@ if (enable_java_templates) { ...@@ -1928,51 +1962,62 @@ if (enable_java_templates) {
_native_libs_file_arg_dep = ":$build_config_target" _native_libs_file_arg_dep = ":$build_config_target"
_native_libs_file_arg = "@FileArg($_rebased_build_config:native:libraries)" _native_libs_file_arg = "@FileArg($_rebased_build_config:native:libraries)"
_secondary_abi_native_libs_file_arg_dep = ":$build_config_target"
_secondary_abi_native_libs_file_arg =
"@FileArg($_rebased_build_config:native:secondary_abi_libraries)"
assert(_secondary_abi_native_libs_file_arg != "" &&
_secondary_abi_native_libs_file_arg_dep != "") # Mark as used.
if (_native_libs_deps != [] && _enable_relocation_packing) { if (_native_libs_deps != [] && _enable_relocation_packing) {
_prepare_native_target_name = "${_template_name}__prepare_native" _prepare_native_target_name = "${_template_name}__prepare_native"
_native_libs_dir = "$gen_dir/packed-libs"
_native_libs_json = "$gen_dir/packed-libs/filelist.json" _native_libs_json = "$gen_dir/packed-libs/filelist.json"
_rebased_native_libs_json = rebase_path(_native_libs_json, root_build_dir) _rebased_native_libs_json = rebase_path(_native_libs_json, root_build_dir)
_native_libs_file_arg_dep = ":$_prepare_native_target_name" _native_libs_file_arg_dep = ":$_prepare_native_target_name"
_native_libs_file_arg = "@FileArg($_rebased_native_libs_json:files)" _native_libs_file_arg = "@FileArg($_rebased_native_libs_json:files)"
action(_prepare_native_target_name) { pack_relocation_section(_prepare_native_target_name) {
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
"deps", "deps",
"public_deps", "public_deps",
]) ])
script = "//build/android/gyp/pack_relocations.py" file_list_json = _native_libs_json
depfile = "$target_gen_dir/$target_name.d" libraries_filearg =
outputs = [ "@FileArg(${_rebased_build_config}:native:libraries)"
_native_libs_json,
]
inputs = [ inputs = [
_build_config, _build_config,
] ]
deps += _native_libs_deps deps += _native_libs_deps
deps += [ deps += [ ":$build_config_target" ]
":$build_config_target", }
relocation_packer_target, if (_secondary_abi_native_libs_deps != []) {
] _prepare_native_target_name =
"${_template_name}_secondary_abi__prepare_native"
_native_libs_json =
"$gen_dir/packed-libs/$android_secondary_abi_cpu/filelist.json"
_rebased_native_libs_json =
rebase_path(_native_libs_json, root_build_dir)
_secondary_abi_native_libs_file_arg_dep =
":$_prepare_native_target_name"
_secondary_abi_native_libs_file_arg =
"@FileArg($_rebased_native_libs_json:files)"
pack_relocation_section(_prepare_native_target_name) {
forward_variables_from(invoker,
[
"deps",
"public_deps",
])
file_list_json = _native_libs_json
libraries_filearg = "@FileArg(${_rebased_build_config}:native:secondary_abi_libraries)"
inputs = [
_build_config,
]
args = [ deps += _secondary_abi_native_libs_deps
"--depfile", deps += [ ":$build_config_target" ]
rebase_path(depfile, root_build_dir), }
"--enable-packing=1",
"--android-pack-relocations",
rebase_path(relocation_packer_exe, root_build_dir),
"--stripped-libraries-dir",
rebase_path(root_build_dir, root_build_dir),
"--packed-libraries-dir",
rebase_path(_native_libs_dir, root_build_dir),
"--libraries=@FileArg(${_rebased_build_config}:native:libraries)",
"--filelistjson=$_rebased_native_libs_json",
]
} }
} }
...@@ -2067,6 +2112,12 @@ if (enable_java_templates) { ...@@ -2067,6 +2112,12 @@ if (enable_java_templates) {
_extra_native_libs_even_when_incremental _extra_native_libs_even_when_incremental
} }
if (_secondary_abi_native_libs_deps != [] && !_create_abi_split) {
deps += _secondary_abi_native_libs_deps +
[ _secondary_abi_native_libs_file_arg_dep ]
secondary_abi_native_libs_filearg = _secondary_abi_native_libs_file_arg
}
# Placeholders necessary for some older devices. # Placeholders necessary for some older devices.
# http://crbug.com/395038 # http://crbug.com/395038
forward_variables_from(invoker, [ "native_lib_placeholders" ]) forward_variables_from(invoker, [ "native_lib_placeholders" ])
......
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