From 870025f89beccc93a22c9cc17609242e7675a110 Mon Sep 17 00:00:00 2001 From: Nan Zhang Date: Wed, 13 Sep 2017 14:56:11 -0700 Subject: [PATCH] Move classes.jar generation right below JarJar phase. By doing this, we don't need run desugar/Jacoco/proguard twice for static java libraries(one for their self build, another for downstream dependents). Test: m clean && m java Bug: b/65455145 Change-Id: I87aee34940937dbde33a977f55d1faf2c8054561 --- core/host_dalvik_java_library.mk | 30 +++++++++++++++--------------- core/java.mk | 32 ++++++++++++++++---------------- core/java_library.mk | 4 ++-- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/core/host_dalvik_java_library.mk b/core/host_dalvik_java_library.mk index 241cf6ead..37e937551 100644 --- a/core/host_dalvik_java_library.mk +++ b/core/host_dalvik_java_library.mk @@ -145,30 +145,30 @@ endif $(eval $(call copy-one-file,$(full_classes_header_jarjar),$(full_classes_header_jar))) +# Run jarjar if necessary, otherwise just copy the file. +ifneq ($(strip $(LOCAL_JARJAR_RULES)),) +$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES) +$(full_classes_jarjar_jar): $(full_classes_compiled_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR) + @echo JarJar: $@ + $(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@ +else +full_classes_jarjar_jar := $(full_classes_compiled_jar) +endif + +$(eval $(call copy-one-file,$(full_classes_jarjar_jar),$(full_classes_jar))) + my_desugaring := ifeq ($(LOCAL_JAVA_LANGUAGE_VERSION),1.8) my_desugaring := true $(full_classes_desugar_jar): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS) -$(full_classes_desugar_jar): $(full_classes_compiled_jar) $(full_java_header_libs) $(DESUGAR) +$(full_classes_desugar_jar): $(full_classes_jar) $(full_java_header_libs) $(DESUGAR) $(desugar-classes-jar) endif ifndef my_desugaring -full_classes_desugar_jar := $(full_classes_compiled_jar) +full_classes_desugar_jar := $(full_classes_jar) endif -# Run jarjar if necessary, otherwise just copy the file. -ifneq ($(strip $(LOCAL_JARJAR_RULES)),) -$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES) -$(full_classes_jarjar_jar): $(full_classes_desugar_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR) - @echo JarJar: $@ - $(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@ -else -full_classes_jarjar_jar := $(full_classes_desugar_jar) -endif - -$(eval $(call copy-one-file,$(full_classes_jarjar_jar),$(full_classes_jar))) - ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true) # No dex; all we want are the .class files with resources. $(LOCAL_BUILT_MODULE) : $(java_resource_sources) @@ -179,7 +179,7 @@ $(LOCAL_BUILT_MODULE) : $(full_classes_jar) else # !LOCAL_IS_STATIC_JAVA_LIBRARY $(built_dex): PRIVATE_INTERMEDIATES_DIR := $(intermediates.COMMON) $(built_dex): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS) -$(built_dex): $(full_classes_jar) $(DX) +$(built_dex): $(full_classes_desugar_jar) $(DX) $(transform-classes.jar-to-dex) $(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex) diff --git a/core/java.mk b/core/java.mk index cc7036835..b2d3833f3 100644 --- a/core/java.mk +++ b/core/java.mk @@ -527,31 +527,33 @@ else full_classes_processed_jar := $(full_classes_compiled_jar) endif +# Run jarjar if necessary +ifneq ($(strip $(LOCAL_JARJAR_RULES)),) +$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES) +$(full_classes_jarjar_jar): $(full_classes_processed_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR) + @echo JarJar: $@ + $(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@ +else +full_classes_jarjar_jar := $(full_classes_processed_jar) +endif + +$(eval $(call copy-one-file,$(full_classes_jarjar_jar),$(full_classes_jar))) + my_desugaring := ifndef LOCAL_JACK_ENABLED ifndef LOCAL_IS_STATIC_JAVA_LIBRARY my_desugaring := true $(full_classes_desugar_jar): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS) -$(full_classes_desugar_jar): $(full_classes_processed_jar) $(full_java_header_libs) $(DESUGAR) +$(full_classes_desugar_jar): $(full_classes_jar) $(full_java_header_libs) $(DESUGAR) $(desugar-classes-jar) endif endif ifndef my_desugaring -full_classes_desugar_jar := $(full_classes_processed_jar) +full_classes_desugar_jar := $(full_classes_jar) endif -# Run jarjar if necessary -ifneq ($(strip $(LOCAL_JARJAR_RULES)),) -$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES) -$(full_classes_jarjar_jar): $(full_classes_desugar_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR) - @echo JarJar: $@ - $(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@ -else -full_classes_jarjar_jar := $(full_classes_desugar_jar) -endif - -LOCAL_FULL_CLASSES_PRE_JACOCO_JAR := $(full_classes_jarjar_jar) +LOCAL_FULL_CLASSES_PRE_JACOCO_JAR := $(full_classes_desugar_jar) ####################################### include $(BUILD_SYSTEM)/jacoco.mk @@ -702,8 +704,6 @@ else # LOCAL_PROGUARD_ENABLED not defined full_classes_proguard_jar := $(full_classes_pre_proguard_jar) endif # LOCAL_PROGUARD_ENABLED defined -$(eval $(call copy-one-file,$(full_classes_proguard_jar),$(full_classes_jar))) - ifneq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true) ifndef LOCAL_JACK_ENABLED $(built_dex_intermediate): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS) @@ -716,7 +716,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_jar) $(DX) +$(built_dex_intermediate): $(full_classes_proguard_jar) $(DX) $(transform-classes.jar-to-dex) endif # LOCAL_JACK_ENABLED is disabled diff --git a/core/java_library.mk b/core/java_library.mk index db4ccb5a2..f766c0110 100644 --- a/core/java_library.mk +++ b/core/java_library.mk @@ -67,12 +67,12 @@ include $(BUILD_SYSTEM)/java.mk ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true) # 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))) +$(eval $(call copy-one-file,$(full_classes_proguard_jar),$(common_javalib.jar))) ifdef LOCAL_JACK_ENABLED $(eval $(call copy-one-file,$(full_classes_jack),$(LOCAL_BUILT_MODULE))) else -$(eval $(call copy-one-file,$(full_classes_jar),$(LOCAL_BUILT_MODULE))) +$(eval $(call copy-one-file,$(full_classes_proguard_jar),$(LOCAL_BUILT_MODULE))) endif else # !LOCAL_IS_STATIC_JAVA_LIBRARY