From f795dcb7673a74d0618ea7104e9fe1b04f690c11 Mon Sep 17 00:00:00 2001 From: Tobias Thierer Date: Tue, 9 Jan 2018 20:33:08 +0000 Subject: [PATCH] Experimental feature: LOCAL_PATCH_MODULE option in .mk files. Specifying this option causes the make target's sources and classpath dependencies to be patched into the specified module via --patch-module (if the build toolchain implements the module system, ie. when targeting 1.9). This allows tests to compile that have classes in packages under test. Currently, only java.base is on the module path (everything else is on the classpath), and only when using -target 1.9 (ie. EXPERIMENTAL_USE_OPENJDK9=true). Bug: 71699916 Test: Treehugger Test: Checked that I was able to compile some ojluni & icu test sources that had classes in (libcore) packages under test. Change-Id: I044fb9d904754ed281f574ab3dd52235cf0d7fec --- core/build-system.html | 13 +++++++++++++ core/clear_vars.mk | 1 + core/definitions.mk | 3 +++ core/java_common.mk | 1 + 4 files changed, 18 insertions(+) diff --git a/core/build-system.html b/core/build-system.html index c7938ccfb4..3d86e24a9b 100644 --- a/core/build-system.html +++ b/core/build-system.html @@ -762,6 +762,19 @@ does this.

Dialer, Contacts, etc. This will probably change or go away when we switch to an ant-based build system for the apps.

+

LOCAL_PATCH_MODULE (experimental option)

+

As of January 2018, you almost certainly don't need this option, so please +ask and only use it if you understand what you're doing. This feature is +experimental and may go away in future.

+

+When compiling language level 9+ .java code in packages that are part of a +a system module, LOCAL_PATCH_MODULE names the module that your +sources and dependencies should be patched into. The Android runtime currently +(Jan 2018) doesn't implement the JEP 261 module system so this option is only +supported at compile time. It should only be needed to compile tests in packages +that exist in libcore and which are inconvenient to move elsewhere. +

+

LOCAL_PATH

The directory your Android.mk file is in. You can set it by putting the following as the first line in your Android.mk:

diff --git a/core/clear_vars.mk b/core/clear_vars.mk index b4a03ea11e..a151beff76 100644 --- a/core/clear_vars.mk +++ b/core/clear_vars.mk @@ -181,6 +181,7 @@ LOCAL_OVERRIDES_MODULES:= LOCAL_PACKAGE_NAME:= LOCAL_PACKAGE_SPLITS:= LOCAL_PACK_MODULE_RELOCATIONS:= +LOCAL_PATCH_MODULE:= LOCAL_PICKUP_FILES:= LOCAL_POST_INSTALL_CMD:= LOCAL_POST_LINK_CMD:= diff --git a/core/definitions.mk b/core/definitions.mk index a20bf44a95..7aef2907fd 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -2245,6 +2245,9 @@ $(hide) if [ -s $(PRIVATE_JAVA_SOURCE_LIST) ] ; then \ $(addprefix -bootclasspath ,$(strip \ $(call normalize-path-list,$(PRIVATE_BOOTCLASSPATH)) \ $(PRIVATE_EMPTY_BOOTCLASSPATH)))) \ + $(if $(PRIVATE_USE_SYSTEM_MODULES), \ + $(if $(PRIVATE_PATCH_MODULE), \ + --patch-module=$(PRIVATE_PATCH_MODULE)=$(call normalize-path-list,. $(2)))) \ $(addprefix -classpath ,$(strip \ $(call normalize-path-list,$(2)))) \ $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \ diff --git a/core/java_common.mk b/core/java_common.mk index cfc9d7f65f..436f3a3b3b 100644 --- a/core/java_common.mk +++ b/core/java_common.mk @@ -359,6 +359,7 @@ endif $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := $(full_java_bootclasspath_libs) $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EMPTY_BOOTCLASSPATH := $(empty_bootclasspath) $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SYSTEM_MODULES := $(my_system_modules_dir) +$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PATCH_MODULE := $(LOCAL_PATCH_MODULE) ifndef LOCAL_IS_HOST_MODULE # This is set by packages that are linking to other packages that export