175 lines
6.2 KiB
Plaintext
175 lines
6.2 KiB
Plaintext
# Copyright 2022 The Chromium Authors
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
import("//build/config/android/rules.gni")
|
|
|
|
# Creates a stub .apk suitable for use with compressed system APKs.
|
|
#
|
|
# Variables:
|
|
# package_name: Package name to use for the stub.
|
|
# version_code: Version code for the stub.
|
|
# version_name: Version name for the stub.
|
|
# package_info_from_target: Use the package name and version_code from this
|
|
# apk/bundle target.
|
|
# static_library_name: For static library apks, name for the <static-library>.
|
|
# static_library_version: For static library apks, version for the
|
|
# <static-library> tag (for TrichromeLibrary, we set this to be the same
|
|
# as the package's version_code)
|
|
# stub_output: Path to output stub apk (default: do not create a stub).
|
|
#
|
|
# package_name and package_info_from_target are mutually exclusive.
|
|
template("system_image_stub_apk") {
|
|
# Android requires stubs end with -Stub.apk.
|
|
assert(filter_exclude([ invoker.stub_output ], [ "*-Stub.apk" ]) == [],
|
|
"stub_output \"${invoker.stub_output}\" must end with \"-Stub.apk\"")
|
|
|
|
_resource_apk_path = "${target_out_dir}/$target_name.ap_"
|
|
_resource_apk_target_name = "${target_name}__compile_resources"
|
|
|
|
_manifest_target_name = "${target_name}__manifest"
|
|
_manifest_path = "$target_gen_dir/$_manifest_target_name.xml"
|
|
action("$_manifest_target_name") {
|
|
outputs = [ _manifest_path ]
|
|
script = "//build/android/gyp/create_stub_manifest.py"
|
|
args = [
|
|
"--output",
|
|
rebase_path(_manifest_path, root_build_dir),
|
|
]
|
|
if (defined(invoker.static_library_name)) {
|
|
args += [
|
|
"--static-library-name",
|
|
invoker.static_library_name,
|
|
]
|
|
|
|
# TODO(crbug.com/1408164): Make static_library_version mandatory.
|
|
if (defined(invoker.static_library_version)) {
|
|
args += [
|
|
"--static-library-version",
|
|
invoker.static_library_version,
|
|
]
|
|
} else {
|
|
args += [ "--static-library-version=1" ]
|
|
}
|
|
}
|
|
}
|
|
|
|
action_with_pydeps(_resource_apk_target_name) {
|
|
script = "//build/android/gyp/compile_resources.py"
|
|
inputs = [
|
|
_manifest_path,
|
|
android_sdk_jar,
|
|
]
|
|
outputs = [ _resource_apk_path ]
|
|
args = [
|
|
"--aapt2-path",
|
|
rebase_path(android_sdk_tools_bundle_aapt2, root_build_dir),
|
|
"--min-sdk-version=$default_min_sdk_version",
|
|
"--target-sdk-version=$default_android_sdk_version",
|
|
"--android-manifest",
|
|
rebase_path(_manifest_path, root_build_dir),
|
|
"--arsc-path",
|
|
rebase_path(_resource_apk_path, root_build_dir),
|
|
]
|
|
deps = [ ":$_manifest_target_name" ]
|
|
if (defined(invoker.package_name)) {
|
|
_package_name = invoker.package_name
|
|
_version_code = invoker.version_code
|
|
_version_name = invoker.version_name
|
|
} else {
|
|
_target = invoker.package_info_from_target
|
|
deps += [ "${_target}$build_config_target_suffix" ]
|
|
_build_config = get_label_info(_target, "target_gen_dir") + "/" +
|
|
get_label_info(_target, "name") + ".build_config.json"
|
|
inputs += [ _build_config ]
|
|
_rebased_build_config = rebase_path(_build_config, root_build_dir)
|
|
_package_name = "@FileArg($_rebased_build_config:deps_info:package_name)"
|
|
_version_code = "@FileArg($_rebased_build_config:deps_info:version_code)"
|
|
_version_name = "@FileArg($_rebased_build_config:deps_info:version_name)"
|
|
}
|
|
args += [
|
|
"--rename-manifest-package=$_package_name",
|
|
"--arsc-package-name=$_package_name",
|
|
"--version-code=$_version_code",
|
|
"--version-name=$_version_name",
|
|
"--include-resources",
|
|
rebase_path(android_sdk_jar, root_build_dir),
|
|
]
|
|
}
|
|
|
|
package_apk(target_name) {
|
|
forward_variables_from(invoker,
|
|
[
|
|
"keystore_name",
|
|
"keystore_path",
|
|
"keystore_password",
|
|
])
|
|
min_sdk_version = default_min_sdk_version
|
|
deps = [ ":$_resource_apk_target_name" ]
|
|
|
|
packaged_resources_path = _resource_apk_path
|
|
output_apk_path = invoker.stub_output
|
|
}
|
|
}
|
|
|
|
# Generates artifacts for system APKs.
|
|
#
|
|
# Variables:
|
|
# apk_or_bundle_target: Target that creates input bundle or apk.
|
|
# input_apk_or_bundle: Path to input .apk or .aab.
|
|
# static_library_name: For static library apks, name for the <static-library>.
|
|
# static_library_version: For static library apks, version for the
|
|
# <static-library> tag (for TrichromeLibrary, we set this to be the same
|
|
# as the package's version_code)
|
|
# output: Path to the output system .apk or .zip.
|
|
# fuse_apk: Fuse all apk splits into a single .apk (default: false).
|
|
# stub_output: Path to output stub apk (default: do not create a stub).
|
|
#
|
|
template("system_image_apks") {
|
|
if (defined(invoker.stub_output)) {
|
|
_stub_apk_target_name = "${target_name}__stub"
|
|
system_image_stub_apk(_stub_apk_target_name) {
|
|
forward_variables_from(invoker,
|
|
[
|
|
"static_library_name",
|
|
"static_library_version",
|
|
])
|
|
package_info_from_target = invoker.apk_or_bundle_target
|
|
stub_output = invoker.stub_output
|
|
}
|
|
}
|
|
|
|
action_with_pydeps(target_name) {
|
|
script = "//build/android/gyp/system_image_apks.py"
|
|
deps = [ invoker.apk_or_bundle_target ]
|
|
inputs = [ invoker.input_apk_or_bundle ]
|
|
if (defined(invoker.stub_output)) {
|
|
public_deps = [ ":$_stub_apk_target_name" ]
|
|
}
|
|
outputs = [ invoker.output ]
|
|
args = [
|
|
"--input",
|
|
rebase_path(invoker.input_apk_or_bundle, root_out_dir),
|
|
"--output",
|
|
rebase_path(invoker.output, root_out_dir),
|
|
]
|
|
|
|
_is_bundle =
|
|
filter_exclude([ invoker.input_apk_or_bundle ], [ "*.aab" ]) == []
|
|
|
|
if (_is_bundle) {
|
|
_wrapper_path = "$root_out_dir/bin/" +
|
|
get_label_info(invoker.apk_or_bundle_target, "name")
|
|
args += [
|
|
"--bundle-wrapper",
|
|
rebase_path(_wrapper_path, root_out_dir),
|
|
]
|
|
inputs += [ _wrapper_path ]
|
|
deps += [ "//build/android:apk_operations_py" ]
|
|
if (defined(invoker.fuse_apk) && invoker.fuse_apk) {
|
|
args += [ "--fuse-apk" ]
|
|
}
|
|
}
|
|
}
|
|
}
|