Support LOCAL_JACK_ENABLED := javac_frontend

Allow working around Jack bugs by using javac to compile *.java
to class files, and then pass through Jack for desugaring,
proguarding, and dexing.

Also make ANDROID_COMPILE_WITH_JACK=false override LOCAL_JACK_ENABLED.

Bug: 37483961
Test: m -j checkbuild
Test: Add LOCAL_JACK_ENABLED := javac_frontend to a target
Change-Id: I2189055aac9deccc36b8eab8e949796dddadf7a1
This commit is contained in:
Colin Cross 2017-04-27 13:34:02 -07:00
parent 7928afb83d
commit b17f285169
5 changed files with 48 additions and 16 deletions

View File

@ -104,7 +104,7 @@ LOCAL_IS_RUNTIME_RESOURCE_OVERLAY:=
LOCAL_JACK_CLASSPATH:=
LOCAL_JACK_COVERAGE_EXCLUDE_FILTER:=
LOCAL_JACK_COVERAGE_INCLUDE_FILTER:=
# '' (ie disabled), disabled, full, incremental
# '' (ie disabled), disabled, full, incremental, javac_frontend
LOCAL_JACK_ENABLED:=$(DEFAULT_JACK_ENABLED)
LOCAL_JACK_FLAGS:=
LOCAL_JACK_PLUGIN:=

View File

@ -610,11 +610,7 @@ DATA_BINDING_COMPILER := $(HOST_OUT_JAVA_LIBRARIES)/databinding-compiler.jar
FAT16COPY := build/tools/fat16copy.py
CHECK_LINK_TYPE := build/tools/check_link_type.py
ifeq ($(ANDROID_COMPILE_WITH_JACK),true)
DEFAULT_JACK_ENABLED:=full
else
DEFAULT_JACK_ENABLED:=
endif
ifneq ($(ANDROID_JACK_EXTRA_ARGS),)
JACK_DEFAULT_ARGS :=
DEFAULT_JACK_EXTRA_ARGS := $(ANDROID_JACK_EXTRA_ARGS)

View File

@ -18,18 +18,23 @@ ifdef ANDROID_FORCE_JACK_ENABLED
LOCAL_JACK_ENABLED := $(ANDROID_FORCE_JACK_ENABLED)
endif
ifneq ($(ANDROID_COMPILE_WITH_JACK),true)
LOCAL_JACK_ENABLED :=
endif
LOCAL_JACK_ENABLED := $(strip $(LOCAL_JACK_ENABLED))
LOCAL_MODULE := $(strip $(LOCAL_MODULE))
ifneq ($(LOCAL_JACK_ENABLED),full)
ifneq ($(LOCAL_JACK_ENABLED),incremental)
valid_jack_enabled_values := full incremental javac_frontend disabled
ifdef LOCAL_JACK_ENABLED
ifneq ($(LOCAL_JACK_ENABLED),disabled)
$(error $(LOCAL_PATH): invalid LOCAL_JACK_ENABLED "$(LOCAL_JACK_ENABLED)" for $(LOCAL_MODULE))
endif
endif
LOCAL_JACK_ENABLED :=
endif
ifneq ($(LOCAL_JACK_ENABLED),$(filter $(firstword $(LOCAL_JACK_ENABLED)),$(valid_jack_enabled_values)))
$(error $(LOCAL_PATH): invalid LOCAL_JACK_ENABLED "$(LOCAL_JACK_ENABLED)" for $(LOCAL_MODULE))
endif
ifeq ($(LOCAL_JACK_ENABLED),disabled)
LOCAL_JACK_ENABLED :=
endif
endif
ifdef $(LOCAL_MODULE).JACK_VERSION

View File

@ -2262,9 +2262,10 @@ $(hide) mkdir -p $(dir $(PRIVATE_CLASSES_JACK))
$(hide) mkdir -p $(PRIVATE_JACK_INTERMEDIATES_DIR)
$(if $(PRIVATE_JACK_INCREMENTAL_DIR),$(hide) mkdir -p $(PRIVATE_JACK_INCREMENTAL_DIR))
$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list)
$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list; \
fi
$(if $(PRIVATE_SOURCE_INTERMEDIATES_DIR), \
$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list; \
fi)
$(if $(PRIVATE_HAS_PROTO_SOURCES), \
$(hide) find $(PRIVATE_PROTO_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list )
$(if $(PRIVATE_HAS_RS_SOURCES), \
@ -2281,6 +2282,10 @@ $(if $(PRIVATE_EXTRA_JAR_ARGS),
$(hide) $(call add-java-resources-to,$@.res.tmp.zip)
$(hide) unzip -qo $@.res.tmp.zip -d $@.res.tmp
$(hide) rm $@.res.tmp.zip)
$(if $(PRIVATE_JACK_IMPORT_JAR),
$(hide) mkdir -p $@.tmpjill.res
$(hide) unzip -qo $(PRIVATE_JACK_IMPORT_JAR) -d $@.tmpjill.res
$(hide) find $@.tmpjill.res -iname "*.class" -delete)
$(hide) if [ -s $(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \
export tmpEcjArg="@$(PRIVATE_JACK_INTERMEDIATES_DIR)/java-source-list-uniq"; \
else \
@ -2293,6 +2298,8 @@ $(call call-jack) \
-D jack.dex.optimize="false") \
$(if $(PRIVATE_RMTYPEDEFS), \
-D jack.android.remove-typedef="true") \
$(if $(PRIVATE_JACK_IMPORT_JAR), \
--import $(PRIVATE_JACK_IMPORT_JAR) --import-resource $@.tmpjill.res) \
$(addprefix --classpath ,$(strip \
$(call normalize-path-list,$(PRIVATE_JACK_SHARED_LIBRARIES)))) \
$(addprefix --import ,$(call reverse-list,$(PRIVATE_STATIC_JACK_LIBRARIES))) \

View File

@ -340,7 +340,11 @@ endif
ifndef LOCAL_CHECKED_MODULE
ifdef full_classes_jar
ifdef LOCAL_JACK_ENABLED
ifeq ($(LOCAL_JACK_ENABLED),javac_frontend)
LOCAL_CHECKED_MODULE := $(full_classes_compiled_jar)
else
LOCAL_CHECKED_MODULE := $(jack_check_timestamp)
endif
else
ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true)
LOCAL_CHECKED_MODULE := $(full_classes_compiled_jar)
@ -774,6 +778,26 @@ else
$(built_dex_intermediate): PRIVATE_JACK_COVERAGE_OPTIONS :=
endif
# Compiling with javac to jar, then converting jar to dex with jack
ifeq ($(LOCAL_JACK_ENABLED),javac_frontend)
# PRIVATE_EXTRA_JAR_ARGS and source files were already handled during javac
$(built_dex_intermediate): PRIVATE_EXTRA_JAR_ARGS :=
$(built_dex_intermediate): PRIVATE_JAVA_SOURCES :=
$(built_dex_intermediate): PRIVATE_SOURCE_INTERMEDIATES_DIR :=
$(built_dex_intermediate): PRIVATE_HAS_PROTO_SOURCES :=
$(built_dex_intermediate): PRIVATE_HAS_RS_SOURCES :=
# Incremental compilation is not supported when mixing javac and jack
$(built_dex_intermediate): PRIVATE_JACK_INCREMENTAL_DIR :=
# Pass output of javac to jack
$(built_dex_intermediate): PRIVATE_JACK_IMPORT_JAR := $(full_classes_compiled_jar)
$(built_dex_intermediate): $(full_classes_compiled_jar)
else # LOCAL_JACK_ENABLED != javac_frontend
$(built_dex_intermediate): PRIVATE_JACK_IMPORT_JAR :=
endif # LOCAL_JACK_ENABLED != javac_frontend
$(built_dex_intermediate): PRIVATE_JACK_PLUGIN_PATH := $(LOCAL_JACK_PLUGIN_PATH)
$(built_dex_intermediate): PRIVATE_JACK_PLUGIN := $(LOCAL_JACK_PLUGIN)
$(built_dex_intermediate): $(jack_all_deps) $(LOCAL_JACK_PLUGIN_PATH) | setup-jack-server