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
Bug: 36902714
Change-Id: I6730e2d3ec38004874265b2a690442dec57b33f4
(cherry picked from commit 941b682099)
This commit is contained in:
Colin Cross 2017-03-29 13:53:29 -07:00
parent ffbf0a66d8
commit 69d85288cb
7 changed files with 42 additions and 33 deletions

View file

@ -681,7 +681,7 @@ endef
# $(1): library name # $(1): library name
# $(2): Non-empty if IS_HOST_MODULE # $(2): Non-empty if IS_HOST_MODULE
define _java-lib-full-classes.jar 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 endef
# Get the jar files (you can pass to "javac -classpath") of static or shared # 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)) $(call java-lib-files,$(1),$(2))
endef 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 ..." ## 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 -- # emma is hardcoded to use the leaf name of its input for the output file --
# only the output directory can be changed # only the output directory can be changed
full_classes_emma_jar := $(emma_intermediates_dir)/lib/$(notdir $(full_classes_jarjar_jar)) full_classes_emma_jar := $(emma_intermediates_dir)/lib/$(notdir $(full_classes_jarjar_jar))
full_classes_jar := $(intermediates.COMMON)/classes.jar
LOCAL_INTERMEDIATE_TARGETS += \ LOCAL_INTERMEDIATE_TARGETS += \
$(full_classes_compiled_jar) \ $(full_classes_compiled_jar) \
@ -109,3 +110,4 @@ full_classes_emma_jar := $(full_classes_jarjar_jar)
endif # LOCAL_EMMA_INSTRUMENT 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),$(LOCAL_BUILT_MODULE)))
$(eval $(call copy-one-file,$(full_classes_emma_jar),$(full_classes_jar)))

View file

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

View file

@ -156,7 +156,7 @@ ifdef need_compile_java
full_static_java_libs := \ full_static_java_libs := \
$(foreach lib,$(LOCAL_STATIC_JAVA_LIBRARIES), \ $(foreach lib,$(LOCAL_STATIC_JAVA_LIBRARIES), \
$(call intermediates-dir-for, \ $(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) $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_STATIC_JAVA_LIBRARIES := $(full_static_java_libs)
@ -221,11 +221,11 @@ ifeq ($(USE_CORE_LIB_BOOTCLASSPATH),true)
ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true) ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
my_bootclasspath := "" my_bootclasspath := ""
else 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 endif
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := -bootclasspath $(my_bootclasspath) $(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) full_java_lib_deps := $(full_shared_java_libs)
else # !USE_CORE_LIB_BOOTCLASSPATH else # !USE_CORE_LIB_BOOTCLASSPATH
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH :=

View file

@ -35,9 +35,14 @@ LOCAL_BUILT_MODULE_STEM := classes.jack
endif endif
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) 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 common_javalib.jar := $(intermediates.COMMON)/javalib.jar
LOCAL_INTERMEDIATE_TARGETS += $(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) ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true)
# No dex; all we want are the .class files with resources. # There are some dependencies outside the build system that assume classes.jar
$(common_javalib.jar) : $(java_resource_sources) # is available as javalib.jar so copy it there too.
$(common_javalib.jar) : $(full_classes_jar) $(eval $(call copy-one-file,$(full_classes_jar),$(common_javalib.jar)))
@echo "target Static Jar: $(PRIVATE_MODULE) ($@)"
$(copy-file-to-target)
ifdef LOCAL_JACK_ENABLED ifdef LOCAL_JACK_ENABLED
$(LOCAL_BUILT_MODULE) : $(full_classes_jack) $(eval $(call copy-one-file,$(full_classes_jack),$(LOCAL_BUILT_MODULE)))
else else
$(LOCAL_BUILT_MODULE) : $(common_javalib.jar) $(eval $(call copy-one-file,$(full_classes_jar),$(LOCAL_BUILT_MODULE)))
endif endif
$(copy-file-to-target)
else # !LOCAL_IS_STATIC_JAVA_LIBRARY else # !LOCAL_IS_STATIC_JAVA_LIBRARY
@ -100,8 +102,7 @@ ifdef LOCAL_DEX_PREOPT
ifneq ($(dexpreopt_boot_jar_module),) # boot jar ifneq ($(dexpreopt_boot_jar_module),) # boot jar
# boot jar's rules are defined in dex_preopt.mk # 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 dexpreopted_boot_jar := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(dexpreopt_boot_jar_module)_nodex.jar
$(LOCAL_BUILT_MODULE) : $(dexpreopted_boot_jar) $(eval $(call copy-one-file,$(dexpreopted_boot_jar),$(LOCAL_BUILT_MODULE)))
$(call copy-file-to-target)
# For libart boot jars, we don't have .odex files. # For libart boot jars, we don't have .odex files.
else # ! boot jar else # ! boot jar
@ -111,8 +112,7 @@ $(built_odex) : $(dir $(LOCAL_BUILT_MODULE))% : $(common_javalib.jar)
@echo "Dexpreopt Jar: $(PRIVATE_MODULE) ($@)" @echo "Dexpreopt Jar: $(PRIVATE_MODULE) ($@)"
$(call dexpreopt-one-file,$<,$@) $(call dexpreopt-one-file,$<,$@)
$(LOCAL_BUILT_MODULE) : $(common_javalib.jar) $(eval $(call copy-one-file,$(common_javalib.jar),$(LOCAL_BUILT_MODULE)))
$(call copy-file-to-target)
ifneq (nostripping,$(LOCAL_DEX_PREOPT)) ifneq (nostripping,$(LOCAL_DEX_PREOPT))
$(call dexpreopt-remove-classes.dex,$@) $(call dexpreopt-remove-classes.dex,$@)
endif endif
@ -120,8 +120,7 @@ endif
endif # ! boot jar endif # ! boot jar
else # LOCAL_DEX_PREOPT else # LOCAL_DEX_PREOPT
$(LOCAL_BUILT_MODULE) : $(common_javalib.jar) $(eval $(call copy-one-file,$(common_javalib.jar),$(LOCAL_BUILT_MODULE)))
$(call copy-file-to-target)
endif # LOCAL_DEX_PREOPT endif # LOCAL_DEX_PREOPT
endif # !LOCAL_IS_STATIC_JAVA_LIBRARY endif # !LOCAL_IS_STATIC_JAVA_LIBRARY

View file

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

View file

@ -431,7 +431,22 @@ endif # ! prebuilt_module_is_dex_javalib
ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES) ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
my_src_jar := $(my_prebuilt_src_file) 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, # 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. # 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 common_classes_jar := $(intermediates.COMMON)/classes.jar
@ -524,6 +539,7 @@ endif # LOCAL_IS_HOST_MODULE is not set
ifneq ($(prebuilt_module_is_dex_javalib),true) 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. # 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_FLAGS:=$(LOCAL_JACK_FLAGS)
$(intermediates.COMMON)/classes.jack : PRIVATE_JACK_MIN_SDK_VERSION := $(if $(strip $(LOCAL_MIN_SDK_VERSION)),$(LOCAL_MIN_SDK_VERSION),1) $(intermediates.COMMON)/classes.jack : PRIVATE_JACK_MIN_SDK_VERSION := $(if $(strip $(LOCAL_MIN_SDK_VERSION)),$(LOCAL_MIN_SDK_VERSION),1)
@ -538,7 +554,7 @@ $(intermediates.COMMON)/classes.jack : $(LOCAL_JACK_PLUGIN_PATH) $(my_src_jar) \
# always rebuilt. # always rebuilt.
$(intermediates.COMMON)/classes.dex.toc: $(intermediates.COMMON)/classes.jack $(intermediates.COMMON)/classes.dex.toc: $(intermediates.COMMON)/classes.jack
touch $@ touch $@
endif # LOCAL_JACK_ENABLED
endif # ! prebuilt_module_is_dex_javalib endif # ! prebuilt_module_is_dex_javalib
endif # JAVA_LIBRARIES endif # JAVA_LIBRARIES