0

Reland "jni_generator: Use GN metadata rather than build_config.json for java"

This reverts commit ec6b0118f7.

Reason for reland: Fixed arm64 release builds

Original change's description:
> Revert "jni_generator: Use GN metadata rather than build_config.json for java"
>
> This reverts commit 7c2bc5318e.
>
> Reason for revert: Breaks builds, see https://ci.chromium.org/ui/p/chromium/builders/ci/android-code-coverage-native/14020/overview and https://ci.chromium.org/ui/p/chromium/builders/reviver/coverage-runner/b8777612281650433537/overview
>
> Original change's description:
> > jni_generator: Use GN metadata rather than build_config.json for java
> >
> > Now that all targets use srcjar_deps for JNI, use GN metadata to
> > restrict JNI registration to parsing only files that actually contain
> > JNI.
> >
> > * Deletes JniIgnoreNatives annotation
> > * Deletes |file_exclusions| from generate_jni_registration
> > * Changes all registration srcjars to be created in only the default
> >   toolchain.
> >
> > Bug: 1410872
> > Change-Id: If7deaf1fa820c655aceae3c8f708d06fd20eb730
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4630912
> > Commit-Queue: Andrew Grieve <agrieve@chromium.org>
> > Owners-Override: Andrew Grieve <agrieve@chromium.org>
> > Reviewed-by: Sam Maier <smaier@chromium.org>
> > Cr-Commit-Position: refs/heads/main@{#1160998}
>
> Bug: 1410872
> Change-Id: Ib422981395f0d1894d6b51af710b46d9fcd85964
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4633361
> Commit-Queue: Sam Maier <smaier@chromium.org>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Auto-Submit: Mateusz Zbikowski <zbikowski@google.com>
> Owners-Override: Sam Maier <smaier@chromium.org>
> Reviewed-by: Sam Maier <smaier@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1161164}

Bug: 1410872
Change-Id: I84eefa442bfb1fde5741d4afbdaa591ddb63afdf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4638903
Owners-Override: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Mohamed Heikal <mheikal@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1162403}
This commit is contained in:
Andrew Grieve
2023-06-26 14:37:54 +00:00
committed by Chromium LUCI CQ
parent 06a65a37e4
commit 1b15af251f
20 changed files with 132 additions and 245 deletions

@ -393,24 +393,20 @@ template("webview_alternate_library") {
}
}
if (defined(android_secondary_abi_toolchain)) {
if (android_64bit_target_cpu && !skip_secondary_abi_for_cq) {
# Note here that on a given system, the webview-only library needs the same
# library name as the browser library, since the system webview factory will
# differentiate only by ABI.
if (current_toolchain == android_secondary_abi_toolchain) {
webview_alternate_library("monochrome_64") {
# This target is the 32-bit WebView library that pairs with a 64-bit
# browser. It is suffixed with _64 because its name must match the 64-bit
# browser library.
webview_alternate_library("monochrome_64") {
}
} else {
# Inverse of above, for the original 32-bit case.
webview_alternate_library("monochrome") {
}
enable_target = current_toolchain == android_secondary_abi_toolchain
}
} else {
# 32-bit WebView library used in 32-bit only builds of 64/32 targets.
webview_alternate_library("monochrome_64") {
# Inverse of above, for the original 32-bit case.
webview_alternate_library("monochrome") {
enable_target = current_toolchain != android_secondary_abi_toolchain
}
}

@ -4,10 +4,8 @@
package com.android.webview.chromium;
import org.chromium.base.annotations.JniIgnoreNatives;
import org.chromium.build.annotations.UsedByReflection;
@JniIgnoreNatives
class DrawFunctor {
public static long getDrawFnFunctionTable() {
return nativeGetFunctionTable();

@ -9,7 +9,6 @@ import android.view.View;
import android.webkit.WebViewDelegate;
import org.chromium.android_webview.AwContents;
import org.chromium.base.annotations.JniIgnoreNatives;
import org.chromium.build.annotations.UsedByReflection;
/**
@ -18,7 +17,6 @@ import org.chromium.build.annotations.UsedByReflection;
* and then drawn and detached from the view tree any number of times (using requestDrawGL and
* detach respectively).
*/
@JniIgnoreNatives
class DrawGLFunctor implements AwContents.NativeDrawGLFunctor {
private static final String TAG = DrawGLFunctor.class.getSimpleName();

@ -4,10 +4,8 @@
package com.android.webview.chromium;
import org.chromium.base.annotations.JniIgnoreNatives;
import org.chromium.build.annotations.UsedByReflection;
@JniIgnoreNatives
abstract class GraphicsUtils {
public static long getDrawSWFunctionTable() {
return nativeGetDrawSWFunctionTable();

@ -259,8 +259,7 @@ template("system_webview_apk_or_module_tmpl") {
foreach(_lib, _jni_registrations) {
_label =
get_label_info(_lib, "label_no_toolchain") + "__jni_registration"
_toolchain = get_label_info(_lib, "toolchain")
srcjar_deps += [ "$_label($_toolchain)" ]
srcjar_deps += [ "$_label($default_toolchain)" ]
}
}

@ -4170,7 +4170,6 @@ if (is_android) {
"android/java/src/org/chromium/base/annotations/CalledByNativeForTesting.java",
"android/java/src/org/chromium/base/annotations/CalledByNativeUnchecked.java",
"android/java/src/org/chromium/base/annotations/JNINamespace.java",
"android/java/src/org/chromium/base/annotations/JniIgnoreNatives.java",
"android/java/src/org/chromium/base/annotations/NativeClassQualifiedName.java",
"android/java/src/org/chromium/base/annotations/NativeMethods.java",
]

@ -1,16 +0,0 @@
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.base.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Causes generate_jni_registration() to skip native methods in a file.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface JniIgnoreNatives {}

@ -18,7 +18,6 @@ import org.chromium.base.Log;
import org.chromium.base.StreamUtil;
import org.chromium.base.TimeUtils.UptimeMillisTimer;
import org.chromium.base.annotations.AccessedByNative;
import org.chromium.base.annotations.JniIgnoreNatives;
import org.chromium.base.metrics.RecordHistogram;
import java.io.BufferedReader;
@ -73,7 +72,6 @@ import javax.annotation.concurrent.GuardedBy;
* available to then send the Bundle to Linkers in other processes, consumed
* by takeSharedRelrosFromBundle().
*/
@JniIgnoreNatives
class Linker {
private static final String TAG = "Linker";
@ -769,7 +767,6 @@ class Linker {
* well.
*/
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
@JniIgnoreNatives
static class LibInfo implements Parcelable {
private static final String EXTRA_LINKER_LIB_INFO = "libinfo";
@ -870,8 +867,6 @@ class Linker {
public int mRelroFd = -1; // shared RELRO file descriptor, or -1
}
// Intentionally omitting @NativeMethods because generation of the stubs it requires (as
// GEN_JNI.java) is disabled by the @JniIgnoreNatives.
interface Natives {
/**
* Reserves a memory region (=mapping) of sufficient size to hold the loaded library before

@ -7,19 +7,13 @@ package org.chromium.base.library_loader;
import androidx.annotation.NonNull;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JniIgnoreNatives;
/**
* Mockable stub for all native methods in Linker.
*
* This functionality is usually generated from @NativeMethods, which cannot be used for the
* auxiliary native library used by classes in Linker and other classes in this package.
*
* Generation of JNI stubs for classes in this package is omitted via @JniIgnoreNatives because
* otherwise the generated native parts would have been linked into lib{,mono}chrome.so instead of
* lib$LINKER_JNI_LIBRARY.so, where they are needed.
*/
@JniIgnoreNatives
class LinkerJni implements Linker.Natives {
@Override
public void findMemoryRegionAtRandomAddress(@NonNull Linker.LibInfo libInfo) {
@ -52,6 +46,8 @@ class LinkerJni implements Linker.Natives {
return nativeGetRelroSharingResult();
}
// Does not use JNI Generator because the native side is in libchromium_linker.so rather
// libmonochrome.so
private static native void nativeFindMemoryRegionAtRandomAddress(
@NonNull Linker.LibInfo libInfo);
private static native void nativeReserveMemoryForLibrary(@NonNull Linker.LibInfo libInfo);

@ -130,8 +130,6 @@ void MyClass::NonStatic(JNIEnv* env) { ... }
- The binding generator also looks for `native` JNI method declarations and
generates stubs for them. This used to be the norm, but is now obsolete.
- If you have native methods that you don't want stubs generated for, you should
add @JniIgnoreNatives to the class.
#### Testing Mockable Natives

@ -218,7 +218,7 @@ class BaseTest(unittest.TestCase):
java_sources_file = pathlib.Path(tdir) / 'java_sources.txt'
java_sources_file.write_text('\n'.join(java_sources))
cmd += ['--java-sources-files', str(java_sources_file)]
cmd += ['--java-sources-file', str(java_sources_file)]
if native_sources:
native_sources_file = pathlib.Path(tdir) / 'native_sources.txt'
native_sources_file.write_text('\n'.join(native_sources))

@ -40,11 +40,6 @@ MERGEABLE_KEYS = [
'REGISTER_NATIVES',
]
# Classes here will be removed from the java side of registration.
PERMANENTLY_IGNORED_JAVA_ONLY_FILES = [r'\W+third_party/cardboard/']
PERMANENTLY_IGNORED_JAVA_ONLY_FILES_RE = re.compile(
'|'.join(PERMANENTLY_IGNORED_JAVA_ONLY_FILES))
def _Generate(options, native_sources, java_sources):
"""Generates files required to perform JNI registration.
@ -75,8 +70,10 @@ def _Generate(options, native_sources, java_sources):
results.append(d)
cached_results_for_stubs[path] = jni_obj
used_sources = {d['FILE_PATH'] for d in results}
stub_dicts = _GenerateStubsAndAssert(options, used_sources, java_sources,
native_sources_set = {d['FILE_PATH'] for d in results}
java_sources_set = set(java_sources)
stub_dicts = _GenerateStubsAndAssert(options, native_sources_set,
java_sources_set,
cached_results_for_stubs)
# Sort to make output deterministic.
results.sort(key=lambda d: d['FULL_CLASS_NAME'])
@ -158,10 +155,10 @@ def _Generate(options, native_sources, java_sources):
stub_methods=stub_methods_string))
def _GenerateStubsAndAssert(options, native_sources, java_sources,
def _GenerateStubsAndAssert(options, native_sources_set, java_sources_set,
cached_results_for_stubs):
native_only = native_sources - java_sources
java_only = java_sources - native_sources
native_only = native_sources_set - java_sources_set
java_only = java_sources_set - native_sources_set
# Using stub_only because we just need this to do a boolean check to see if
# the files have JNI - we don't need any actual output.
dict_by_path = {
@ -204,12 +201,6 @@ def _DictForPath(options, path, stub_only=False, cached_results_for_stubs=None):
assert (cached_results_for_stubs is not None) == stub_only
jni_obj = stub_only and cached_results_for_stubs.get(path)
if not jni_obj:
with open(path) as f:
# TODO(crbug.com/1410871): Remove annotation once using GN metadata to
# only parse specific files.
if '@JniIgnoreNatives' in f.read():
return None, path, None
jni_obj = jni_generator.JNIFromJavaSource.CreateFromFile(path, options)
if not options.include_test_only:
jni_obj.RemoveTestOnlyNatives()
@ -895,21 +886,10 @@ def _MakeProxySignature(options, proxy_native):
})
def _GetFilesSetFromSources(sources_files, file_exclusions):
def should_include(p):
return ((p.startswith('..') or os.path.isabs(p))
and p not in file_exclusions and not p.endswith('.kt')
and not p.endswith('package-info.java'))
java_file_paths = set()
for f in sources_files:
# Skip generated files (ones starting with ..), since the GN targets do not
# declare any deps, so they may not be built at the time of this script
# running. Thus, we don't support JNI from generated files. Also skip Kotlin
# files as they are not supported by JNI generation.
java_file_paths.update(p for p in build_utils.ReadSourcesList(f)
if should_include(p))
return java_file_paths
def _ParseSourceList(path):
# Path can have duplicates.
with open(path) as f:
return sorted(set(f.read().splitlines()))
def main(argv):
@ -919,22 +899,21 @@ def main(argv):
arg_parser.add_argument('--native-sources-file',
help='A file which contains Java file paths, derived '
'from native deps onto generate_jni.')
arg_parser.add_argument('--java-sources-files',
arg_parser.add_argument('--java-sources-file',
required=True,
action='append',
help='A list of .sources files which contain Java '
'file paths, derived from our Java dependencies.')
help='A file which contains Java file paths, derived '
'from java deps metadata.')
arg_parser.add_argument(
'--add-stubs-for-missing-native',
action='store_true',
help='Adds stub methods for any --java-sources-files which are missing '
help='Adds stub methods for any --java-sources-file which are missing '
'from --native-sources-files. If not passed, we will assert that none of '
'these exist.')
arg_parser.add_argument(
'--remove-uncalled-methods',
action='store_true',
help='Removes --native-sources-files which are not in '
'--java-sources-files. If not passed, we will assert that none of these '
'--java-sources-file. If not passed, we will assert that none of these '
'exist.')
arg_parser.add_argument(
'--header-path', help='Path to output header file (optional).')
@ -943,10 +922,6 @@ def main(argv):
required=True,
help='Path to output srcjar for GEN_JNI.java (and J/N.java if proxy'
' hash is enabled).')
arg_parser.add_argument('--file-exclusions',
default=[],
help='A list of Java files which should be ignored '
'by the parser.')
arg_parser.add_argument(
'--namespace',
default='',
@ -999,40 +974,23 @@ def main(argv):
'Invalid arguments: --manual-jni-registration without --header-path. '
'Cannot manually register JNI if there is no output header file.')
java_sources_files = sorted(
set(action_helpers.parse_gn_list(args.java_sources_files)))
java_sources = _GetFilesSetFromSources(java_sources_files,
args.file_exclusions)
java_sources = {
j
for j in java_sources
if not PERMANENTLY_IGNORED_JAVA_ONLY_FILES_RE.match(j)
}
java_sources = _ParseSourceList(args.java_sources_file)
if args.native_sources_file:
native_sources = _GetFilesSetFromSources([args.native_sources_file],
args.file_exclusions)
native_sources = _ParseSourceList(args.native_sources_file)
else:
assert not args.remove_uncalled_methods
if args.add_stubs_for_missing_native:
# This will create a fully stubbed out GEN_JNI.
native_sources = set()
native_sources = []
else:
# Just treating it like we have perfect alignment between native and java
# when only looking at java.
native_sources = java_sources
native_ignored = {
j
for j in native_sources if PERMANENTLY_IGNORED_JAVA_ONLY_FILES_RE.match(j)
}
assert not native_ignored, (
f'''Permanently ignored java files shouldn't be in a generate_jni target:
{native_ignored}
''')
_Generate(args, native_sources, java_sources=java_sources)
if args.depfile:
all_inputs = java_sources_files + list(native_sources) + list(java_sources)
all_inputs = [args.java_sources_file] + native_sources + java_sources
if args.native_sources_file:
all_inputs.append(args.native_sources_file)
action_helpers.write_depfile(args.depfile, args.srcjar_path, all_inputs)

@ -437,12 +437,6 @@ into the final APK as-is.
NOTE: This has nothing to do with *Android* resources.
* `deps_info['jni_all_source']`
The list of all `deps_info['target_sources_file']` entries for all library
dependencies for this APK. Note: this is a list of files, where each file
contains a list of Java and Kotlin source files. This is used for JNI
registration.
* `deps_info['proguard_all_configs']`:
The collection of all 'deps_info['proguard_configs']` values from this target
and all its dependencies.
@ -1473,19 +1467,6 @@ def main(argv):
if options.r_text_path:
deps_info['r_text_path'] = options.r_text_path
# TODO(tiborg): Remove creation of JNI info for type group and java_library
# once we can generate the JNI registration based on APK / module targets as
# opposed to groups and libraries.
if is_apk_or_module_target or options.type in ('group', 'java_library',
'robolectric_binary',
'dist_aar'):
all_target_sources = [
c['target_sources_file'] for c in all_library_deps
if 'target_sources_file' in c
]
if options.target_sources_file:
all_target_sources.append(options.target_sources_file)
if is_apk_or_module_target or options.type in ('group', 'java_library',
'robolectric_binary'):
if options.apk_proto_resources:
@ -1822,7 +1803,6 @@ def main(argv):
'device_classpath', 'trace_event_rewritten_device_classpath',
'all_dex_files'
]
jni_all_source = set()
lint_aars = set()
lint_srcjars = set()
lint_sources = set()
@ -1843,7 +1823,6 @@ def main(argv):
deps_info['lint_android_manifest'] = c['android_manifest']
else:
lint_extra_android_manifests.add(c['android_manifest'])
jni_all_source.update(c['jni_all_source'])
lint_aars.update(c['lint_aars'])
lint_srcjars.update(c['lint_srcjars'])
lint_sources.update(c['lint_sources'])
@ -1853,7 +1832,6 @@ def main(argv):
for f in per_module_fields:
if f in c:
module[f] = c[f]
deps_info['jni_all_source'] = sorted(jni_all_source)
deps_info['lint_aars'] = sorted(lint_aars)
deps_info['lint_srcjars'] = sorted(lint_srcjars)
deps_info['lint_sources'] = sorted(lint_sources)
@ -1865,11 +1843,6 @@ def main(argv):
_DedupFeatureModuleSharedCode(options.uses_split, modules,
per_module_fields)
if is_apk_or_module_target or options.type in ('group', 'java_library',
'robolectric_binary',
'dist_aar'):
deps_info['jni_all_source'] = sorted(set(all_target_sources))
system_jars = [c['unprocessed_jar_path'] for c in system_library_deps]
system_interface_jars = [c['interface_jar_path'] for c in system_library_deps]
if system_library_deps:
@ -2173,7 +2146,6 @@ def main(argv):
RemoveObjDups(config, ancestor, 'deps_info', 'dependency_zips')
RemoveObjDups(config, ancestor, 'deps_info', 'dependency_zip_overlays')
RemoveObjDups(config, ancestor, 'deps_info', 'extra_package_names')
RemoveObjDups(config, ancestor, 'deps_info', 'jni_all_source')
RemoveObjDups(config, ancestor, 'extra_android_manifests')
if is_java_target:

@ -743,6 +743,7 @@ template("test_runner_script") {
forward_variables_from(invoker,
[
"assert_no_deps",
"metadata",
"public_deps",
"visibility",
])

@ -26,7 +26,11 @@ if (target_os == "android") {
template("jni_sources_list") {
generated_file(target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ])
forward_variables_from(invoker,
TESTONLY_AND_VISIBILITY + [
"deps",
"walk_keys",
])
outputs = [ invoker.output ]
data_keys = [ "jni_source_files" ]
rebase = root_build_dir
@ -52,10 +56,10 @@ template("jni_sources_list") {
# about the format of the header file.
#
# Variables
# targets: List of .build_config.json supported targets to provide java sources.
# java_targets: List of android_* targets that comprise your app.
# native_deps: List of shared_library targets that comprise your app.
# manual_jni_registration: Manually do JNI registration - required for feature
# splits which provide their own native library. (optional)
# file_exclusions: List of .java files that should be skipped. (optional)
# namespace: Registration functions will be wrapped into this. (optional)
# require_native_mocks: Enforce that any native calls using
# org.chromium.base.annotations.NativeMethods must have a mock set
@ -66,28 +70,35 @@ template("jni_sources_list") {
#
# Example
# generate_jni_registration("chrome_jni_registration") {
# targets = [ ":chrome_public_apk" ]
# java_targets = [ ":chrome_public_apk" ]
# manual_jni_registration = false
# file_exclusions = [
# "//path/to/Exception.java",
# ]
# }
template("generate_jni_registration") {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
if (defined(invoker.native_deps)) {
_jni_sources_list = "$target_gen_dir/$target_name.jnisources"
_jni_sources_target = "${target_name}__jni_sources"
jni_sources_list(_jni_sources_target) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
_native_sources_list = "$target_gen_dir/$target_name.nativesources.txt"
jni_sources_list("${target_name}__native_sources") {
deps = invoker.native_deps
output = _jni_sources_list
output = _native_sources_list
}
}
action_with_pydeps(target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
_java_sources_list = "$target_gen_dir/$target_name.javasources.txt"
jni_sources_list("${target_name}__java_sources") {
deps = invoker.java_targets
output = _java_sources_list
# When apk or bundle module targets are uses, do not pull metadata from
# their native library deps.
walk_keys = [ "java_walk_keys" ]
}
action_with_pydeps(target_name) {
script = "//base/android/jni_generator/jni_registration_generator.py"
inputs = []
# Cannot depend on jni_sources_list targets since they likely depend on
# this target via srcjar_deps. Depfiles are used to add the dep instead.
deps = []
_srcjar_output = "$target_gen_dir/$target_name.srcjar"
outputs = [ _srcjar_output ]
@ -98,31 +109,14 @@ template("generate_jni_registration") {
rebase_path(_srcjar_output, root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
"--java-sources-file",
rebase_path(_java_sources_list, root_build_dir),
]
if (defined(_jni_sources_target)) {
inputs += [ _jni_sources_list ]
deps += [ ":$_jni_sources_target" ]
if (defined(_native_sources_list)) {
args += [
"--native-sources-file",
rebase_path(_jni_sources_list, root_build_dir),
]
}
foreach(_target, invoker.java_targets) {
# Due to robolectric, we can't import internal_rules.gni unconditionally,
# which means that build_config_target_suffix isn't always available, so
# we hardcode the value of it here.
deps += [ "${_target}__build_config_crbug_908819($default_toolchain)" ]
_build_config =
get_label_info("${_target}($default_toolchain)", "target_gen_dir") +
"/" + get_label_info("${_target}($default_toolchain)", "name") +
".build_config.json"
_rebased_build_config = rebase_path(_build_config, root_build_dir)
inputs += [ _build_config ]
args += [
# This is a list of .sources files.
"--java-sources-files=@FileArg($_rebased_build_config:deps_info:jni_all_source)",
rebase_path(_native_sources_list, root_build_dir),
]
}
@ -181,12 +175,6 @@ template("generate_jni_registration") {
public_configs = [ "//build/config/android:jni_include_dir" ]
}
if (defined(invoker.file_exclusions)) {
_rebase_file_exclusions =
rebase_path(invoker.file_exclusions, root_build_dir)
args += [ "--file-exclusions=$_rebase_file_exclusions" ]
}
if (defined(invoker.namespace)) {
args += [ "--namespace=${invoker.namespace}" ]
}
@ -207,15 +195,16 @@ template("generate_jni_registration") {
# In order to depend on the JNI registration, use
# <native-target-name>__jni_registration.
template("_native_with_jni") {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
_jni_registration_name = "${target_name}__jni_registration"
_needs_native_dep =
(defined(invoker.manual_jni_registration) &&
invoker.manual_jni_registration) || allow_jni_multiplexing
if (_needs_native_dep || current_toolchain == default_toolchain) {
_jni_registration_target_name = "${target_name}__jni_registration"
}
# DFMs only ever need to be defined in the default toolchain, since we never
# do cross-toolchain deps with DFMs.
_use_all_toolchains = !defined(invoker.module_name)
if (_use_all_toolchains || current_toolchain == default_toolchain) {
generate_jni_registration(_jni_registration_name) {
if (current_toolchain == default_toolchain) {
generate_jni_registration(_jni_registration_target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
native_deps = invoker.deps
if (allow_jni_multiplexing) {
@ -248,19 +237,20 @@ template("_native_with_jni") {
])
}
target(invoker.target_type, target_name) {
deps = invoker.deps
_need_native_dep =
(defined(invoker.manual_jni_registration) &&
invoker.manual_jni_registration) || allow_jni_multiplexing
if (_need_native_dep) {
_jni_registration_dep = ":$_jni_registration_name"
if (!_use_all_toolchains) {
_jni_registration_dep += "($default_toolchain)"
if (!defined(invoker.enable_target) || invoker.enable_target) {
target(invoker.target_type, target_name) {
deps = invoker.deps
if (_needs_native_dep) {
deps += [ ":$_jni_registration_target_name($default_toolchain)" ]
}
deps += [ _jni_registration_dep ]
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY + [ "deps" ])
}
} else {
not_needed(invoker, "*")
if (current_toolchain != default_toolchain) {
not_needed([ "target_name" ])
}
forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY + [ "deps" ])
}
}

@ -1417,7 +1417,7 @@ if (enable_java_templates && is_android) {
"$target_name has shared_libraries with incorrect toolchain. " +
"Should contain (\$robolectric_toolchain) suffix: $_dep")
_jni_srcjar_deps +=
[ "${_dep_no_toolchain}__jni_registration($_dep_toolchain)" ]
[ "${_dep_no_toolchain}__jni_registration($default_toolchain)" ]
}
# Write shared library output files of all dependencies to a file. Those
@ -1431,12 +1431,11 @@ if (enable_java_templates && is_android) {
rebase = root_build_dir
}
} else {
_outer_target_name = target_name
_jni_srcjar_target_name = "${target_name}__final_jni"
generate_jni_registration(_jni_srcjar_target_name) {
enable_native_mocks = true
require_native_mocks = true
java_targets = [ ":$_outer_target_name" ]
java_targets = [ ":$_java_binary_target_name" ]
add_stubs_for_missing_jni = true
}
_jni_srcjar_deps = [ ":$_jni_srcjar_target_name" ]
@ -1515,6 +1514,11 @@ if (enable_java_templates && is_android) {
# Add non-libary deps, since the __host target does not depend on them.
deps += filter_exclude(_invoker_deps, java_library_patterns)
metadata = {
# Allows metadata collection via apk targets that traverse only java deps.
java_walk_keys = [ ":${_java_binary_target_name}__host" ]
}
}
}
@ -3320,8 +3324,15 @@ if (enable_java_templates && is_android) {
"assert_no_deps",
"data",
"data_deps",
"metadata",
])
metadata = {
if (defined(invoker.metadata)) {
forward_variables_from(invoker.metadata, "*")
}
# Allows metadata collection via apk targets that traverse only java deps.
java_walk_keys = [ ":$_java_target_name" ]
}
# Generate apk related operations at runtime.
public_deps = _final_deps
@ -3413,7 +3424,6 @@ if (enable_java_templates && is_android) {
"input_jars_paths",
"jacoco_never_instrument",
"javac_args",
"jni_registrations",
"keystore_name",
"keystore_password",
"keystore_path",
@ -3473,9 +3483,9 @@ if (enable_java_templates && is_android) {
}
metadata = {
install_artifacts = [ final_apk_path ]
}
if (defined(invoker.static_library_provider)) {
metadata.install_artifacts_barrier = []
if (defined(invoker.static_library_provider)) {
install_artifacts_barrier = []
}
}
# TODO(smaier) - there were some remaining usages of this in angle. Once
@ -3560,7 +3570,6 @@ if (enable_java_templates && is_android) {
"jacoco_never_instrument",
"jar_excluded_patterns",
"javac_args",
"jni_registrations",
"loadable_modules",
"product_config_java_packages",
"main_component_library",
@ -5371,9 +5380,9 @@ if (enable_java_templates && is_android) {
deps = [ ":$_bundle_target_name" ]
metadata = {
install_artifacts = [ _apks_path ]
}
if (defined(invoker.static_library_provider)) {
metadata.install_artifacts_barrier = []
if (defined(invoker.static_library_provider)) {
install_artifacts_barrier = []
}
}
# http://crbug.com/725224. Fix for bots running out of memory.

@ -48,14 +48,14 @@ if (android_64bit_target_cpu && skip_secondary_abi_for_cq) {
assert(current_toolchain != android_secondary_abi_toolchain)
}
if (current_toolchain == default_toolchain) {
# 32-bit library will have browser code in it. 64-bit is webview-only.
if (android_64bit_target_cpu && !skip_secondary_abi_for_cq) {
_monochrome_browser_toolchain = android_secondary_abi_toolchain
} else {
_monochrome_browser_toolchain = current_toolchain
}
# 32-bit library will have browser code in it. 64-bit is webview-only.
if (android_64bit_target_cpu && !skip_secondary_abi_for_cq) {
_monochrome_browser_toolchain = android_secondary_abi_toolchain
} else {
_monochrome_browser_toolchain = default_toolchain
}
if (current_toolchain == default_toolchain) {
app_hooks_impl = "java/src/org/chromium/chrome/browser/AppHooksImpl.java"
template("chrome_public_bundle") {
@ -3671,37 +3671,38 @@ template("libmonochrome_apk_or_bundle_tmpl") {
}
}
if (!android_64bit_target_cpu ||
(!skip_secondary_abi_for_cq &&
current_toolchain == android_secondary_abi_toolchain)) {
libmonochrome_apk_or_bundle_tmpl("libmonochrome") {
enable_target = current_toolchain == _monochrome_browser_toolchain
define_unwind_table_target =
add_unwind_tables_in_chrome_32bit_apk && current_cpu == "arm"
if (enable_resource_allowlist_generation) {
# Make sure allowlist_inputs is built first so when concurrent_links == 1
# it comes before the actual (very slow) link step.
deps = [ ":libmonochrome_inputs($_monochrome_browser_toolchain)" ]
}
}
if (current_toolchain == _monochrome_browser_toolchain) {
# Avoiding a real link for this step allows the actual libmonochrome to
# run at the same time as R8.
libmonochrome_apk_or_bundle_tmpl("libmonochrome_inputs") {
collect_inputs_only = true
}
libmonochrome_apk_or_bundle_tmpl("libmonochrome") {
define_unwind_table_target =
add_unwind_tables_in_chrome_32bit_apk && current_cpu == "arm"
if (enable_resource_allowlist_generation) {
# Make sure allowlist_inputs is built first so when concurrent_links == 1
# it comes before the actual (very slow) link step.
deps = [ ":libmonochrome_inputs" ]
}
}
if (android_64bit_target_cpu && !skip_secondary_abi_for_cq) {
group("monochrome_64_secondary_abi_lib") {
public_deps = [ ":libmonochrome_64($android_secondary_abi_toolchain)" ]
}
}
} else {
}
if (android_64bit_target_cpu) {
# 64-bit browser library targets (APK and bundle).
libmonochrome_apk_or_bundle_tmpl("libmonochrome_64") {
}
# 32-bit browser library alias targets, pulled in by 64-bit WebView builds.
if (android_64bit_target_cpu && !skip_secondary_abi_for_cq) {
if (!skip_secondary_abi_for_cq) {
group("monochrome_secondary_abi_lib") {
public_deps = [ ":libmonochrome($android_secondary_abi_toolchain)" ]
}

@ -567,7 +567,7 @@ template("chrome_common_apk_or_module_tmpl") {
}
}
} else {
srcjar_deps = [ "//chrome/android:libmonochrome__jni_registration($android_secondary_abi_toolchain)" ]
srcjar_deps = [ "//chrome/android:libmonochrome__jni_registration($default_toolchain)" ]
if (_is_monochrome) {
if (_include_64_bit_webview) {
shared_libraries += [ "//android_webview:monochrome" ]

@ -54,12 +54,6 @@ generate_jni_registration("cronet_jni_registration") {
# JNI generated is used for test and non-test apks.
include_testonly = true
file_exclusions = [
"//base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java",
"//base/android/java/src/org/chromium/base/library_loader/LibraryPrefetcher.java",
"//base/android/java/src/org/chromium/base/process_launcher/ChildProcessService.java",
"//base/android/java/src/org/chromium/base/SysUtils.java",
]
}
android_library("cronet_jni_registration_java") {

@ -7,10 +7,10 @@ import("//testing/libfuzzer/fuzzer_test.gni")
import("//testing/test.gni")
import("features.gni")
import("//build/config/android/jni.gni")
import("//build/config/cronet/config.gni")
if (is_android || is_robolectric) {
import("//build/config/android/jni.gni")
import("//build/config/android/rules.gni")
}
@ -392,11 +392,12 @@ if (is_android && !is_cronet_build) {
}
}
if (is_robolectric) {
# Use this in robolectric_binary() targets if you just need GURL and //base
# functionality. Otherwise, define a custom shared_library().
# Use this in robolectric_binary() targets if you just need GURL and //base
# functionality. Otherwise, define a custom shared_library().
if (!is_cronet_build && target_os == "android") {
shared_library_with_jni("libgurl_robolectric") {
testonly = true
enable_target = is_robolectric
sources = [ "android/robolectric_test_main.cc" ]
deps = [
"//base",