Commit 5e827d95 authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Android: Target JDK11 when building !supports_android targets

And removes last remnant of JDK8: sun_java_tools

Bug: 693079
Change-Id: I4a1988a739543a561accbd4d6a8dbaad75d545b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1956048Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Auto-Submit: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744380}
parent 69cb0173
......@@ -8,8 +8,6 @@ import("//build/config/python.gni")
import("//build_overrides/build.gni")
if (enable_java_templates) {
sun_tools_jar_path = "$root_gen_dir/sun_tools_jar/tools.jar"
# Create or update the API versions cache if necessary by running a
# functionally empty lint task. This prevents racy creation of the
# cache while linting java targets in android_lint.
......@@ -18,23 +16,6 @@ if (enable_java_templates) {
create_cache = true
}
action("find_sun_tools_jar") {
script = "//build/android/gyp/find_sun_tools_jar.py"
depfile = "$target_gen_dir/$target_name.d"
outputs = [ sun_tools_jar_path ]
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--output",
rebase_path(sun_tools_jar_path, root_build_dir),
]
}
java_prebuilt("sun_tools_java") {
jar_path = sun_tools_jar_path
deps = [ ":find_sun_tools_jar" ]
}
# Write to a file some GN vars that are useful to scripts that use the output
# directory. Format is chosen as easliy importable by both python and bash.
_lines = [
......
......@@ -421,6 +421,7 @@ def _OnStaleMd5(options, javac_cmd, java_files, classpath):
build_utils.CheckOutput(
cmd,
print_stdout=options.chromium_code,
stdout_filter=ProcessJavacOutput,
stderr_filter=ProcessJavacOutput)
logging.info('Finished build command')
......
#!/usr/bin/env python
#
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""This finds the java distribution's tools.jar and copies it somewhere.
"""
import argparse
import os
import re
import shutil
import sys
from util import build_utils
RT_JAR_FINDER = re.compile(r'\[Opened (.*)/jre/lib/rt.jar\]')
def main():
parser = argparse.ArgumentParser(description='Find Sun Tools Jar')
parser.add_argument('--depfile',
help='Path to depfile. This must be specified as the '
'action\'s first output.')
parser.add_argument('--output', required=True)
args = parser.parse_args()
sun_tools_jar_path = FindSunToolsJarPath()
if sun_tools_jar_path is None:
raise Exception("Couldn\'t find tools.jar")
# Using copyfile instead of copy() because copy() calls copymode()
# We don't want the locked mode because we may copy over this file again
shutil.copyfile(sun_tools_jar_path, args.output)
if args.depfile:
build_utils.WriteDepfile(args.depfile, args.output, [sun_tools_jar_path])
def FindSunToolsJarPath():
# This works with at least openjdk 1.6, 1.7 and sun java 1.6, 1.7
stdout = build_utils.CheckOutput(
["java", "-verbose", "-version"], print_stderr=False)
for ln in stdout.splitlines():
match = RT_JAR_FINDER.match(ln)
if match:
return os.path.join(match.group(1), 'lib', 'tools.jar')
return None
if __name__ == '__main__':
sys.exit(main())
......@@ -2783,11 +2783,13 @@ if (enable_java_templates) {
"--generated-dir=$_rebased_generated_dir",
"--jar-path=$_rebased_javac_jar_path",
"--java-srcjars=$_rebased_java_srcjars",
"--java-version=1.8",
"--classpath=@FileArg($_rebased_build_config:deps_info:javac_full_interface_classpath)",
"--processorpath=@FileArg($_rebased_build_config:javac:processor_classpath)",
"--processors=@FileArg($_rebased_build_config:javac:processor_classes)",
]
if (invoker.supports_android) {
args += [ "--java-version=1.8" ]
}
if (use_java_goma) {
args += [ "--gomacc-path=$goma_dir/gomacc" ]
}
......@@ -3333,6 +3335,7 @@ if (enable_java_templates) {
}
srcjar_deps = _srcjar_deps
chromium_code = _chromium_code
supports_android = _supports_android
requires_android = _requires_android
deps = _accumulated_deps + _accumulated_public_deps
......
......@@ -202,13 +202,18 @@ java_annotation_processor("robolectric_processor") {
deps = [
":robolectric_annotations_java",
":sdk_list_txt",
"//build/android:sun_tools_java",
"//third_party/android_deps:com_google_code_gson_gson_java",
"//third_party/android_deps:com_google_guava_guava_java",
"//third_party/android_deps:org_ow2_asm_asm_commons_java",
"//third_party/android_deps:org_ow2_asm_asm_java",
"//third_party/android_deps:org_ow2_asm_asm_tree_java",
]
javac_args = [
"--add-exports",
"jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"--add-exports",
"jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
]
provider_configurations = [ "local/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor" ]
main_class = "org.robolectric.annotation.processing.RobolectricProcessor"
sources = [
......@@ -398,12 +403,12 @@ java_library("robolectric_utils_java") {
"//third_party/junit:junit",
]
sources = [
"local/robolectric/src/main/java/org/robolectric/util/reflector/UnsafeAccess.java",
"robolectric/utils/reflector/src/main/java/org/robolectric/util/reflector/Accessor.java",
"robolectric/utils/reflector/src/main/java/org/robolectric/util/reflector/ForType.java",
"robolectric/utils/reflector/src/main/java/org/robolectric/util/reflector/Reflector.java",
"robolectric/utils/reflector/src/main/java/org/robolectric/util/reflector/ReflectorClassWriter.java",
"robolectric/utils/reflector/src/main/java/org/robolectric/util/reflector/Static.java",
"robolectric/utils/reflector/src/main/java/org/robolectric/util/reflector/UnsafeAccess.java",
"robolectric/utils/reflector/src/main/java/org/robolectric/util/reflector/WeakerHashMap.java",
"robolectric/utils/reflector/src/main/java/org/robolectric/util/reflector/WithType.java",
"robolectric/utils/src/main/java/org/robolectric/AndroidMetadata.java",
......@@ -1092,12 +1097,18 @@ java_library("shadows_multidex_java") {
":robolectric_shadowapi_java",
":robolectric_utils_java",
":shadows_core_java",
"//build/android:sun_tools_java",
"//third_party/android_deps:com_android_support_multidex_java_orig",
"//third_party/android_deps:com_google_code_gson_gson_java",
"//third_party/android_deps:com_google_guava_guava_java",
]
javac_args = [
"--add-exports",
"jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"--add-exports",
"jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
]
# Work-around for gradle generator not yet supporting annotation processors.
gradle_treat_as_prebuilt = true
}
......
......@@ -16,6 +16,7 @@ Local Modifications:
- Added custom_asynctask folder to have workable copies of shadows required
for our own implementation of AsyncTask
- Added DefaultSdkProvider as a local file with Jellybean references removed.
- Removed non-compiling JDK9 class from UnsafeAccess.java.
How To Update:
- Visit the migration guide to see which APIs changed and need updating.
http://robolectric.org/migrating/
......
package org.robolectric.util.reflector;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import sun.misc.Unsafe;
/** Access to sun.misc.Unsafe and the various scary things within. */
@SuppressWarnings("NewApi")
public class UnsafeAccess {
private static final Danger DANGER = new Danger11Plus();
interface Danger {
<T> Class<?> defineClass(Class<T> iClass, String reflectorClassName, byte[] bytecode);
}
static <T> Class<?> defineClass(Class<T> iClass, String reflectorClassName, byte[] bytecode) {
return DANGER.defineClass(iClass, reflectorClassName, bytecode);
}
private static class Danger11Plus implements Danger {
private final Method privateLookupInMethod;
private final Method defineClassMethod;
{
try {
privateLookupInMethod = MethodHandles.class.getMethod(
"privateLookupIn", Class.class, MethodHandles.Lookup.class);
defineClassMethod =
MethodHandles.Lookup.class.getMethod("defineClass", byte[].class);
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
}
}
@Override
public <T> Class<?> defineClass(
Class<T> iClass, String reflectorClassName, byte[] bytecode) {
MethodHandles.Lookup lookup = MethodHandles.lookup();
try {
// MethodHandles.Lookup privateLookup = MethodHandles.privateLookupIn(iClass,
// lookup);
MethodHandles.Lookup privateLookup =
(Lookup) privateLookupInMethod.invoke(lookup, iClass, lookup);
// return privateLookup.defineClass(bytecode);
return (Class<?>) defineClassMethod.invoke(privateLookup, bytecode);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new AssertionError(e);
}
}
}
/**
* Returns the Java version as an int value.
*
* @return the Java version as an int value (8, 9, etc.)
*/
private static int getJavaVersion() {
String version = System.getProperty("java.version");
assert version != null;
if (version.startsWith("1.")) {
version = version.substring(2);
}
// Allow these formats:
// 1.8.0_72-ea
// 9-ea
// 9
// 9.0.1
int dotPos = version.indexOf('.');
int dashPos = version.indexOf('-');
return Integer.parseInt(
version.substring(0, dotPos > -1 ? dotPos : dashPos > -1 ? dashPos : 1));
}
}
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