forked from openkylin/platform_build
Pass OpenJDK 8's bootclasspath for host tools targeting <= 1.8.
Host (as opposed to hostdex) tools compile and run against OpenJDK's core libraries. Before this CL, the core libraries of the default toolchain were always used, even when targeting an earlier language version. This meant that code that uses APIs from a later version of OpenJDK than corresponded to LOCAL_JAVA_LANGUAGE_VERSION would compile, but would fail to run under that earlier version of OpenJDK. It also meant that calls to existing APIs might be reinterpreted; for example, the return type of java.nio.ByteBuffer.clear() changed from Buffer in OpenJDK 8 to ByteBuffer in OpenJDK 9. At compile time, this was noted via the warning: bootstrap class path not set in conjunction with -source 1.8 After this CL, when targeting a language version <= 1.8 (which is always the case when building with OpenJDK 8), some of OpenJDK 8's core library/tools jars are now passed on the bootclasspath. The decision to include the bootclasspath argument when building with OpenJDK 8 was somewhat arbitrary, but has the advantage that we discover any issues before we switch to OpenJDK 9. Even when compiling with OpenJDK 9, use of OpenJDK 9 APIs will now fail at compile time rather than at runtime; calls to existing APIs will now be interpreted in OpenJDK 8 rather than 9 fashion. For example, this means that dx and host-side CTS tests built with OpenJDK 9 javac -target 1.8 will be runnable under OpenJDK 8. Bug: 70521453 Bug: 70862583 Test: Checked that the bootclasspath argument was passed in the javac invocation targeting 1.8 during: make showcommands compatibility-common-util-hostsidelib Test: make checkbuild Change-Id: I9b6081edfdd2c3e9a450ae8a39c4e32c3d2cda92
This commit is contained in:
parent
a53865d108
commit
7e99d45ec2
|
@ -713,14 +713,8 @@ USE_OPENJDK9 := true
|
|||
TARGET_OPENJDK9 := true
|
||||
endif
|
||||
|
||||
# Path to tools.jar, or empty if USE_OPENJDK9 is unset
|
||||
HOST_JDK_TOOLS_JAR :=
|
||||
# TODO: Remove HOST_JDK_TOOLS_JAR and all references to it once OpenJDK 8
|
||||
# toolchains are no longer supported (i.e. when USE_OPENJDK9 is enforced).
|
||||
# http://b/38418220
|
||||
ifndef USE_OPENJDK9
|
||||
HOST_JDK_TOOLS_JAR := $(ANDROID_JAVA_TOOLCHAIN)/../lib/tools.jar
|
||||
endif # ifndef USE_OPENJDK9
|
||||
# Path to tools.jar
|
||||
HOST_JDK_TOOLS_JAR := $(ANDROID_JAVA8_HOME)/lib/tools.jar
|
||||
|
||||
# It's called md5 on Mac OS and md5sum on Linux
|
||||
ifeq ($(HOST_OS),darwin)
|
||||
|
|
|
@ -35,6 +35,27 @@ ifeq (,$(LOCAL_JAVA_LANGUAGE_VERSION))
|
|||
endif
|
||||
LOCAL_JAVACFLAGS += -source $(LOCAL_JAVA_LANGUAGE_VERSION) -target $(LOCAL_JAVA_LANGUAGE_VERSION)
|
||||
|
||||
###########################################################
|
||||
|
||||
# OpenJDK versions up to 8 shipped with bootstrap and tools jars
|
||||
# (rt.jar, jce.jar, tools.jar etc.). These are no longer part of
|
||||
# OpenJDK 9, but we still make them available for host tools that
|
||||
# are targeting older versions.
|
||||
USE_HOST_BOOTSTRAP_JARS := true
|
||||
ifeq (,$(filter $(LOCAL_JAVA_LANGUAGE_VERSION), 1.6 1.7 1.8))
|
||||
USE_HOST_BOOTSTRAP_JARS := false
|
||||
endif
|
||||
|
||||
###########################################################
|
||||
|
||||
# Drop HOST_JDK_TOOLS_JAR from classpath when targeting versions > 9 (which don't have it).
|
||||
# TODO: Remove HOST_JDK_TOOLS_JAR and all references to it once host
|
||||
# bootstrap jars are no longer supported (ie. when USE_HOST_BOOTSTRAP_JARS
|
||||
# is always false). http://b/38418220
|
||||
ifneq ($(USE_HOST_BOOTSTRAP_JARS),true)
|
||||
LOCAL_CLASSPATH := $(filter-out $(HOST_JDK_TOOLS_JAR),$(LOCAL_CLASSPATH))
|
||||
endif
|
||||
|
||||
###########################################################
|
||||
## .proto files: Compile proto files to .java
|
||||
###########################################################
|
||||
|
@ -290,7 +311,23 @@ else # LOCAL_IS_HOST_MODULE
|
|||
full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),true)
|
||||
full_shared_java_header_libs := $(call java-lib-header-files,$(LOCAL_JAVA_LIBRARIES),true)
|
||||
else # !USE_CORE_LIB_BOOTCLASSPATH
|
||||
|
||||
# Give host-side tools a version of OpenJDK's standard libraries
|
||||
# close to what they're targeting. As of Dec 2017, AOSP is only
|
||||
# bundling OpenJDK 8 and 9, so nothing < 8 is available.
|
||||
#
|
||||
# When building with OpenJDK 8, the following should have no
|
||||
# effect since those jars would be available by default.
|
||||
#
|
||||
# When building with OpenJDK 9 but targeting a version < 1.8,
|
||||
# putting them on the bootclasspath means that:
|
||||
# a) code can't (accidentally) refer to OpenJDK 9 specific APIs
|
||||
# b) references to existing APIs are not reinterpreted in an
|
||||
# OpenJDK 9-specific way, eg. calls to subclasses of
|
||||
# java.nio.Buffer as in http://b/70862583
|
||||
ifeq ($(USE_HOST_BOOTSTRAP_JARS),true)
|
||||
full_java_bootclasspath_libs += $(ANDROID_JAVA8_HOME)/jre/lib/jce.jar
|
||||
full_java_bootclasspath_libs += $(ANDROID_JAVA8_HOME)/jre/lib/rt.jar
|
||||
endif
|
||||
full_shared_java_libs := $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/,\
|
||||
$(addsuffix $(COMMON_JAVA_PACKAGE_SUFFIX),$(LOCAL_JAVA_LIBRARIES)))
|
||||
full_shared_java_header_libs := $(full_shared_java_libs)
|
||||
|
|
Loading…
Reference in New Issue