blob: d59fd8e9857e47597e1088b064e2d6b96e03fdd0 [file] [log] [blame]
# Copyright 2019 The Chromium Authors. All rights reserved.
# 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")
# Declare an Android library factory target.
#
# This target creates an Android library target containing stripped java
# factory files. The generated target will not contain any .class files as all
# of them are excluded by jar_excluded_patterns. This target is intended to
# generate an empty factory that will be swapped out at build time by the real
# factory.
#
# Specific requirements for the java factory files are listed in the script:
# //chrome/android/features/create_stripped_java_factory.py
#
# Variables:
# sources: A list of all java factory files to be stripped.
# deps: Any deps needed by the generated Android library target.
#
# Example:
# android_library_factory("foo_java") {
# sources = [
# "android/org/chromium/foo/FooFactory.java",
# ]
# deps = [
# ":foo_public_interface"
# ]
# }
#
# //android/org/chromium/foo/FooFactory.java:
# public class FooFactory {
# private FooFactory () {}
#
# public static Foo createFoo() {
# return new FooImpl();
# }
# }
#
# //generated/org/chromium/foo/FooFactory.java:
# public class FooFactory {
# private FooFactory () {}
#
# public static Foo createFoo() {
# return null;
# }
# }
template("android_library_factory") {
forward_variables_from(invoker, [ "testonly" ])
# No underscores for factory target name to avoid crbug.com/908819.
_process_factory_target_name = "${target_name}factory"
_base_gen_dir = "${target_gen_dir}/${target_name}"
action_foreach_with_pydeps(_process_factory_target_name) {
script = "//chrome/android/features/create_stripped_java_factory.py"
sources = invoker.sources
outputs = [
"$_base_gen_dir/{{source_root_relative_dir}}/{{source_file_part}}",
]
args = [
"--output",
rebase_path(outputs[0], root_build_dir),
"--input={{source}}",
]
}
android_library(target_name) {
deps = [
":$_process_factory_target_name",
]
if (defined(invoker.deps)) {
deps += invoker.deps
}
java_files = get_target_outputs(":$_process_factory_target_name")
jar_excluded_patterns = [ "*" ]
}
}