Use system modules generated by soong when using javac -target 1.9
Soong has support for building system modules. Use the directories
produced by Soong with --system to replace -bootclasspath arguments
when using javac -target 1.9.
Since soong can't generate current SDK stubs yet, and no existing
SDK stubs need -target, only use -target 1.9 for modules that are
not compiling against the SDK. That means in practice the only
system modules that will be used for now is the default one,
core-system-modules.
Bug: 63986449
Test: m -j EXPERIMENTAL_USE_OPENJDK9=true makes some progress
Change-Id: I350ef50aedf36fdd72458c23d4fe8a2edf1a9a02
diff --git a/core/config.mk b/core/config.mk
index 7007c5d..2ce064f 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -804,6 +804,9 @@
# We don't have prebuilt test_current SDK yet.
TARGET_AVAILABLE_SDK_VERSIONS := test_current $(TARGET_AVAILABLE_SDK_VERSIONS)
+TARGET_SDK_VERSIONS_WITHOUT_JAVA_18_SUPPORT := $(call numbers_less_than,24,$(TARGET_AVAILABLE_SDK_VERSIONS))
+TARGET_SDK_VERSIONS_WITHOUT_JAVA_19_SUPPORT := $(call numbers_less_than,27,$(TARGET_AVAILABLE_SDK_VERSIONS))
+
INTERNAL_PLATFORM_API_FILE := $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/public_api.txt
INTERNAL_PLATFORM_REMOVED_API_FILE := $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/removed.txt
INTERNAL_PLATFORM_SYSTEM_API_FILE := $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/system-api.txt
diff --git a/core/definitions.mk b/core/definitions.mk
index 1f9891e..0e7093e 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -2251,9 +2251,11 @@
$(hide) if [ -s $(PRIVATE_JAVA_SOURCE_LIST) ] ; then \
$(SOONG_JAVAC_WRAPPER) $(1) -encoding UTF-8 \
$(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
- $(addprefix -bootclasspath ,$(strip \
- $(call normalize-path-list,$(PRIVATE_BOOTCLASSPATH)) \
- $(PRIVATE_EMPTY_BOOTCLASSPATH))) \
+ $(if $(PRIVATE_USE_SYSTEM_MODULES), \
+ $(addprefix --system=,$(PRIVATE_SYSTEM_MODULES)), \
+ $(addprefix -bootclasspath ,$(strip \
+ $(call normalize-path-list,$(PRIVATE_BOOTCLASSPATH)) \
+ $(PRIVATE_EMPTY_BOOTCLASSPATH)))) \
$(addprefix -classpath ,$(strip \
$(call normalize-path-list,$(2)))) \
$(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \
@@ -2300,6 +2302,7 @@
$(3) \
$(5) \
$$(full_java_bootclasspath_libs) \
+ $$(full_java_system_modules_deps) \
$$(layers_file) \
$$(annotation_processor_deps) \
$$(NORMALIZE_PATH) \
diff --git a/core/host_dalvik_java_library.mk b/core/host_dalvik_java_library.mk
index 96796df..4bfe288 100644
--- a/core/host_dalvik_java_library.mk
+++ b/core/host_dalvik_java_library.mk
@@ -93,6 +93,7 @@
$(java_sources_deps) \
$(full_java_header_libs) \
$(full_java_bootclasspath_libs) \
+ $(full_java_system_modules_deps) \
$(annotation_processor_deps) \
$(NORMALIZE_PATH) \
$(JAR_ARGS) \
diff --git a/core/java.mk b/core/java.mk
index cf49994..7584479 100644
--- a/core/java.mk
+++ b/core/java.mk
@@ -499,6 +499,7 @@
$(java_sources_deps) \
$(full_java_header_libs) \
$(full_java_bootclasspath_libs) \
+ $(full_java_system_modules_deps) \
$(NORMALIZE_PATH) \
$(JAR_ARGS) \
$(ZIPTIME) \
diff --git a/core/java_common.mk b/core/java_common.mk
index 320c52f..a73c6db 100644
--- a/core/java_common.mk
+++ b/core/java_common.mk
@@ -15,20 +15,17 @@
# Modules can override this logic by specifying
# LOCAL_JAVA_LANGUAGE_VERSION explicitly.
ifeq (,$(LOCAL_JAVA_LANGUAGE_VERSION))
- private_sdk_versions_without_any_java_18_support := 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
- ifneq (,$(filter $(LOCAL_SDK_VERSION), $(private_sdk_versions_without_any_java_18_support)))
+ ifneq (,$(filter $(LOCAL_SDK_VERSION), $(TARGET_SDK_VERSIONS_WITHOUT_JAVA_18_SUPPORT)))
LOCAL_JAVA_LANGUAGE_VERSION := 1.7
+ else ifneq (,$(filter $(LOCAL_SDK_VERSION), $(TARGET_SDK_VERSIONS_WITHOUT_JAVA_19_SUPPORT)))
+ LOCAL_JAVA_LANGUAGE_VERSION := 1.8
+ else ifneq (,$(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS))
+ # TODO(ccross): allow 1.9 for current and unbundled once we have SDK system modules
+ LOCAL_JAVA_LANGUAGE_VERSION := 1.8
else
- ifneq ($(EXPERIMENTAL_USE_OPENJDK9),true)
- LOCAL_JAVA_LANGUAGE_VERSION := 1.8
- else
- private_sdk_versions_without_any_java_19_support := 24 25 26
- ifneq (,$(filter $(LOCAL_SDK_VERSION), $(private_sdk_versions_without_any_java_19_support)))
- LOCAL_JAVA_LANGUAGE_VERSION := 1.8
- else
- LOCAL_JAVA_LANGUAGE_VERSION := 1.9
- endif
- endif
+ # DEFAULT_JAVA_LANGUAGE_VERSION is 1.8 unless EXPERIMENTAL_USE_OPENJDK9=true
+ # in which case it is 1.9
+ LOCAL_JAVA_LANGUAGE_VERSION := $(DEFAULT_JAVA_LANGUAGE_VERSION)
endif
endif
LOCAL_JAVACFLAGS += -source $(LOCAL_JAVA_LANGUAGE_VERSION) -target $(LOCAL_JAVA_LANGUAGE_VERSION)
@@ -201,6 +198,7 @@
full_java_bootclasspath_libs :=
empty_bootclasspath :=
+my_system_modules :=
# full_java_libs: The list of files that should be used as the classpath.
# Using this list as a dependency list WILL NOT WORK.
@@ -209,8 +207,13 @@
ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
# No bootclasspath. But we still need "" to prevent javac from using default host bootclasspath.
empty_bootclasspath := ""
+ # Most users of LOCAL_NO_STANDARD_LIBRARIES really mean no framework libs,
+ # and manually add back the core libs. The ones that don't are in soong
+ # now, so just always assume that they want the default system modules
+ my_system_modules := $(DEFAULT_SYSTEM_MODULES)
else # LOCAL_NO_STANDARD_LIBRARIES
full_java_bootclasspath_libs := $(call java-lib-header-files,$(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES))
+ my_system_modules := $(DEFAULT_SYSTEM_MODULES)
endif # LOCAL_NO_STANDARD_LIBRARIES
else
ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
@@ -255,6 +258,7 @@
full_java_bootclasspath_libs := $(call java-lib-header-files,$(addsuffix -hostdex,$(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES)),true)
endif
+ my_system_modules := $(DEFAULT_SYSTEM_MODULES)
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
@@ -270,8 +274,25 @@
endif
endif
+full_java_system_modules_deps :=
+my_system_modules_dir :=
+$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_USE_SYSTEM_MODULES :=
+ifeq ($(LOCAL_JAVA_LANGUAGE_VERSION),1.9)
+ $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_USE_SYSTEM_MODULES := true
+ ifdef my_system_modules
+ ifneq ($(my_system_modules),none)
+ ifndef SOONG_SYSTEM_MODULES_$(my_system_modules)
+ $(call pretty-error, Invalid system modules $(my_system_modules))
+ endif
+ full_java_system_modules_deps := $(SOONG_SYSTEM_MODULES_$(my_system_modules))
+ my_system_modules_dir := $(patsubst %/lib/modules,%,$(SOONG_SYSTEM_MODULES_$(my_system_modules)))
+ endif
+ endif
+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)
full_java_libs := $(full_shared_java_libs) $(full_static_java_libs) $(LOCAL_CLASSPATH)
full_java_header_libs := $(full_shared_java_header_libs) $(full_static_java_header_libs)
diff --git a/core/math.mk b/core/math.mk
index 57cb681..44e03ce 100644
--- a/core/math.mk
+++ b/core/math.mk
@@ -72,6 +72,10 @@
$(if $(filter $(1),$(call math_max,$(1),$(2))),true)
endef
+define math_lt
+$(if $(call math_gt_or_eq,$(1),$(2)),,true)
+endef
+
#$(warning $(call math_gt_or_eq, 2, 1))
#$(warning $(call math_gt_or_eq, 1, 1))
#$(warning $(if $(call math_gt_or_eq, 1, 2),false,true))
@@ -81,6 +85,15 @@
$(strip $(eval $(1) := $($(1)) .)$(words $($(1))))
endef
+# Returns the words in $2 that are numbers and are less than $1
+define numbers_less_than
+$(strip \
+ $(foreach n,$2, \
+ $(if $(call math_is_number,$(n)), \
+ $(if $(call math_lt,$(n),$(1)), \
+ $(n)))))
+endef
+
_INT_LIMIT_WORDS := $(foreach a,x x,$(foreach b,x x x x x x x x x x x x x x x x,\
$(foreach c,x x x x x x x x x x x x x x x x,x x x x x x x x x x x x x x x x)))