Rearrange java library outputs

Jack can silently handle using a java library as a static java
library by merging in the java library dex file.  This causes
problems when switching to javac, because dex doesn't support
dex merging with multidex enabled?

Make the output files consistent between java libraries and static
java libraries.  Java libraries will now produce:
classes-pre-proguard.jar: the classes before proguard processing
classes.jar: the final jar file containing classes before dexing
javalib.jar: a jar containing classes.dex

Static java libraries will eventually only produce
classes-pre-proguard.jar and classes.jar.  All inter-library
linking is done with classes.jar, so a java library can be
used as a static java library.

There are too many dependencies outside the build system that
expect javalib.jar to exist for static and host java libraries,
so for now continue to build a javalib.jar that is a copy of
classes.jar.

Test: m -j ANDROID_COMPILE_WITH_JACK=false java
Test: m -j java
Bug: 36901093
Change-Id: I6730e2d3ec38004874265b2a690442dec57b33f4
This commit is contained in:
Colin Cross 2017-03-29 13:53:29 -07:00
parent 950f1efbbc
commit 941b682099
7 changed files with 42 additions and 33 deletions

View File

@ -681,7 +681,7 @@ endef
# $(1): library name
# $(2): Non-empty if IS_HOST_MODULE
define _java-lib-full-classes.jar
$(call _java-lib-dir,$(1),$(2))/$(if $(2),javalib,classes)$(COMMON_JAVA_PACKAGE_SUFFIX)
$(call _java-lib-dir,$(1),$(2))/classes.jar
endef
# Get the jar files (you can pass to "javac -classpath") of static or shared
@ -704,14 +704,6 @@ define java-lib-deps
$(call java-lib-files,$(1),$(2))
endef
# Get the jar files (you can pass to "javac -classpath") of host dalvik Java libraries.
# You can also use them as dependency files.
# A host dalvik Java library is different from a host Java library in that
# the java lib file is classes.jar, not javalib.jar.
# $(1): library name list
define host-dex-java-lib-files
$(foreach lib,$(1),$(call _java-lib-dir,$(lib),true)/classes.jar)
endef
###########################################################
## Convert "core ext framework" to "out/.../classes.jack ..."

View File

@ -37,6 +37,7 @@ emma_intermediates_dir := $(intermediates.COMMON)/emma_out
# emma is hardcoded to use the leaf name of its input for the output file --
# only the output directory can be changed
full_classes_emma_jar := $(emma_intermediates_dir)/lib/$(notdir $(full_classes_jarjar_jar))
full_classes_jar := $(intermediates.COMMON)/classes.jar
LOCAL_INTERMEDIATE_TARGETS += \
$(full_classes_compiled_jar) \
@ -104,3 +105,4 @@ full_classes_emma_jar := $(full_classes_jarjar_jar)
endif # LOCAL_EMMA_INSTRUMENT
$(eval $(call copy-one-file,$(full_classes_emma_jar),$(LOCAL_BUILT_MODULE)))
$(eval $(call copy-one-file,$(full_classes_emma_jar),$(full_classes_jar)))

View File

@ -640,7 +640,7 @@ $(built_dex_intermediate): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
ifeq ($(LOCAL_EMMA_INSTRUMENT),true)
$(built_dex_intermediate): PRIVATE_DX_FLAGS += --no-locals
endif
$(built_dex_intermediate): $(full_classes_proguard_jar) $(DX)
$(built_dex_intermediate): $(full_classes_jar) $(DX)
$(transform-classes.jar-to-dex)
endif # LOCAL_JACK_ENABLED is disabled

View File

@ -151,7 +151,7 @@ ifdef need_compile_java
full_static_java_libs := \
$(foreach lib,$(LOCAL_STATIC_JAVA_LIBRARIES), \
$(call intermediates-dir-for, \
JAVA_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),COMMON)/javalib.jar)
JAVA_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),COMMON)/classes.jar)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_STATIC_JAVA_LIBRARIES := $(full_static_java_libs)
@ -216,11 +216,11 @@ ifeq ($(USE_CORE_LIB_BOOTCLASSPATH),true)
ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
my_bootclasspath := ""
else
my_bootclasspath := $(call normalize-path-list,$(call host-dex-java-lib-files,core-oj-hostdex core-libart-hostdex))
my_bootclasspath := $(call normalize-path-list,$(call java-lib-files,core-oj-hostdex core-libart-hostdex,true))
endif
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := -bootclasspath $(my_bootclasspath)
full_shared_java_libs := $(call host-dex-java-lib-files,$(LOCAL_JAVA_LIBRARIES))
full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),true)
full_java_lib_deps := $(full_shared_java_libs)
else # !USE_CORE_LIB_BOOTCLASSPATH
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH :=

View File

@ -35,9 +35,14 @@ LOCAL_BUILT_MODULE_STEM := classes.jack
endif
endif
# For non-static java libraries, other modules should depend on
# out/target/common/obj/JAVA_LIBRARIES/.../javalib.jar (for jack)
# or out/target/common/obj/JAVA_LIBRARIES/.../classes.jar (for javac).
# For static java libraries, other modules should depend on
# out/target/common/obj/JAVA_LIBRARIES/.../classes.jar
# There are some dependencies outside the build system that assume static
# java libraries produce javalib.jar, so we will copy classes.jar there too.
intermediates.COMMON := $(call local-intermediates-dir,COMMON)
# This file will be the one that other modules should depend on.
common_javalib.jar := $(intermediates.COMMON)/javalib.jar
LOCAL_INTERMEDIATE_TARGETS += $(common_javalib.jar)
@ -65,18 +70,15 @@ include $(BUILD_SYSTEM)/java.mk
#################################
ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true)
# No dex; all we want are the .class files with resources.
$(common_javalib.jar) : $(java_resource_sources)
$(common_javalib.jar) : $(full_classes_jar)
@echo "target Static Jar: $(PRIVATE_MODULE) ($@)"
$(copy-file-to-target)
# There are some dependencies outside the build system that assume classes.jar
# is available as javalib.jar so copy it there too.
$(eval $(call copy-one-file,$(full_classes_jar),$(common_javalib.jar)))
ifdef LOCAL_JACK_ENABLED
$(LOCAL_BUILT_MODULE) : $(full_classes_jack)
$(eval $(call copy-one-file,$(full_classes_jack),$(LOCAL_BUILT_MODULE)))
else
$(LOCAL_BUILT_MODULE) : $(common_javalib.jar)
$(eval $(call copy-one-file,$(full_classes_jar),$(LOCAL_BUILT_MODULE)))
endif
$(copy-file-to-target)
else # !LOCAL_IS_STATIC_JAVA_LIBRARY
@ -100,8 +102,7 @@ ifdef LOCAL_DEX_PREOPT
ifneq ($(dexpreopt_boot_jar_module),) # boot jar
# boot jar's rules are defined in dex_preopt.mk
dexpreopted_boot_jar := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(dexpreopt_boot_jar_module)_nodex.jar
$(LOCAL_BUILT_MODULE) : $(dexpreopted_boot_jar)
$(call copy-file-to-target)
$(eval $(call copy-one-file,$(dexpreopted_boot_jar),$(LOCAL_BUILT_MODULE)))
# For libart boot jars, we don't have .odex files.
else # ! boot jar
@ -111,8 +112,7 @@ $(built_odex) : $(dir $(LOCAL_BUILT_MODULE))% : $(common_javalib.jar)
@echo "Dexpreopt Jar: $(PRIVATE_MODULE) ($@)"
$(call dexpreopt-one-file,$<,$@)
$(LOCAL_BUILT_MODULE) : $(common_javalib.jar)
$(call copy-file-to-target)
$(eval $(call copy-one-file,$(common_javalib.jar),$(LOCAL_BUILT_MODULE)))
ifneq (nostripping,$(LOCAL_DEX_PREOPT))
$(call dexpreopt-remove-classes.dex,$@)
endif
@ -120,8 +120,7 @@ endif
endif # ! boot jar
else # LOCAL_DEX_PREOPT
$(LOCAL_BUILT_MODULE) : $(common_javalib.jar)
$(call copy-file-to-target)
$(eval $(call copy-one-file,$(common_javalib.jar),$(LOCAL_BUILT_MODULE)))
endif # LOCAL_DEX_PREOPT
endif # !LOCAL_IS_STATIC_JAVA_LIBRARY

View File

@ -116,7 +116,7 @@ $(call auto-prebuilt-boilerplate, \
$(prebuilt_module_tags), \
, \
, \
javalib.jar)
$(if $(prebuilt_is_host),classes.jar,javalib.jar))
$(call auto-prebuilt-boilerplate, \
$(prebuilt_static_java_libraries), \
@ -125,7 +125,7 @@ $(call auto-prebuilt-boilerplate, \
$(prebuilt_module_tags), \
, \
true, \
javalib.jar)
classes.jar)
prebuilt_static_libs :=
prebuilt_shared_libs :=

View File

@ -427,7 +427,22 @@ endif # LOCAL_MODULE_CLASS != APPS
ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
my_src_jar := $(my_prebuilt_src_file)
ifeq ($(LOCAL_IS_HOST_MODULE),)
ifdef LOCAL_IS_HOST_MODULE
# for host java libraries deps should be in the common dir, so we make a copy in
# the common dir.
common_classes_jar := $(intermediates.COMMON)/classes.jar
common_javalib_jar := $(intermediates.COMMON)/javalib.jar
$(common_classes_jar) $(common_javalib_jar): PRIVATE_MODULE := $(LOCAL_MODULE)
$(common_classes_jar) : $(my_src_jar)
$(transform-prebuilt-to-target)
$(common_javalib_jar) : $(common_classes_jar)
$(transform-prebuilt-to-target)
else # !LOCAL_IS_HOST_MODULE
# for target java libraries, the LOCAL_BUILT_MODULE is in a product-specific dir,
# while the deps should be in the common dir, so we make a copy in the common dir.
common_classes_jar := $(intermediates.COMMON)/classes.jar
@ -520,6 +535,7 @@ endif # LOCAL_IS_HOST_MODULE is not set
ifneq ($(prebuilt_module_is_dex_javalib),true)
ifdef LOCAL_JACK_ENABLED
# We may be building classes.jack from a host jar for host dalvik Java library.
$(intermediates.COMMON)/classes.jack : PRIVATE_JACK_FLAGS:=$(LOCAL_JACK_FLAGS)
$(intermediates.COMMON)/classes.jack : PRIVATE_JACK_MIN_SDK_VERSION := $(if $(strip $(LOCAL_MIN_SDK_VERSION)),$(LOCAL_MIN_SDK_VERSION),1)
@ -534,7 +550,7 @@ $(intermediates.COMMON)/classes.jack : $(LOCAL_JACK_PLUGIN_PATH) $(my_src_jar) \
# always rebuilt.
$(intermediates.COMMON)/classes.dex.toc: $(intermediates.COMMON)/classes.jack
touch $@
endif # LOCAL_JACK_ENABLED
endif # ! prebuilt_module_is_dex_javalib
endif # JAVA_LIBRARIES