GN + Android: extract android_standalone_library rule.
This patch extracts the rule needed to produce a standalone .dex.jar for a set of Java dependencies into a separate rule. This allows to package any android library into a standalone .dex.jar file without affecting the target being packaged. BUG=437290 Review URL: https://codereview.chromium.org/778093004 Cr-Original-Commit-Position: refs/heads/master@{#307575} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 7d7c32ec12774eaf22c901194ff9f788a1dcc9b2
This commit is contained in:
Родитель
9ef4e72d30
Коммит
22dd633466
|
@ -95,13 +95,14 @@ def main(argv):
|
|||
|
||||
|
||||
if not options.type in [
|
||||
'java_library', 'android_resources', 'android_apk']:
|
||||
'java_library', 'android_resources', 'android_apk', 'deps_dex']:
|
||||
raise Exception('Unknown type: <%s>' % options.type)
|
||||
|
||||
required_options = ['build_config'] + {
|
||||
'java_library': ['jar_path'],
|
||||
'android_resources': ['resources_zip'],
|
||||
'android_apk': ['jar_path', 'dex_path', 'resources_zip']
|
||||
'android_apk': ['jar_path', 'dex_path', 'resources_zip'],
|
||||
'deps_dex': ['dex_path']
|
||||
}[options.type]
|
||||
|
||||
if options.native_libs:
|
||||
|
@ -213,10 +214,8 @@ def main(argv):
|
|||
c['package_name'] for c in all_resources_deps if 'package_name' in c]
|
||||
|
||||
|
||||
# Dependencies for the final dex file of an apk or the standalone .dex.jar
|
||||
# output of a library.
|
||||
if options.type == 'android_apk' or (options.type == "java_library"
|
||||
and options.supports_android):
|
||||
# Dependencies for the final dex file of an apk or a 'deps_dex'.
|
||||
if options.type in ['android_apk', 'deps_dex']:
|
||||
config['final_dex'] = {}
|
||||
dex_config = config['final_dex']
|
||||
# TODO(cjhopman): proguard version
|
||||
|
|
|
@ -66,12 +66,13 @@ template("dex") {
|
|||
testonly = invoker.testonly
|
||||
}
|
||||
|
||||
assert(defined(invoker.sources))
|
||||
assert(defined(invoker.output))
|
||||
action(target_name) {
|
||||
script = "//build/android/gyp/dex.py"
|
||||
depfile = "$target_gen_dir/$target_name.d"
|
||||
sources = invoker.sources
|
||||
if (defined(invoker.sources)) {
|
||||
sources = invoker.sources
|
||||
}
|
||||
outputs = [
|
||||
depfile,
|
||||
invoker.output,
|
||||
|
@ -103,7 +104,9 @@ template("dex") {
|
|||
args += invoker.args
|
||||
}
|
||||
|
||||
args += rebase_path(invoker.sources, root_build_dir)
|
||||
if (defined(invoker.sources)) {
|
||||
args += rebase_path(invoker.sources, root_build_dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,7 +166,7 @@ template("write_build_config") {
|
|||
build_config = invoker.build_config
|
||||
|
||||
assert(type == "android_apk" || type == "java_library" ||
|
||||
type == "android_resources")
|
||||
type == "android_resources" || type == "deps_dex")
|
||||
|
||||
action(target_name) {
|
||||
script = "//build/android/gyp/write_build_config.py"
|
||||
|
@ -201,11 +204,12 @@ template("write_build_config") {
|
|||
is_java_library = type == "java_library"
|
||||
is_apk = type == "android_apk"
|
||||
is_android_resources = type == "android_resources"
|
||||
is_deps_dex = type == "deps_dex"
|
||||
|
||||
supports_android = is_apk || is_android_resources ||
|
||||
supports_android = is_apk || is_android_resources || is_deps_dex ||
|
||||
(is_java_library && defined(invoker.supports_android) &&
|
||||
invoker.supports_android)
|
||||
requires_android = is_apk || is_android_resources ||
|
||||
requires_android = is_apk || is_android_resources || is_deps_dex ||
|
||||
(is_java_library && defined(invoker.requires_android) &&
|
||||
invoker.requires_android)
|
||||
|
||||
|
@ -216,6 +220,7 @@ template("write_build_config") {
|
|||
assert(is_java_library || true)
|
||||
assert(is_apk || true)
|
||||
assert(is_android_resources || true)
|
||||
assert(is_deps_dex || true)
|
||||
|
||||
if (is_java_library || is_apk) {
|
||||
args += [
|
||||
|
@ -224,7 +229,7 @@ template("write_build_config") {
|
|||
]
|
||||
}
|
||||
|
||||
if (is_apk || (is_java_library && supports_android)) {
|
||||
if (is_apk || is_deps_dex || (is_java_library && supports_android)) {
|
||||
args += [
|
||||
"--dex-path",
|
||||
rebase_path(invoker.dex_path, root_build_dir),
|
||||
|
@ -898,22 +903,6 @@ template("java_library_impl") {
|
|||
]
|
||||
output = _dex_path
|
||||
}
|
||||
|
||||
if (defined(invoker.standalone_dex_path)) {
|
||||
_final_deps += [ ":${_template_name}__standalone_dex" ]
|
||||
_rebased_build_config = rebase_path(_build_config, root_build_dir)
|
||||
dex("${_template_name}__standalone_dex") {
|
||||
sources = [
|
||||
_jar_path,
|
||||
]
|
||||
inputs = [
|
||||
_build_config,
|
||||
]
|
||||
output = invoker.standalone_dex_path
|
||||
dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files"
|
||||
args = [ "--inputs=@FileArg($dex_arg_key)" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group(target_name) {
|
||||
|
@ -1061,3 +1050,25 @@ template("copy_ex") {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Produces a single .dex.jar out of a set of Java dependencies.
|
||||
template("deps_dex") {
|
||||
build_config = "$target_gen_dir/${target_name}.build_config"
|
||||
write_build_config("${target_name}__build_config") {
|
||||
type = "deps_dex"
|
||||
deps = invoker.deps
|
||||
|
||||
build_config = build_config
|
||||
dex_path = invoker.dex_path
|
||||
}
|
||||
|
||||
rebased_build_config = rebase_path(build_config, root_build_dir)
|
||||
dex(target_name) {
|
||||
inputs = [
|
||||
build_config,
|
||||
]
|
||||
output = invoker.dex_path
|
||||
dex_arg_key = "${rebased_build_config}:final_dex:dependency_dex_files"
|
||||
args = [ "--inputs=@FileArg($dex_arg_key)" ]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -922,8 +922,6 @@ template("java_prebuilt") {
|
|||
#
|
||||
# dex_path: If set, the resulting .dex.jar file will be placed under this
|
||||
# path.
|
||||
# standalone_dex_path: If set, a standalone .dex.jar containing the code from
|
||||
# the library and all dependencies will be placed under this path.
|
||||
#
|
||||
#
|
||||
# Example
|
||||
|
@ -986,9 +984,6 @@ template("android_library") {
|
|||
if (defined(invoker.dex_path)) {
|
||||
dex_path = invoker.dex_path
|
||||
}
|
||||
if (defined(invoker.standalone_dex_path)) {
|
||||
standalone_dex_path = invoker.standalone_dex_path
|
||||
}
|
||||
|
||||
supports_android = true
|
||||
requires_android = true
|
||||
|
@ -1005,6 +1000,20 @@ template("android_library") {
|
|||
}
|
||||
}
|
||||
|
||||
# Declare a target that packages a set of Java dependencies into a standalone
|
||||
# .dex.jar.
|
||||
#
|
||||
# Variables
|
||||
# deps: specifies the dependencies of this target. Android libraries in deps
|
||||
# will be packaged into the resulting .dex.jar file.
|
||||
# dex_path: location at which the output file will be put
|
||||
template("android_standalone_library") {
|
||||
deps_dex(target_name) {
|
||||
deps = invoker.deps
|
||||
dex_path = invoker.dex_path
|
||||
}
|
||||
}
|
||||
|
||||
# Declare an Android library target for a prebuilt jar
|
||||
#
|
||||
# This target creates an Android library containing java code and Android
|
||||
|
|
Загрузка…
Ссылка в новой задаче