From f960257c1445149aebbfde386e9330a0c82f2265 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 12 Oct 2017 13:34:40 -0700 Subject: [PATCH] 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 --- core/config.mk | 3 +++ core/definitions.mk | 9 ++++--- core/host_dalvik_java_library.mk | 1 + core/java.mk | 1 + core/java_common.mk | 45 +++++++++++++++++++++++--------- core/math.mk | 13 +++++++++ 6 files changed, 57 insertions(+), 15 deletions(-) diff --git a/core/config.mk b/core/config.mk index 7007c5d1dd..2ce064ff8a 100644 --- a/core/config.mk +++ b/core/config.mk @@ -804,6 +804,9 @@ TARGET_AVAILABLE_SDK_VERSIONS := $(call numerically_sort,\ # 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 1f9891ee42..0e7093e6e9 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -2251,9 +2251,11 @@ $(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR) $(PRIVATE_ANNO_INTERMEDIATES $(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 @@ $(1): \ $(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 96796df177..4bfe288487 100644 --- a/core/host_dalvik_java_library.mk +++ b/core/host_dalvik_java_library.mk @@ -93,6 +93,7 @@ $(full_classes_compiled_jar): \ $(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 cf49994906..7584479efa 100644 --- a/core/java.mk +++ b/core/java.mk @@ -499,6 +499,7 @@ $(full_classes_turbine_jar): \ $(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 320c52f47a..a73c6dbb88 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 @@ $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RMTYPEDEFS := $(LOCAL_RMTYPEDEFS) 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 @@ ifndef LOCAL_IS_HOST_MODULE 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 @@ else # LOCAL_IS_HOST_MODULE 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 @@ ifdef empty_bootclasspath 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 57cb681810..44e03ce826 100644 --- a/core/math.mk +++ b/core/math.mk @@ -72,6 +72,10 @@ define math_gt_or_eq $(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 @@ define inc_and_print $(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)))