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,
} }
......
This diff is collapsed.
...@@ -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