Commit 4227e23c authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Android: Refactor GN templates to unify prebuilt & non-prebuilt logic

Makes it easier to add a java_annotation_processor() template

This removes main_class from java_prebuilt() in favor of using
java_binary() with a jar_path.

Bug: 792170
Cq-Include-Trybots: master.tryserver.chromium.android:android_cronet_tester;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I8b92addae2228398f911d9456b9c55d5ebf48529
Reviewed-on: https://chromium-review.googlesource.com/810032Reviewed-by: default avatarAndrei Kapishnikov <kapishnikov@chromium.org>
Reviewed-by: default avatarEric Stevenson <estevenson@chromium.org>
Commit-Queue: agrieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522220}
parent 5a3ed56a
...@@ -34,7 +34,9 @@ if (enable_java_templates) { ...@@ -34,7 +34,9 @@ if (enable_java_templates) {
java_prebuilt("sun_tools_java") { java_prebuilt("sun_tools_java") {
jar_path = sun_tools_jar_path jar_path = sun_tools_jar_path
jar_dep = ":find_sun_tools_jar" deps = [
":find_sun_tools_jar",
]
} }
generate_interface_jar("android_ijar") { generate_interface_jar("android_ijar") {
......
...@@ -69,7 +69,6 @@ def main(argv): ...@@ -69,7 +69,6 @@ def main(argv):
parser = optparse.OptionParser() parser = optparse.OptionParser()
build_utils.AddDepfileOption(parser) build_utils.AddDepfileOption(parser)
parser.add_option('--output', help='Output path for executable script.') parser.add_option('--output', help='Output path for executable script.')
parser.add_option('--jar-path', help='Path to the main jar.')
parser.add_option('--main-class', parser.add_option('--main-class',
help='Name of the java class with the "main" entry point.') help='Name of the java class with the "main" entry point.')
parser.add_option('--classpath', action='append', default=[], parser.add_option('--classpath', action='append', default=[],
...@@ -86,7 +85,7 @@ def main(argv): ...@@ -86,7 +85,7 @@ def main(argv):
else: else:
noverify_flag = '' noverify_flag = ''
classpath = [options.jar_path] classpath = []
for cp_arg in options.classpath: for cp_arg in options.classpath:
classpath += build_utils.ParseGnList(cp_arg) classpath += build_utils.ParseGnList(cp_arg)
......
...@@ -287,6 +287,8 @@ def main(argv): ...@@ -287,6 +287,8 @@ def main(argv):
# java library options # java library options
parser.add_option('--jar-path', help='Path to target\'s jar output.') parser.add_option('--jar-path', help='Path to target\'s jar output.')
parser.add_option('--is-prebuilt', action='store_true',
help='Whether the jar was compiled or pre-compiled.')
parser.add_option('--java-sources-file', help='Path to .sources file') parser.add_option('--java-sources-file', help='Path to .sources file')
parser.add_option('--bundled-srcjars', parser.add_option('--bundled-srcjars',
help='GYP-list of .srcjars that have been included in this java_library.') help='GYP-list of .srcjars that have been included in this java_library.')
...@@ -352,10 +354,9 @@ def main(argv): ...@@ -352,10 +354,9 @@ def main(argv):
parser.error('\n'.join(build_utils.ParseGnList(options.fail))) parser.error('\n'.join(build_utils.ParseGnList(options.fail)))
required_options_map = { required_options_map = {
'java_binary': ['build_config', 'jar_path'], 'java_binary': ['build_config'],
'junit_binary': ['build_config', 'jar_path'], 'junit_binary': ['build_config'],
'java_library': ['build_config', 'jar_path'], 'java_library': ['build_config', 'jar_path'],
'java_prebuilt': ['build_config', 'jar_path'],
'android_assets': ['build_config'], 'android_assets': ['build_config'],
'android_resources': ['build_config', 'resources_zip'], 'android_resources': ['build_config', 'resources_zip'],
'android_apk': ['build_config', 'jar_path', 'dex_path'], 'android_apk': ['build_config', 'jar_path', 'dex_path'],
...@@ -370,11 +371,6 @@ def main(argv): ...@@ -370,11 +371,6 @@ def main(argv):
build_utils.CheckOptions(options, parser, required_options) build_utils.CheckOptions(options, parser, required_options)
# Java prebuilts are the same as libraries except for in gradle files.
is_java_prebuilt = options.type == 'java_prebuilt'
if is_java_prebuilt:
options.type = 'java_library'
if options.type == 'java_library': if options.type == 'java_library':
if options.supports_android and not options.dex_path: if 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.')
...@@ -424,7 +420,7 @@ def main(argv): ...@@ -424,7 +420,7 @@ def main(argv):
# Required for generating gradle files. # Required for generating gradle files.
if options.type == 'java_library': if options.type == 'java_library':
deps_info['is_prebuilt'] = is_java_prebuilt deps_info['is_prebuilt'] = bool(options.is_prebuilt)
deps_info['gradle_treat_as_prebuilt'] = options.gradle_treat_as_prebuilt deps_info['gradle_treat_as_prebuilt'] = options.gradle_treat_as_prebuilt
if options.android_manifest: if options.android_manifest:
...@@ -485,9 +481,10 @@ def main(argv): ...@@ -485,9 +481,10 @@ def main(argv):
if options.type in ( if options.type in (
'java_binary', 'junit_binary', 'java_library', 'android_apk'): 'java_binary', 'junit_binary', 'java_library', 'android_apk'):
deps_info['jar_path'] = options.jar_path if options.jar_path:
if options.type == 'android_apk' or options.supports_android: deps_info['jar_path'] = options.jar_path
deps_info['dex_path'] = options.dex_path if options.type == 'android_apk' or options.supports_android:
deps_info['dex_path'] = options.dex_path
if options.type == 'android_apk': if options.type == 'android_apk':
deps_info['apk_path'] = options.apk_path deps_info['apk_path'] = options.apk_path
deps_info['incremental_apk_path'] = options.incremental_apk_path deps_info['incremental_apk_path'] = options.incremental_apk_path
...@@ -496,12 +493,10 @@ def main(argv): ...@@ -496,12 +493,10 @@ def main(argv):
deps_info['non_native_packed_relocations'] = str( deps_info['non_native_packed_relocations'] = str(
options.non_native_packed_relocations) options.non_native_packed_relocations)
requires_javac_classpath = options.type in ( requires_classpath = options.type in (
'java_binary', 'junit_binary', 'java_library', 'android_apk', 'dist_jar') 'java_binary', 'junit_binary', 'java_library', 'android_apk', 'dist_jar')
requires_full_classpath = (
options.type == 'java_prebuilt' or requires_javac_classpath)
if requires_javac_classpath: if requires_classpath:
# Classpath values filled in below (after applying tested_apk_config). # Classpath values filled in below (after applying tested_apk_config).
config['javac'] = {} config['javac'] = {}
...@@ -600,7 +595,7 @@ def main(argv): ...@@ -600,7 +595,7 @@ def main(argv):
if options.type in ['android_apk', 'deps_dex']: if options.type in ['android_apk', 'deps_dex']:
deps_dex_files = [c['dex_path'] for c in all_library_deps] deps_dex_files = [c['dex_path'] for c in all_library_deps]
if requires_javac_classpath: if requires_classpath:
extra_jars = [] extra_jars = []
if options.extra_classpath_jars: if options.extra_classpath_jars:
extra_jars += build_utils.ParseGnList(options.extra_classpath_jars) extra_jars += build_utils.ParseGnList(options.extra_classpath_jars)
...@@ -612,8 +607,7 @@ def main(argv): ...@@ -612,8 +607,7 @@ def main(argv):
c['jar_path'] for c in classpath_deps.Direct('java_library')] c['jar_path'] for c in classpath_deps.Direct('java_library')]
javac_classpath = [c['jar_path'] for c in direct_library_deps] javac_classpath = [c['jar_path'] for c in direct_library_deps]
if requires_full_classpath: java_full_classpath = [c['jar_path'] for c in all_library_deps]
java_full_classpath = [c['jar_path'] for c in all_library_deps]
if extra_jars: if extra_jars:
deps_info['extra_classpath_jars'] = extra_jars deps_info['extra_classpath_jars'] = extra_jars
...@@ -693,15 +687,13 @@ def main(argv): ...@@ -693,15 +687,13 @@ def main(argv):
dex_config = config['final_dex'] dex_config = config['final_dex']
dex_config['dependency_dex_files'] = deps_dex_files dex_config['dependency_dex_files'] = deps_dex_files
if requires_javac_classpath: if requires_classpath:
config['javac']['classpath'] = javac_classpath config['javac']['classpath'] = javac_classpath
javac_interface_classpath = [ javac_interface_classpath = [
_AsInterfaceJar(p) for p in javac_classpath _AsInterfaceJar(p) for p in javac_classpath
if p not in deps_info.get('extra_classpath_jars', [])] if p not in deps_info.get('extra_classpath_jars', [])]
javac_interface_classpath += deps_info.get('extra_classpath_jars', []) javac_interface_classpath += deps_info.get('extra_classpath_jars', [])
config['javac']['interface_classpath'] = javac_interface_classpath config['javac']['interface_classpath'] = javac_interface_classpath
if requires_full_classpath:
deps_info['java'] = { deps_info['java'] = {
'full_classpath': java_full_classpath, 'full_classpath': java_full_classpath,
} }
......
...@@ -53,12 +53,10 @@ _default_proguard_jar_path = "//third_party/proguard/lib/proguard.jar" ...@@ -53,12 +53,10 @@ _default_proguard_jar_path = "//third_party/proguard/lib/proguard.jar"
# build/android/gyp/util/build_utils.py:ExpandFileArgs # build/android/gyp/util/build_utils.py:ExpandFileArgs
template("write_build_config") { template("write_build_config") {
type = invoker.type type = invoker.type
_is_prebuilt_binary =
defined(invoker.is_prebuilt_binary) && invoker.is_prebuilt_binary
# Don't need to enforce naming scheme for these targets since we never # Don't need to enforce naming scheme for these targets since we never
# consider them in dependency chains. # consider them in dependency chains.
if (!_is_prebuilt_binary && type != "android_apk" && type != "java_binary" && if (type != "android_apk" && type != "java_binary" &&
type != "resource_rewriter" && type != "dist_jar") { type != "resource_rewriter" && type != "dist_jar") {
set_sources_assignment_filter(_java_target_whitelist) set_sources_assignment_filter(_java_target_whitelist)
_parent_invoker = invoker.invoker _parent_invoker = invoker.invoker
...@@ -88,7 +86,7 @@ template("write_build_config") { ...@@ -88,7 +86,7 @@ template("write_build_config") {
type == "android_resources" || type == "deps_dex" || type == "android_resources" || type == "deps_dex" ||
type == "dist_jar" || type == "android_assets" || type == "dist_jar" || type == "android_assets" ||
type == "resource_rewriter" || type == "java_binary" || type == "resource_rewriter" || type == "java_binary" ||
type == "group" || type == "java_prebuilt" || type == "junit_binary") type == "group" || type == "junit_binary")
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
...@@ -192,6 +190,9 @@ template("write_build_config") { ...@@ -192,6 +190,9 @@ template("write_build_config") {
if (requires_android) { if (requires_android) {
args += [ "--requires-android" ] args += [ "--requires-android" ]
} }
if (defined(invoker.is_prebuilt) && invoker.is_prebuilt) {
args += [ "--is-prebuilt" ]
}
if (defined(invoker.bypass_platform_checks) && if (defined(invoker.bypass_platform_checks) &&
invoker.bypass_platform_checks) { invoker.bypass_platform_checks) {
args += [ "--bypass-platform-checks" ] args += [ "--bypass-platform-checks" ]
...@@ -918,50 +919,54 @@ if (enable_java_templates) { ...@@ -918,50 +919,54 @@ if (enable_java_templates) {
# #
# Variables # Variables
# main_class: The class containing the program entry point. # main_class: The class containing the program entry point.
# jar_path: The path to the jar to run. # jar_file: Optional first classpath entry.
# script_name: Name of the script to generate. # script_name: Name of the script to generate.
# build_config: Path to .build_config for the jar (contains classpath). # build_config: Path to .build_config for the jar (contains classpath).
# wrapper_script_args: List of extra arguments to pass to the executable. # wrapper_script_args: List of extra arguments to pass to the executable.
# #
template("java_binary_script") { template("java_binary_script") {
set_sources_assignment_filter([]) action(target_name) {
forward_variables_from(invoker, [ "testonly" ]) forward_variables_from(invoker,
[
"deps",
"testonly",
])
_main_class = invoker.main_class _main_class = invoker.main_class
_build_config = invoker.build_config _build_config = invoker.build_config
_jar_path = invoker.jar_path _script_name = invoker.script_name
_script_name = invoker.script_name
action(target_name) {
script = "//build/android/gyp/create_java_binary_script.py" script = "//build/android/gyp/create_java_binary_script.py"
depfile = "$target_gen_dir/$_script_name.d" depfile = "$target_gen_dir/$_script_name.d"
java_script = "$root_build_dir/bin/$_script_name" _java_script = "$root_build_dir/bin/$_script_name"
inputs = [ inputs = [
_build_config, _build_config,
] ]
outputs = [ outputs = [
java_script, _java_script,
] ]
forward_variables_from(invoker, [ "deps" ])
_rebased_build_config = rebase_path(_build_config, root_build_dir) _rebased_build_config = rebase_path(_build_config, root_build_dir)
args = [ args = [
"--depfile", "--depfile",
rebase_path(depfile, root_build_dir), rebase_path(depfile, root_build_dir),
"--output", "--output",
rebase_path(java_script, root_build_dir), rebase_path(_java_script, root_build_dir),
"--classpath=@FileArg($_rebased_build_config:deps_info:java:full_classpath)",
"--jar-path",
rebase_path(_jar_path, root_build_dir),
"--main-class", "--main-class",
_main_class, _main_class,
] ]
if (defined(invoker.jar_path)) {
_jar_path_list = [ rebase_path(invoker.jar_path, root_build_dir) ]
args += [ "--classpath=$_jar_path_list" ]
}
args += [ "--classpath=@FileArg($_rebased_build_config:deps_info:java:full_classpath)" ]
if (emma_coverage) { if (emma_coverage) {
args += [ args += [
"--classpath", "--classpath",
rebase_path("//third_party/android_tools/sdk/tools/lib/emma.jar", rebase_path("//third_party/android_tools/sdk/tools/lib/emma.jar",
root_build_dir), root_build_dir),
"--noverify",
] ]
args += [ "--noverify" ]
} }
if (defined(invoker.wrapper_script_args)) { if (defined(invoker.wrapper_script_args)) {
args += [ "--" ] + invoker.wrapper_script_args args += [ "--" ] + invoker.wrapper_script_args
...@@ -1332,6 +1337,7 @@ if (enable_java_templates) { ...@@ -1332,6 +1337,7 @@ if (enable_java_templates) {
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
"deps", "deps",
"public_deps",
"testonly", "testonly",
]) ])
...@@ -2039,226 +2045,17 @@ if (enable_java_templates) { ...@@ -2039,226 +2045,17 @@ if (enable_java_templates) {
} }
} }
template("java_prebuilt_impl") {
set_sources_assignment_filter([])
forward_variables_from(invoker, [ "testonly" ])
_supports_android =
defined(invoker.supports_android) && invoker.supports_android
_requires_android =
defined(invoker.requires_android) && invoker.requires_android
assert(defined(invoker.jar_path))
if (defined(invoker.output_name)) {
_output_name = invoker.output_name
} else {
_output_name = get_path_info(invoker.jar_path, "name")
}
_base_path = "${target_gen_dir}/$target_name"
# Jar files can be needed at runtime (by Robolectric tests or java binaries),
# so do not put them under gen/.
_target_dir_name = get_label_info(":$target_name", "dir")
_jar_path = "$root_out_dir/lib.java$_target_dir_name/$_output_name.jar"
_ijar_path =
"$root_out_dir/lib.java$_target_dir_name/$_output_name.interface.jar"
_build_config = _base_path + ".build_config"
if (_supports_android) {
_dex_path = _base_path + ".dex.jar"
}
_deps = []
if (defined(invoker.deps)) {
_deps = invoker.deps
}
_jar_deps = []
if (defined(invoker.jar_dep)) {
_jar_deps = [ invoker.jar_dep ]
}
_template_name = target_name
_build_config_target_name = "${_template_name}__build_config"
_process_jar_target_name = "${_template_name}__process_jar"
_ijar_target_name = "${_template_name}__ijar"
if (_supports_android) {
_dex_target_name = "${_template_name}__dex"
}
_enable_build_hooks =
_supports_android &&
(!defined(invoker.no_build_hooks) || !invoker.no_build_hooks)
if (_enable_build_hooks) {
_deps += [ "//build/android/buildhooks:build_hooks_java" ]
}
# Some testonly targets use their own resources and the code being
# tested will use custom resources so there's no need to enable this
# for testonly targets.
_enable_build_hooks_android =
_enable_build_hooks && _requires_android &&
(!defined(invoker.testonly) || !invoker.testonly)
if (_enable_build_hooks_android) {
_deps += [ "//build/android/buildhooks:build_hooks_android_java" ]
}
write_build_config(_build_config_target_name) {
type = "java_prebuilt"
is_prebuilt_binary = defined(invoker.main_class)
forward_variables_from(invoker,
[
"input_jars_paths",
"proguard_configs",
])
supports_android = _supports_android
requires_android = _requires_android
if (defined(invoker.deps)) {
possible_config_deps = _deps
}
build_config = _build_config
jar_path = _jar_path
if (_supports_android) {
dex_path = _dex_path
}
if (defined(invoker.include_java_resources) &&
invoker.include_java_resources) {
# Use original jar_path because _jar_path points to a library without
# resources.
java_resources_jar = invoker.jar_path
}
}
process_java_prebuilt(_process_jar_target_name) {
forward_variables_from(invoker,
[
"jar_excluded_patterns",
"strip_resource_classes",
])
visibility = [
":$_ijar_target_name",
":$_template_name",
]
if (_supports_android) {
visibility += [ ":$_dex_target_name" ]
}
supports_android = _supports_android
enable_build_hooks = _enable_build_hooks
enable_build_hooks_android = _enable_build_hooks_android
build_config = _build_config
input_jar_path = invoker.jar_path
output_jar_path = _jar_path
deps = [ ":$_build_config_target_name" ] + _deps + _jar_deps
}
generate_interface_jar(_ijar_target_name) {
# Always used the unfiltered .jar to create the interface jar so that
# other targets will resolve filtered classes when depending on
# BuildConfig, NativeLibraries, etc.
input_jar = invoker.jar_path
deps = _deps + _jar_deps
output_jar = _ijar_path
}
if (_supports_android) {
dex(_dex_target_name) {
sources = [
_jar_path,
]
output = _dex_path
deps = [ ":$_process_jar_target_name" ] + _deps + _jar_deps
}
}
if (defined(invoker.main_class)) {
_binary_script_target_name = "${_template_name}__java_binary_script"
java_binary_script(_binary_script_target_name) {
forward_variables_from(invoker,
[
"bootclasspath",
"deps",
"main_class",
"wrapper_script_args",
])
if (!defined(deps)) {
deps = []
}
build_config = _build_config
jar_path = _jar_path
script_name = _template_name
if (defined(invoker.wrapper_script_name)) {
script_name = invoker.wrapper_script_name
}
deps += [ ":$_build_config_target_name" ]
}
}
group(target_name) {
forward_variables_from(invoker,
[
"data",
"data_deps",
"visibility",
])
public_deps = [
":$_ijar_target_name",
":$_process_jar_target_name",
]
if (_supports_android) {
public_deps += [ ":$_dex_target_name" ]
}
if (defined(invoker.main_class)) {
# Some targets use the generated script while building, so make it a dep
# rather than a data_dep.
public_deps += [ ":$_binary_script_target_name" ]
}
}
}
# Compiles and jars a set of java files.
#
# Outputs:
# $jar_path.jar
# $jar_path.interface.jar
#
# Variables
# java_files: List of .java files to compile (same as exists in java_sources_file)
# java_sources_file: Path to file containing list of files to compile.
# chromium_code: If true, enable extra warnings.
# srcjar_deps: List of srcjar dependencies. The .java files contained in the
# dependencies srcjar outputs will be compiled and added to the output jar.
# jar_path: Use this to explicitly set the output jar path. Defaults to
# "${target_gen_dir}/${target_name}.jar.
# javac_args: Additional arguments to pass to javac.
template("compile_java") { template("compile_java") {
set_sources_assignment_filter([])
forward_variables_from(invoker, [ "testonly" ]) forward_variables_from(invoker, [ "testonly" ])
assert(defined(invoker.build_config))
assert(defined(invoker.jar_path))
_build_config = invoker.build_config _build_config = invoker.build_config
_chromium_code = invoker.chromium_code
_requires_android = invoker.requires_android
_chromium_code = false if (defined(invoker.enable_errorprone)) {
if (defined(invoker.chromium_code)) {
_chromium_code = invoker.chromium_code
}
_supports_android = true
if (defined(invoker.supports_android)) {
_supports_android = invoker.supports_android
}
_requires_android =
defined(invoker.requires_android) && invoker.requires_android
_enable_errorprone = use_errorprone_java_compiler
if (!_chromium_code) {
_enable_errorprone = false
} else if (defined(invoker.enable_errorprone)) {
_enable_errorprone = invoker.enable_errorprone _enable_errorprone = invoker.enable_errorprone
} else {
_enable_errorprone = use_errorprone_java_compiler && _chromium_code
} }
_provider_configurations = [] _provider_configurations = []
...@@ -2302,9 +2099,6 @@ if (enable_java_templates) { ...@@ -2302,9 +2099,6 @@ if (enable_java_templates) {
} }
_java_srcjars = [] _java_srcjars = []
if (defined(invoker.srcjars)) {
_java_srcjars = invoker.srcjars
}
foreach(dep, _srcjar_deps) { foreach(dep, _srcjar_deps) {
_dep_gen_dir = get_label_info(dep, "target_gen_dir") _dep_gen_dir = get_label_info(dep, "target_gen_dir")
_dep_name = get_label_info(dep, "name") _dep_name = get_label_info(dep, "name")
...@@ -2316,31 +2110,11 @@ if (enable_java_templates) { ...@@ -2316,31 +2110,11 @@ if (enable_java_templates) {
_javac_args = invoker.javac_args _javac_args = invoker.javac_args
} }
# Mark srcjar_deps as used. _javac_target_name = target_name
assert(_srcjar_deps == [] || true) if (defined(invoker.instrumented_jar_path)) {
_javac_target_name = "${target_name}__javac"
_javac_target_name = "${target_name}__javac"
_process_prebuilt_target_name = "${target_name}__process_prebuilt"
_ijar_target_name = "${target_name}__ijar"
_final_target_name = target_name
_final_jar_path = invoker.jar_path
_javac_jar_path = "$target_gen_dir/$target_name.javac.jar"
_process_prebuilt_jar_path = _final_jar_path
_final_ijar_path = get_path_info(_final_jar_path, "dir") + "/" +
get_path_info(_final_jar_path, "name") + ".interface.jar"
_emma_instrument = defined(invoker.emma_instrument) &&
invoker.emma_instrument && invoker.java_files != []
if (_emma_instrument) {
_emma_instr_target_name = "${target_name}__emma_instr"
_process_prebuilt_jar_path =
"$target_gen_dir/$target_name.process_prebuilt.jar"
} }
_rebased_build_config = rebase_path(_build_config, root_build_dir)
_rebased_jar_path = rebase_path(_javac_jar_path, root_build_dir)
action(_javac_target_name) { action(_javac_target_name) {
script = "//build/android/gyp/javac.py" script = "//build/android/gyp/javac.py"
depfile = "$target_gen_dir/$target_name.d" depfile = "$target_gen_dir/$target_name.d"
...@@ -2350,22 +2124,22 @@ if (enable_java_templates) { ...@@ -2350,22 +2124,22 @@ if (enable_java_templates) {
} }
outputs = [ outputs = [
_javac_jar_path, invoker.javac_jar_path,
_javac_jar_path + ".md5.stamp", invoker.javac_jar_path + ".md5.stamp",
]
sources = invoker.java_files + _java_srcjars
inputs = [
_build_config,
] ]
inputs = invoker.java_files + _java_srcjars + [ _build_config ]
if (invoker.java_files != []) { if (invoker.java_files != []) {
inputs += [ invoker.java_sources_file ] inputs += [ invoker.java_sources_file ]
} }
_rebased_build_config = rebase_path(_build_config, root_build_dir)
_rebased_javac_jar_path =
rebase_path(invoker.javac_jar_path, root_build_dir)
_rebased_java_srcjars = rebase_path(_java_srcjars, root_build_dir) _rebased_java_srcjars = rebase_path(_java_srcjars, root_build_dir)
_rebased_depfile = rebase_path(depfile, root_build_dir) _rebased_depfile = rebase_path(depfile, root_build_dir)
args = [ args = [
"--depfile=$_rebased_depfile", "--depfile=$_rebased_depfile",
"--jar-path=$_rebased_jar_path", "--jar-path=$_rebased_javac_jar_path",
"--java-srcjars=$_rebased_java_srcjars", "--java-srcjars=$_rebased_java_srcjars",
"--java-srcjars=@FileArg($_rebased_build_config:javac:srcjars)", "--java-srcjars=@FileArg($_rebased_build_config:javac:srcjars)",
"--java-version=1.8", "--java-version=1.8",
...@@ -2380,7 +2154,7 @@ if (enable_java_templates) { ...@@ -2380,7 +2154,7 @@ if (enable_java_templates) {
args += [ "--incremental" ] args += [ "--incremental" ]
deps += [ "//third_party/jmake($default_toolchain)" ] deps += [ "//third_party/jmake($default_toolchain)" ]
inputs += [ "$root_build_dir/bin/jmake" ] inputs += [ "$root_build_dir/bin/jmake" ]
outputs += [ "${_javac_jar_path}.pdb" ] outputs += [ "${invoker.javac_jar_path}.pdb" ]
} }
if (_requires_android) { if (_requires_android) {
if (defined(invoker.alternative_android_sdk_ijar)) { if (defined(invoker.alternative_android_sdk_ijar)) {
...@@ -2402,12 +2176,11 @@ if (enable_java_templates) { ...@@ -2402,12 +2176,11 @@ if (enable_java_templates) {
args += [ "--chromium-code=1" ] args += [ "--chromium-code=1" ]
} }
if (_enable_errorprone) { if (_enable_errorprone) {
deps += deps += [ "//third_party/errorprone:errorprone($default_toolchain)" ]
[ "//third_party/errorprone:errorprone_java($default_toolchain)" ]
deps += [ "//tools/android/errorprone_plugin:errorprone_plugin_java($default_toolchain)" ] deps += [ "//tools/android/errorprone_plugin:errorprone_plugin_java($default_toolchain)" ]
args += [ args += [
"--use-errorprone-path", "--use-errorprone-path",
"bin/errorprone_java", "bin/errorprone",
"--processorpath", "--processorpath",
"lib.java/tools/android/errorprone_plugin/errorprone_plugin_java.jar", "lib.java/tools/android/errorprone_plugin/errorprone_plugin_java.jar",
] ]
...@@ -2436,31 +2209,8 @@ if (enable_java_templates) { ...@@ -2436,31 +2209,8 @@ if (enable_java_templates) {
} }
} }
process_java_prebuilt(_process_prebuilt_target_name) { if (defined(invoker.instrumented_jar_path)) {
forward_variables_from(invoker, emma_instr(target_name) {
[
"alternative_android_sdk_ijar",
"alternative_android_sdk_ijar_dep",
"alternative_android_sdk_jar",
"enable_build_hooks",
"enable_build_hooks_android",
"jar_excluded_patterns",
])
supports_android = _supports_android
build_config = _build_config
input_jar_path = _javac_jar_path
output_jar_path = _process_prebuilt_jar_path
deps = [
":$_javac_target_name",
]
if (defined(invoker.deps)) {
deps += invoker.deps
}
}
if (_emma_instrument) {
emma_instr(_emma_instr_target_name) {
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
"deps", "deps",
...@@ -2468,37 +2218,11 @@ if (enable_java_templates) { ...@@ -2468,37 +2218,11 @@ if (enable_java_templates) {
"java_sources_file", "java_sources_file",
]) ])
input_jar_path = _process_prebuilt_jar_path input_jar_path = invoker.javac_jar_path
output_jar_path = _final_jar_path output_jar_path = invoker.instrumented_jar_path
public_deps = [
if (!defined(deps)) { ":$_javac_target_name",
deps = [] ]
}
deps += [ ":$_process_prebuilt_target_name" ]
}
}
generate_interface_jar(_ijar_target_name) {
# Always used the unfiltered .jar to create the interface jar so that
# other targets will resolve filtered classes when depending on
# BuildConfig, NativeLibraries, etc.
input_jar = _javac_jar_path
deps = [
":$_javac_target_name",
]
output_jar = _final_ijar_path
}
group(_final_target_name) {
forward_variables_from(invoker, [ "visibility" ])
public_deps = [
":$_ijar_target_name",
":$_javac_target_name",
]
if (_emma_instrument) {
public_deps += [ ":$_emma_instr_target_name" ]
} else {
public_deps += [ ":$_process_prebuilt_target_name" ]
} }
} }
} }
...@@ -2506,49 +2230,76 @@ if (enable_java_templates) { ...@@ -2506,49 +2230,76 @@ if (enable_java_templates) {
template("java_library_impl") { template("java_library_impl") {
set_sources_assignment_filter([]) set_sources_assignment_filter([])
forward_variables_from(invoker, [ "testonly" ]) forward_variables_from(invoker, [ "testonly" ])
_accumulated_deps = [] _template_name = target_name
if (defined(invoker.deps)) { _is_prebuilt = defined(invoker.jar_path)
_accumulated_deps = invoker.deps _is_java_binary = defined(invoker.is_java_binary) && invoker.is_java_binary
_java_files = []
if (defined(invoker.java_files)) {
_java_files = invoker.java_files
}
_srcjar_deps = []
if (defined(invoker.srcjar_deps)) {
_srcjar_deps = invoker.srcjar_deps
} }
_has_sources = _java_files != [] || _srcjar_deps != []
# Caller overriding build config must have valid java sources file if it has if (_is_prebuilt) {
# java files. assert(!_has_sources)
assert(!defined(invoker.override_build_config) || } else {
!defined(invoker.java_files) || defined(invoker.java_sources_file)) # Caller overriding build config must have valid java sources file if it has
# java files.
assert(!defined(invoker.override_build_config) || _java_files == [] ||
defined(invoker.java_sources_file))
assert(defined(invoker.java_files) || defined(invoker.srcjars) || # Allow java_binary to not specify any sources. This is needed when a prebuilt
defined(invoker.srcjar_deps)) # is needed as a library as well as a binary.
_base_path = "$target_gen_dir/$target_name" assert(_is_java_binary || _has_sources)
assert(_base_path != "") # Mark as used }
if (defined(invoker.output_name)) { if (_is_java_binary) {
_output_name = invoker.output_name assert(defined(invoker.main_class), "java_binary() must set main_class")
} else { } else {
_output_name = target_name assert(!defined(invoker.main_class),
"Use java_binary() to set main_class")
} }
# Jar files can be needed at runtime (by Robolectric tests or java binaries), if (_is_prebuilt || _has_sources) {
# so do not put them under gen/. if (defined(invoker.output_name)) {
target_dir_name = get_label_info(":$target_name", "dir") _output_name = invoker.output_name
_jar_path = "$root_out_dir/lib.java$target_dir_name/$_output_name.jar" } else if (_is_prebuilt) {
if (defined(invoker.jar_path)) { _output_name = get_path_info(invoker.jar_path, "name")
_jar_path = invoker.jar_path } else {
} _output_name = target_name
_template_name = target_name }
_final_deps = [] # Jar files can be needed at runtime (by Robolectric tests or java binaries),
# so do not put them under gen/.
_target_dir_name = get_label_info(":$target_name", "dir")
_final_jar_path =
"$root_out_dir/lib.java$_target_dir_name/$_output_name.jar"
if (defined(invoker.final_jar_path)) {
_final_jar_path = invoker.final_jar_path
}
}
_supports_android = _supports_android =
defined(invoker.supports_android) && invoker.supports_android defined(invoker.supports_android) && invoker.supports_android
_requires_android = _requires_android =
defined(invoker.requires_android) && invoker.requires_android defined(invoker.requires_android) && invoker.requires_android
assert(_requires_android || true) # Mark as used. assert(_requires_android || true) # Mark as used.
_android_manifest = "//build/android/AndroidManifest.xml" _android_manifest = "//build/android/AndroidManifest.xml"
if (defined(invoker.android_manifest)) { if (defined(invoker.android_manifest)) {
_android_manifest = invoker.android_manifest _android_manifest = invoker.android_manifest
} }
assert(_android_manifest != "") # Mark as used. assert(_android_manifest != "") # Mark as used.
_accumulated_deps = []
if (defined(invoker.deps)) {
_accumulated_deps = invoker.deps
}
_enable_build_hooks = _enable_build_hooks =
_supports_android && _supports_android &&
(!defined(invoker.no_build_hooks) || !invoker.no_build_hooks) (!defined(invoker.no_build_hooks) || !invoker.no_build_hooks)
...@@ -2572,57 +2323,52 @@ if (enable_java_templates) { ...@@ -2572,57 +2323,52 @@ if (enable_java_templates) {
if (defined(invoker.chromium_code)) { if (defined(invoker.chromium_code)) {
_chromium_code = invoker.chromium_code _chromium_code = invoker.chromium_code
} else { } else {
_chromium_code = defined(invoker.java_files) && invoker.java_files != [] # Default based on whether target is in third_party.
if (_chromium_code) { set_sources_assignment_filter([ "*\bthird_party\b*" ])
# Make chromium_code = false be the default for targets within sources = [
# third_party which contain no chromium-namespaced java files. get_label_info(":$target_name", "dir"),
set_sources_assignment_filter([ "*\bthird_party\b*" ]) ]
sources = [ _chromium_code = sources != []
get_label_info(":$target_name", "dir"), if (!_chromium_code && !_is_prebuilt && _java_files != []) {
] # Unless third_party code has an org.chromium file in it.
if (sources == []) { set_sources_assignment_filter([ "*\bchromium\b*" ])
set_sources_assignment_filter([ "*\bchromium\b*" ]) sources = _java_files
sources = invoker.java_files _chromium_code = _java_files != sources
_chromium_code = invoker.java_files != sources
}
set_sources_assignment_filter([])
sources = []
} }
set_sources_assignment_filter([])
sources = []
} }
_emma_never_instrument = !_chromium_code if (_supports_android && defined(_final_jar_path)) {
if (defined(invoker.emma_never_instrument)) { _dex_path = "$target_gen_dir/$target_name.dex.jar"
_emma_never_instrument = invoker.emma_never_instrument
}
assert(_emma_never_instrument || true) # Mark as used
_emma_instrument = emma_coverage && !_emma_never_instrument
if (_supports_android) {
_dex_path = _base_path + ".dex.jar"
if (defined(invoker.dex_path)) { if (defined(invoker.dex_path)) {
_dex_path = invoker.dex_path _dex_path = invoker.dex_path
} }
} }
_java_files = []
if (defined(invoker.java_files)) {
_java_files += invoker.java_files
}
if (_java_files != []) { if (_java_files != []) {
_java_sources_file = "$target_gen_dir/$target_name.sources"
if (defined(invoker.java_sources_file)) { if (defined(invoker.java_sources_file)) {
_java_sources_file = invoker.java_sources_file _java_sources_file = invoker.java_sources_file
} else {
_java_sources_file = "$_base_path.sources"
} }
write_file(_java_sources_file, rebase_path(_java_files, root_build_dir)) write_file(_java_sources_file, rebase_path(_java_files, root_build_dir))
} }
_emma_instrument = emma_coverage && !_chromium_code && _has_sources
if (defined(invoker.emma_never_instrument)) {
_emma_instrument = !invoker.emma_never_instrument && _emma_instrument
}
if (_emma_instrument) {
_instrumented_jar_path = "$target_gen_dir/$target_name.instrumented.jar"
}
# Define build_config_deps which will be a list of targets required to # Define build_config_deps which will be a list of targets required to
# build the _build_config. # build the _build_config.
if (defined(invoker.override_build_config)) { if (defined(invoker.override_build_config)) {
_build_config = invoker.override_build_config _build_config = invoker.override_build_config
} else { } else {
_build_config = _base_path + ".build_config" _build_config = "$target_gen_dir/$target_name.build_config"
build_config_target_name = "${_template_name}__build_config" build_config_target_name = "${_template_name}__build_config"
write_build_config(build_config_target_name) { write_build_config(build_config_target_name) {
...@@ -2635,11 +2381,12 @@ if (enable_java_templates) { ...@@ -2635,11 +2381,12 @@ if (enable_java_templates) {
"main_class", "main_class",
"proguard_configs", "proguard_configs",
]) ])
if (defined(invoker.is_java_binary) && invoker.is_java_binary) { if (_is_java_binary) {
type = "java_binary" type = "java_binary"
} else { } else {
type = "java_library" type = "java_library"
} }
is_prebuilt = _is_prebuilt
possible_config_deps = _accumulated_deps possible_config_deps = _accumulated_deps
supports_android = _supports_android supports_android = _supports_android
requires_android = _requires_android requires_android = _requires_android
...@@ -2647,21 +2394,27 @@ if (enable_java_templates) { ...@@ -2647,21 +2394,27 @@ if (enable_java_templates) {
invoker.bypass_platform_checks invoker.bypass_platform_checks
build_config = _build_config build_config = _build_config
jar_path = _jar_path if (!_is_java_binary && defined(_final_jar_path)) {
if (_supports_android) { jar_path = _final_jar_path
}
if (defined(_dex_path)) {
dex_path = _dex_path dex_path = _dex_path
} }
if (_java_files != []) { if (_java_files != []) {
java_sources_file = _java_sources_file java_sources_file = _java_sources_file
} }
if (defined(invoker.srcjar_deps)) { bundled_srcjars = []
bundled_srcjars = [] foreach(d, _srcjar_deps) {
foreach(d, invoker.srcjar_deps) { _dep_gen_dir = get_label_info(d, "target_gen_dir")
_dep_gen_dir = get_label_info(d, "target_gen_dir") _dep_name = get_label_info(d, "name")
_dep_name = get_label_info(d, "name") bundled_srcjars += [ "$_dep_gen_dir/$_dep_name.srcjar" ]
bundled_srcjars += [ "$_dep_gen_dir/$_dep_name.srcjar" ] }
} if (defined(invoker.include_java_resources) &&
invoker.include_java_resources) {
# Use original jar_path because _jar_path points to a library without
# resources.
java_resources_jar = invoker.jar_path
} }
} }
_accumulated_deps += [ ":$build_config_target_name" ] _accumulated_deps += [ ":$build_config_target_name" ]
...@@ -2670,97 +2423,54 @@ if (enable_java_templates) { ...@@ -2670,97 +2423,54 @@ if (enable_java_templates) {
_accumulated_deps += invoker.classpath_deps _accumulated_deps += invoker.classpath_deps
} }
_srcjar_deps = [] # TODO(agrieve): Enable lint for _has_sources rather than just _java_files.
if (defined(invoker.srcjar_deps)) { _has_lint_target = _java_files != [] && _supports_android && _chromium_code
_srcjar_deps = invoker.srcjar_deps if (_has_sources) {
} _javac_jar_path = "$target_gen_dir/$target_name.javac.jar"
_compile_java_target = "${_template_name}__compile_java"
_srcjars = [] compile_java(_compile_java_target) {
if (defined(invoker.srcjars)) {
_srcjars = invoker.srcjars
}
assert(_java_files != [] || _srcjar_deps != [] || _srcjars != [])
_compile_java_target = "${_template_name}__compile_java"
_final_deps += [ ":$_compile_java_target" ]
compile_java(_compile_java_target) {
forward_variables_from(invoker,
[
"additional_jar_files",
"alternative_android_sdk_ijar",
"alternative_android_sdk_ijar_dep",
"alternative_android_sdk_jar",
"dist_jar_path",
"enable_errorprone",
"enable_incremental_javac_override",
"jar_excluded_patterns",
"manifest_entries",
"processors_javac",
"processor_args_javac",
"provider_configurations",
"javac_args",
])
jar_path = _jar_path
build_config = _build_config
java_files = _java_files
if (_java_files != []) {
java_sources_file = _java_sources_file
}
srcjar_deps = _srcjar_deps
srcjars = _srcjars
chromium_code = _chromium_code
supports_android = _supports_android
requires_android = _requires_android
emma_instrument = _emma_instrument
enable_build_hooks = _enable_build_hooks
enable_build_hooks_android = _enable_build_hooks_android
deps = _accumulated_deps
}
_accumulated_deps += [ ":$_compile_java_target" ]
assert(_accumulated_deps != []) # Mark used.
if (defined(invoker.main_class)) {
# Targets might use the generated script while building, so make it a dep
# rather than a data_dep.
_final_deps += [ ":${_template_name}__java_binary_script" ]
java_binary_script("${_template_name}__java_binary_script") {
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
"bootclasspath", "additional_jar_files",
"main_class", "alternative_android_sdk_ijar",
"wrapper_script_args", "alternative_android_sdk_ijar_dep",
"enable_errorprone",
"enable_incremental_javac_override",
"manifest_entries",
"processors_javac",
"processor_args_javac",
"provider_configurations",
"javac_args",
]) ])
build_config = _build_config build_config = _build_config
jar_path = _jar_path java_files = _java_files
script_name = _template_name if (_java_files != []) {
if (defined(invoker.wrapper_script_name)) { java_sources_file = _java_sources_file
script_name = invoker.wrapper_script_name
} }
srcjar_deps = _srcjar_deps
chromium_code = _chromium_code
requires_android = _requires_android
deps = _accumulated_deps deps = _accumulated_deps
javac_jar_path = _javac_jar_path
if (_emma_instrument) {
instrumented_jar_path = _instrumented_jar_path
}
} }
} _accumulated_deps += [ ":$_compile_java_target" ]
_has_lint_target = false if (_has_lint_target) {
if (_supports_android) {
if (_chromium_code) {
_has_lint_target = true
android_lint("${_template_name}__lint") { android_lint("${_template_name}__lint") {
if (defined(invoker.lint_suppressions_file)) {
lint_suppressions_file = invoker.lint_suppressions_file
}
android_manifest = _android_manifest
build_config = _build_config build_config = _build_config
android_manifest = _android_manifest
# Run lint on javac output. jar_path = _javac_jar_path
jar_path = "$target_gen_dir/$_compile_java_target.javac.jar" deps = _accumulated_deps
java_files = _java_files java_files = _java_files
if (_java_files != []) { if (_java_files != []) {
java_sources_file = _java_sources_file java_sources_file = _java_sources_file
} }
deps = _accumulated_deps if (defined(invoker.lint_suppressions_file)) {
lint_suppressions_file = invoker.lint_suppressions_file
}
if (_emma_instrument) { if (_emma_instrument) {
# Disable the NewApi lint warning when building with coverage # Disable the NewApi lint warning when building with coverage
# enabled. Coverage seems to mess with how the linter detects # enabled. Coverage seems to mess with how the linter detects
...@@ -2779,17 +2489,90 @@ if (enable_java_templates) { ...@@ -2779,17 +2489,90 @@ if (enable_java_templates) {
] ]
} }
} }
} # _has_sources
_final_deps += [ ":${_template_name}__dex" ] if (defined(_final_jar_path)) {
dex("${_template_name}__dex") { _process_prebuilt_target_name = "${target_name}__process_prebuilt"
sources = [ process_java_prebuilt(_process_prebuilt_target_name) {
_jar_path, forward_variables_from(invoker,
] [
output = _dex_path "alternative_android_sdk_ijar",
deps = [ "alternative_android_sdk_ijar_dep",
":$_compile_java_target", "alternative_android_sdk_jar",
] "jar_excluded_patterns",
])
supports_android = _supports_android
enable_build_hooks = _enable_build_hooks
enable_build_hooks_android = _enable_build_hooks_android
build_config = _build_config
if (_is_prebuilt) {
input_jar_path = invoker.jar_path
} else if (_emma_instrument) {
input_jar_path = _instrumented_jar_path
} else {
input_jar_path = _javac_jar_path
}
output_jar_path = _final_jar_path
deps = _accumulated_deps
} }
_accumulated_deps += [ ":$_process_prebuilt_target_name" ]
if (defined(_dex_path)) {
dex("${target_name}__dex") {
sources = [
_final_jar_path,
]
output = _dex_path
deps = [
":$_process_prebuilt_target_name",
]
}
_accumulated_deps += [ ":${target_name}__dex" ]
}
_final_ijar_path =
get_path_info(_final_jar_path, "dir") + "/" +
get_path_info(_final_jar_path, "name") + ".interface.jar"
_ijar_target_name = "${target_name}__ijar"
generate_interface_jar(_ijar_target_name) {
# Always used the unfiltered .jar to create the interface jar so that
# other targets will resolve filtered classes when depending on
# BuildConfig, NativeLibraries, etc.
if (_is_prebuilt) {
input_jar = invoker.jar_path
forward_variables_from(invoker, [ "deps" ])
} else {
input_jar = _javac_jar_path
deps = [
":$_compile_java_target",
]
}
output_jar = _final_ijar_path
}
_accumulated_deps += [ ":$_ijar_target_name" ]
}
if (_is_java_binary) {
# Targets might use the generated script while building, so make it a dep
# rather than a data_dep.
java_binary_script("${target_name}__java_binary_script") {
forward_variables_from(invoker,
[
"bootclasspath",
"main_class",
"wrapper_script_args",
])
build_config = _build_config
if (defined(_final_jar_path)) {
jar_path = _final_jar_path
}
script_name = _template_name
if (defined(invoker.wrapper_script_name)) {
script_name = invoker.wrapper_script_name
}
deps = _accumulated_deps
}
_accumulated_deps += [ ":${target_name}__java_binary_script" ]
} }
group(target_name) { group(target_name) {
...@@ -2799,11 +2582,11 @@ if (enable_java_templates) { ...@@ -2799,11 +2582,11 @@ if (enable_java_templates) {
"data_deps", "data_deps",
"visibility", "visibility",
]) ])
if (!defined(data_deps)) { public_deps = _accumulated_deps
data_deps = []
}
public_deps = _final_deps
if (_has_lint_target) { if (_has_lint_target) {
if (!defined(data_deps)) {
data_deps = []
}
data_deps += [ ":${_template_name}__analysis" ] data_deps += [ ":${_template_name}__analysis" ]
} }
} }
......
...@@ -1052,11 +1052,11 @@ if (enable_java_templates) { ...@@ -1052,11 +1052,11 @@ if (enable_java_templates) {
# will be included in the executable (and the javac classpath). # will be included in the executable (and the javac classpath).
# classpath_deps: Deps that should added to the classpath for this target, # classpath_deps: Deps that should added to the classpath for this target,
# but not linked into the apk (use this for annotation processors). # but not linked into the apk (use this for annotation processors).
# jar_path: Path to a prebuilt jar. Mutually exclusive with java_files &
# srcjar_deps.
# java_files: List of .java files included in this library. # java_files: List of .java files included in this library.
# srcjar_deps: List of srcjar dependencies. The .java files in the srcjars # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
# will be added to java_files and be included in this library. # will be added to java_files and be included in this library.
# srcjars: List of srcjars to be included in this library, together with the
# ones obtained from srcjar_deps.
# bypass_platform_checks: Disables checks about cross-platform (Java/Android) # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
# dependencies for this target. This will allow depending on an # dependencies for this target. This will allow depending on an
# android_library target, for example. # android_library target, for example.
...@@ -1077,13 +1077,16 @@ if (enable_java_templates) { ...@@ -1077,13 +1077,16 @@ if (enable_java_templates) {
# deps = [ ":bar_java" ] # deps = [ ":bar_java" ]
# main_class = "org.chromium.foo.FooMain" # main_class = "org.chromium.foo.FooMain"
# } # }
#
# java_binary("foo") {
# jar_path = "lib/prebuilt.jar"
# deps = [ ":bar_java" ]
# main_class = "org.chromium.foo.FooMain"
# }
template("java_binary") { template("java_binary") {
java_library_impl(target_name) { java_library_impl(target_name) {
forward_variables_from(invoker, "*") forward_variables_from(invoker, "*")
supports_android = false
main_class = invoker.main_class
is_java_binary = true is_java_binary = true
assert(is_java_binary) # Mark as used.
} }
} }
...@@ -1099,8 +1102,6 @@ if (enable_java_templates) { ...@@ -1099,8 +1102,6 @@ if (enable_java_templates) {
# java_files: List of .java files included in this library. # java_files: List of .java files included in this library.
# srcjar_deps: List of srcjar dependencies. The .java files in the srcjars # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
# will be added to java_files and be included in this library. # will be added to java_files and be included in this library.
# srcjars: List of srcjars to be included in this library, together with the
# ones obtained from srcjar_deps.
# #
# chromium_code: If true, extra analysis warning/errors will be enabled. # chromium_code: If true, extra analysis warning/errors will be enabled.
# #
...@@ -1147,8 +1148,6 @@ if (enable_java_templates) { ...@@ -1147,8 +1148,6 @@ if (enable_java_templates) {
if (defined(_java_sources_file)) { if (defined(_java_sources_file)) {
java_sources_file = _java_sources_file java_sources_file = _java_sources_file
} }
_target_dir_name = get_label_info(":$target_name", "dir")
jar_path = "$root_out_dir/lib.java$_target_dir_name/$target_name.jar"
} }
if (defined(invoker.classpath_deps)) { if (defined(invoker.classpath_deps)) {
...@@ -1218,8 +1217,6 @@ if (enable_java_templates) { ...@@ -1218,8 +1217,6 @@ if (enable_java_templates) {
# java_files: List of .java files included in this library. # java_files: List of .java files included in this library.
# srcjar_deps: List of srcjar dependencies. The .java files in the srcjars # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
# will be added to java_files and be included in this library. # will be added to java_files and be included in this library.
# srcjars: List of srcjars to be included in this library, together with the
# ones obtained from srcjar_deps.
# #
# input_jars_paths: A list of paths to the jars that should be included # input_jars_paths: A list of paths to the jars that should be included
# in the classpath. These are in addition to library .jars that # in the classpath. These are in addition to library .jars that
...@@ -1284,7 +1281,6 @@ if (enable_java_templates) { ...@@ -1284,7 +1281,6 @@ if (enable_java_templates) {
# deps: Specifies the dependencies of this target. Java targets in this list # deps: Specifies the dependencies of this target. Java targets in this list
# will be added to the javac classpath. # will be added to the javac classpath.
# jar_path: Path to the prebuilt jar. # jar_path: Path to the prebuilt jar.
# jar_dep: Target that builds jar_path (optional).
# main_class: When specified, a wrapper script is created within # main_class: When specified, a wrapper script is created within
# $root_build_dir/bin to launch the binary with the given class as the # $root_build_dir/bin to launch the binary with the given class as the
# entrypoint. # entrypoint.
...@@ -1305,7 +1301,7 @@ if (enable_java_templates) { ...@@ -1305,7 +1301,7 @@ if (enable_java_templates) {
# ] # ]
# } # }
template("java_prebuilt") { template("java_prebuilt") {
java_prebuilt_impl(target_name) { java_library_impl(target_name) {
forward_variables_from(invoker, "*") forward_variables_from(invoker, "*")
} }
} }
...@@ -1496,8 +1492,6 @@ if (enable_java_templates) { ...@@ -1496,8 +1492,6 @@ if (enable_java_templates) {
# java_files: List of .java files included in this library. # java_files: List of .java files included in this library.
# srcjar_deps: List of srcjar dependencies. The .java files in the srcjars # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
# will be added to java_files and be included in this library. # will be added to java_files and be included in this library.
# srcjars: List of srcjars to be included in this library, together with the
# ones obtained from srcjar_deps.
# #
# input_jars_paths: A list of paths to the jars that should be included # input_jars_paths: A list of paths to the jars that should be included
# in the classpath. These are in addition to library .jars that # in the classpath. These are in addition to library .jars that
...@@ -1550,17 +1544,14 @@ if (enable_java_templates) { ...@@ -1550,17 +1544,14 @@ if (enable_java_templates) {
# ] # ]
# } # }
template("android_library") { template("android_library") {
assert(!defined(invoker.jar_path),
"android_library does not support a custom jar path")
if (defined(invoker.alternative_android_sdk_ijar)) {
assert(defined(invoker.alternative_android_sdk_ijar_dep))
assert(defined(invoker.alternative_android_sdk_jar))
}
java_library_impl(target_name) { java_library_impl(target_name) {
forward_variables_from(invoker, "*") forward_variables_from(invoker, "*")
if (defined(alternative_android_sdk_ijar)) {
assert(defined(alternative_android_sdk_ijar_dep))
assert(defined(alternative_android_sdk_jar))
}
supports_android = true supports_android = true
requires_android = true requires_android = true
...@@ -1618,11 +1609,8 @@ if (enable_java_templates) { ...@@ -1618,11 +1609,8 @@ if (enable_java_templates) {
# ] # ]
# } # }
template("android_java_prebuilt") { template("android_java_prebuilt") {
java_prebuilt_impl(target_name) { android_library(target_name) {
forward_variables_from(invoker, "*") forward_variables_from(invoker, "*")
supports_android = true
requires_android = true
strip_resource_classes = true
} }
} }
...@@ -1732,6 +1720,7 @@ if (enable_java_templates) { ...@@ -1732,6 +1720,7 @@ if (enable_java_templates) {
_lib_dex_path = "$_base_path.dex.jar" _lib_dex_path = "$_base_path.dex.jar"
_rebased_lib_dex_path = rebase_path(_lib_dex_path, root_build_dir) _rebased_lib_dex_path = rebase_path(_lib_dex_path, root_build_dir)
_template_name = target_name _template_name = target_name
_emma_never_instrument = defined(invoker.testonly) && invoker.testonly
if (defined(invoker.java_files)) { if (defined(invoker.java_files)) {
_java_sources_file = "$_base_path.sources" _java_sources_file = "$_base_path.sources"
} }
...@@ -1953,7 +1942,6 @@ if (enable_java_templates) { ...@@ -1953,7 +1942,6 @@ if (enable_java_templates) {
_proguard_output_jar_path = "$_base_path.proguard.jar" _proguard_output_jar_path = "$_base_path.proguard.jar"
} }
_emma_never_instrument = defined(invoker.testonly) && invoker.testonly
_incremental_allowed = _incremental_allowed =
!(defined(invoker.never_incremental) && invoker.never_incremental) !(defined(invoker.never_incremental) && invoker.never_incremental)
...@@ -2187,7 +2175,7 @@ if (enable_java_templates) { ...@@ -2187,7 +2175,7 @@ if (enable_java_templates) {
android_manifest = _android_manifest android_manifest = _android_manifest
srcjar_deps = _srcjar_deps srcjar_deps = _srcjar_deps
jar_path = _jar_path final_jar_path = _jar_path
dex_path = _lib_dex_path dex_path = _lib_dex_path
emma_never_instrument = _emma_never_instrument emma_never_instrument = _emma_never_instrument
if (defined(_java_sources_file)) { if (defined(_java_sources_file)) {
......
...@@ -926,7 +926,7 @@ action("extract_cronet_jars") { ...@@ -926,7 +926,7 @@ action("extract_cronet_jars") {
sources = [] sources = []
foreach(dep, deps) { foreach(dep, deps) {
sources += [ get_label_info(dep, "target_gen_dir") + "/" + sources += [ get_label_info(dep, "target_gen_dir") + "/" +
get_label_info(dep, "name") + "__compile_java.javac.jar" ] get_label_info(dep, "name") + ".javac.jar" ]
} }
_rebased_sources = rebase_path(sources, root_build_dir) _rebased_sources = rebase_path(sources, root_build_dir)
...@@ -1232,8 +1232,8 @@ template("copy_java8_jars") { ...@@ -1232,8 +1232,8 @@ template("copy_java8_jars") {
_deps = [] _deps = []
foreach(dep, invoker.deps) { foreach(dep, invoker.deps) {
_dep_name = get_label_info(dep, "name") _dep_name = get_label_info(dep, "name")
_source_jar = get_label_info(dep, "target_gen_dir") + "/" + _dep_name + _source_jar =
"__compile_java.javac.jar" get_label_info(dep, "target_gen_dir") + "/" + _dep_name + ".javac.jar"
_output_jar = "$_package_dir/" + _dep_name + ".jar" _output_jar = "$_package_dir/" + _dep_name + ".jar"
# cronet_api.jar is a special case. Its file name is # cronet_api.jar is a special case. Its file name is
...@@ -1242,9 +1242,7 @@ template("copy_java8_jars") { ...@@ -1242,9 +1242,7 @@ template("copy_java8_jars") {
_output_jar = "$_package_dir/" + "cronet_api.jar" _output_jar = "$_package_dir/" + "cronet_api.jar"
} }
_copy_dep = ":" + _dep_name + "__compile_java__javac"
_copy_target_name = "${target_name}_${dep}" _copy_target_name = "${target_name}_${dep}"
copy(_copy_target_name) { copy(_copy_target_name) {
sources = [ sources = [
_source_jar, _source_jar,
...@@ -1253,7 +1251,7 @@ template("copy_java8_jars") { ...@@ -1253,7 +1251,7 @@ template("copy_java8_jars") {
_output_jar, _output_jar,
] ]
deps = [ deps = [
_copy_dep, ":$_dep_name",
] ]
} }
_deps += [ ":" + _copy_target_name ] _deps += [ ":" + _copy_target_name ]
......
...@@ -5,8 +5,14 @@ ...@@ -5,8 +5,14 @@
import("//build/config/android/rules.gni") import("//build/config/android/rules.gni")
if (current_toolchain == default_toolchain) { if (current_toolchain == default_toolchain) {
java_prebuilt("errorprone_java") { java_library("errorprone_java") {
jar_path = "lib/error_prone_ant-2.1.2.jar" jar_path = "lib/error_prone_ant-2.1.2.jar"
}
java_binary("errorprone") {
deps = [
":errorprone_java",
]
main_class = "com.google.errorprone.ErrorProneCompiler" main_class = "com.google.errorprone.ErrorProneCompiler"
bootclasspath = "$root_build_dir/lib.java/third_party/errorprone/error_prone_ant-2.1.2.jar" bootclasspath = "$root_build_dir/lib.java/third_party/errorprone/error_prone_ant-2.1.2.jar"
} }
......
...@@ -16,8 +16,12 @@ java_library("errorprone_plugin_java") { ...@@ -16,8 +16,12 @@ java_library("errorprone_plugin_java") {
# Necessary to avoid dependency cycle # Necessary to avoid dependency cycle
enable_errorprone = false enable_errorprone = false
# TODO(agrieve): Make it so that you don't need to specify the full classpath
# of annotation processors.
deps = [ deps = [
"//third_party/auto:auto_common_java",
"//third_party/auto:auto_service_java", "//third_party/auto:auto_service_java",
"//third_party/errorprone:errorprone_java", "//third_party/errorprone:errorprone_java",
"//third_party/guava:guava_java",
] ]
} }
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