From 79e2f73b6c47e89b60cae6b4b2b2bd2ab0a4992a Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 21 Dec 2016 14:29:13 -0800 Subject: [PATCH 1/2] Re-enable dx support This is a partial revert of commits: 858657366fa6 Remove support of disabling Jack. 3ae78612522e Remove javac support in host dex rules. 22313f2b2a4a Remove rules for building dex with dx Test: builds Change-Id: Ie12d743cbe978bdeb030910848b67f5945a4fec8 --- core/clear_vars.mk | 4 +- core/combo/javac.mk | 5 ++ core/config.mk | 5 ++ core/configure_local_jack.mk | 9 +++- core/definitions.mk | 33 ++++++++++++- core/dpi_specific_apk.mk | 14 +++++- core/host_dalvik_java_library.mk | 68 ++++++++++++++++++++++++++ core/java.mk | 82 +++++++++++++++++++++++++++++--- core/java_common.mk | 2 + core/java_library.mk | 22 +++++++++ core/package_internal.mk | 73 +++++++++++++++++++++++----- core/static_java_library.mk | 13 +++-- 12 files changed, 302 insertions(+), 28 deletions(-) diff --git a/core/clear_vars.mk b/core/clear_vars.mk index 614a7ca5e5..da6389190f 100644 --- a/core/clear_vars.mk +++ b/core/clear_vars.mk @@ -62,6 +62,7 @@ LOCAL_DROIDDOC_SOURCE_PATH:= LOCAL_DROIDDOC_STUB_OUT_DIR:= LOCAL_DROIDDOC_TEMPLATE_DIR:= LOCAL_DROIDDOC_USE_STANDARD_DOCLET:= +LOCAL_DX_FLAGS:= LOCAL_EMMA_COVERAGE_FILTER:= LOCAL_EMMA_INSTRUMENT:= LOCAL_EXPORT_C_INCLUDE_DEPS:= @@ -94,8 +95,7 @@ LOCAL_IS_RUNTIME_RESOURCE_OVERLAY:= LOCAL_JACK_CLASSPATH:= LOCAL_JACK_COVERAGE_EXCLUDE_FILTER:= LOCAL_JACK_COVERAGE_INCLUDE_FILTER:= -# full or incremental -LOCAL_JACK_ENABLED:=full +LOCAL_JACK_ENABLED:=$(DEFAULT_JACK_ENABLED) # '' (ie disabled), disabled, full, incremental LOCAL_JACK_FLAGS:= LOCAL_JACK_PLUGIN:= LOCAL_JACK_PLUGIN_PATH:= diff --git a/core/combo/javac.mk b/core/combo/javac.mk index 9042d836e3..7f66ea83a9 100644 --- a/core/combo/javac.mk +++ b/core/combo/javac.mk @@ -9,6 +9,11 @@ # COMMON_JAVAC -- Java compiler command with common arguments # +ifndef ANDROID_COMPILE_WITH_JACK +# Defines if compilation with jack is enabled by default. +ANDROID_COMPILE_WITH_JACK := true +endif + common_jdk_flags := -Xmaxerrs 9999999 # Use the indexer wrapper to index the codebase instead of the javac compiler diff --git a/core/config.mk b/core/config.mk index 2f43f46408..f40f6973d2 100644 --- a/core/config.mk +++ b/core/config.mk @@ -605,6 +605,11 @@ 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) diff --git a/core/configure_local_jack.mk b/core/configure_local_jack.mk index 446bab78df..2270c88c46 100644 --- a/core/configure_local_jack.mk +++ b/core/configure_local_jack.mk @@ -21,9 +21,16 @@ endif LOCAL_JACK_ENABLED := $(strip $(LOCAL_JACK_ENABLED)) LOCAL_MODULE := $(strip $(LOCAL_MODULE)) -ifeq ($(filter full incremental,$(LOCAL_JACK_ENABLED)),) +ifneq ($(LOCAL_JACK_ENABLED),full) +ifneq ($(LOCAL_JACK_ENABLED),incremental) +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 +endif ifdef $(LOCAL_MODULE).JACK_VERSION LOCAL_JACK_VERSION := $($(LOCAL_MODULE).JACK_VERSION) diff --git a/core/definitions.mk b/core/definitions.mk index da5aff10fd..dbbdd1dd82 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -2353,8 +2353,9 @@ $(if $(PRIVATE_HAS_RS_SOURCES), \ $(hide) tr ' ' '\n' < $@.java-source-list \ | sort -u > $@.java-source-list-uniq $(hide) if [ -s $@.java-source-list-uniq ] ; then \ - $(call call-jack) \ + $(call call-jack,$(PRIVATE_JACK_EXTRA_ARGS)) \ $(strip $(PRIVATE_JACK_FLAGS)) \ + $(strip $(PRIVATE_JACK_DEBUG_FLAGS)) \ $(addprefix --classpath ,$(strip \ $(call normalize-path-list,$(call reverse-list,$(PRIVATE_STATIC_JACK_LIBRARIES)) $(PRIVATE_JACK_SHARED_LIBRARIES)))) \ -D jack.import.resource.policy=keep-first \ @@ -2514,6 +2515,25 @@ $(hide) java -classpath $(EMMA_JAR) emma instr -outmode fullcopy -outfile \ $(addprefix -ix , $(PRIVATE_EMMA_COVERAGE_FILTER)) endef +#TODO: use a smaller -Xmx value for most libraries; +# only core.jar and framework.jar need a heap this big. +define transform-classes.jar-to-dex +@echo "target Dex: $(PRIVATE_MODULE)" +@mkdir -p $(dir $@) +$(hide) rm -f $(dir $@)classes*.dex +$(hide) $(DX) \ + -JXms16M -JXmx2048M \ + --dex --output=$(dir $@) \ + $(if $(NO_OPTIMIZE_DX), \ + --no-optimize) \ + $(if $(GENERATE_DEX_DEBUG), \ + --debug --verbose \ + --dump-to=$(@:.dex=.lst) \ + --dump-width=1000) \ + $(PRIVATE_DX_FLAGS) \ + $< +endef + # Create a mostly-empty .jar file that we'll add to later. # The MacOS jar tool doesn't like creating empty jar files, # so we need to give it something. @@ -2533,6 +2553,17 @@ define create-empty-package $(call create-empty-package-at,$@) endef +# Copy an arhchive file and delete any class files and empty folders inside. +# $(1): the source archive file. +# $(2): the destination archive file. +define initialize-package-file +@mkdir -p $(dir $(2)) +$(hide) cp -f $(1) $(2) +$(hide) zip -qd $(2) "*.class" \ + $(if $(strip $(PRIVATE_DONT_DELETE_JAR_DIRS)),,"*/") \ + || true # Ignore the error when nothing to delete. +endef + #TODO: we kinda want to build different asset packages for # different configurations, then combine them later (or something). # Per-locale, etc. diff --git a/core/dpi_specific_apk.mk b/core/dpi_specific_apk.mk index bcc5c18f10..1ca01d514e 100644 --- a/core/dpi_specific_apk.mk +++ b/core/dpi_specific_apk.mk @@ -31,9 +31,15 @@ $(built_dpi_apk): PRIVATE_CERTIFICATE := $(certificate) $(built_dpi_apk): $(additional_certificates) $(built_dpi_apk): PRIVATE_ADDITIONAL_CERTIFICATES := $(additional_certificates) +$(built_dpi_apk): PRIVATE_SOURCE_ARCHIVE := ifneq ($(full_classes_jar),) -$(built_dpi_apk): PRIVATE_JACK_INTERMEDIATES_DIR := $(intermediates.COMMON)/jack-rsc $(built_dpi_apk): PRIVATE_DEX_FILE := $(built_dex) +ifndef LOCAL_JACK_ENABLED +# Use the jarjar processed arhive as the initial package file. +$(built_dpi_apk): PRIVATE_SOURCE_ARCHIVE := $(full_classes_jarjar_jar) +else +$(built_dpi_apk): PRIVATE_JACK_INTERMEDIATES_DIR := $(intermediates.COMMON)/jack-rsc +endif # LOCAL_JACK_ENABLED $(built_dpi_apk): $(built_dex) else $(built_dpi_apk): PRIVATE_DEX_FILE := @@ -46,7 +52,9 @@ $(built_dpi_apk) : $(private_key) $(certificate) $(SIGNAPK_JAR) $(built_dpi_apk) : $(AAPT) $(built_dpi_apk) : $(all_res_assets) $(jni_shared_libraries) $(full_android_manifest) @echo "target Package: $(PRIVATE_MODULE) ($@)" - $(create-empty-package) + $(if $(PRIVATE_SOURCE_ARCHIVE),\ + $(call initialize-package-file,$(PRIVATE_SOURCE_ARCHIVE),$@),\ + $(create-empty-package)) $(add-assets-to-package) ifneq ($(jni_shared_libraries),) $(add-jni-shared-libs-to-package) @@ -56,7 +64,9 @@ ifeq ($(full_classes_jar),) $(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@)) else $(add-dex-to-package) +ifdef LOCAL_JACK_ENABLED $(add-carried-jack-resources) +endif endif $(sign-package) diff --git a/core/host_dalvik_java_library.mk b/core/host_dalvik_java_library.mk index 64b610e6a9..0e358447fe 100644 --- a/core/host_dalvik_java_library.mk +++ b/core/host_dalvik_java_library.mk @@ -31,27 +31,39 @@ include $(BUILD_SYSTEM)/configure_local_jack.mk ####################################### include $(BUILD_SYSTEM)/host_java_library_common.mk ####################################### +ifdef LOCAL_JACK_ENABLED ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true) # For static library, $(LOCAL_BUILT_MODULE) is $(full_classes_jack). LOCAL_BUILT_MODULE_STEM := classes.jack endif +endif ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) LOCAL_JAVA_LIBRARIES := core-oj-hostdex core-libart-hostdex $(LOCAL_JAVA_LIBRARIES) endif +full_classes_compiled_jar := $(intermediates.COMMON)/classes-full-debug.jar +full_classes_jarjar_jar := $(intermediates.COMMON)/classes-jarjar.jar +full_classes_jar := $(intermediates.COMMON)/classes.jar full_classes_jack := $(intermediates.COMMON)/classes.jack jack_check_timestamp := $(intermediates.COMMON)/jack.check.timestamp built_dex := $(intermediates.COMMON)/classes.dex LOCAL_INTERMEDIATE_TARGETS += \ + $(full_classes_compiled_jar) \ + $(full_classes_jarjar_jar) \ $(full_classes_jack) \ + $(full_classes_jar) \ $(jack_check_timestamp) \ $(built_dex) # See comment in java.mk ifndef LOCAL_CHECKED_MODULE +ifdef LOCAL_JACK_ENABLED LOCAL_CHECKED_MODULE := $(jack_check_timestamp) +else +LOCAL_CHECKED_MODULE := $(full_classes_compiled_jar) +endif endif ####################################### @@ -65,6 +77,61 @@ include $(BUILD_SYSTEM)/java_common.mk $(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON) +ifndef LOCAL_JACK_ENABLED + +$(full_classes_compiled_jar): PRIVATE_JAVA_LAYERS_FILE := $(layers_file) +$(full_classes_compiled_jar): PRIVATE_JAVACFLAGS := $(GLOBAL_JAVAC_DEBUG_FLAGS) $(LOCAL_JAVACFLAGS) +$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_FILES := +$(full_classes_compiled_jar): PRIVATE_JAR_PACKAGES := +$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_PACKAGES := +$(full_classes_compiled_jar): \ + $(java_sources) \ + $(java_resource_sources) \ + $(full_java_lib_deps) \ + $(jar_manifest_file) \ + $(proto_java_sources_file_stamp) \ + $(LOCAL_ADDITIONAL_DEPENDENCIES) + $(transform-host-java-to-package) + +# 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) | $(ACP) + @echo Copying: $@ + $(hide) $(ACP) -fp $< $@ +endif + +$(full_classes_jar): $(full_classes_jarjar_jar) | $(ACP) + @echo Copying: $@ + $(hide) $(ACP) -fp $< $@ + +ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true) +# No dex; all we want are the .class files with resources. +$(LOCAL_BUILT_MODULE) : $(java_resource_sources) +$(LOCAL_BUILT_MODULE) : $(full_classes_jar) + @echo "host Static Jar: $(PRIVATE_MODULE) ($@)" + $(copy-file-to-target) + +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) + $(transform-classes.jar-to-dex) + +$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex) +$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_jarjar_jar) +$(LOCAL_BUILT_MODULE): PRIVATE_DONT_DELETE_JAR_DIRS := $(LOCAL_DONT_DELETE_JAR_DIRS) +$(LOCAL_BUILT_MODULE): $(built_dex) $(java_resource_sources) + @echo "Host Jar: $(PRIVATE_MODULE) ($@)" + $(call initialize-package-file,$(PRIVATE_SOURCE_ARCHIVE),$@) + $(add-dex-to-package) + +endif # !LOCAL_IS_STATIC_JAVA_LIBRARY +else # LOCAL_JACK_ENABLED $(LOCAL_INTERMEDIATE_TARGETS): \ PRIVATE_JACK_INTERMEDIATES_DIR := $(intermediates.COMMON)/jack-rsc @@ -116,6 +183,7 @@ endif # LOCAL_IS_STATIC_JAVA_LIBRARY $(jack_check_timestamp): $(jack_all_deps) | setup-jack-server @echo Checking build with Jack: $@ $(jack-check-java) +endif # LOCAL_JACK_ENABLED USE_CORE_LIB_BOOTCLASSPATH := diff --git a/core/java.mk b/core/java.mk index baf097b010..d5fcf61a88 100644 --- a/core/java.mk +++ b/core/java.mk @@ -96,14 +96,34 @@ endif intermediates := $(call local-intermediates-dir) intermediates.COMMON := $(call local-intermediates-dir,COMMON) +# Choose leaf name for the compiled jar file. +ifeq ($(LOCAL_EMMA_INSTRUMENT),true) +full_classes_compiled_jar_leaf := classes-no-debug-var.jar +built_dex_intermediate_leaf := no-local +else +full_classes_compiled_jar_leaf := classes-full-debug.jar +built_dex_intermediate_leaf := with-local +endif + ifeq ($(LOCAL_PROGUARD_ENABLED),disabled) LOCAL_PROGUARD_ENABLED := endif -full_classes_compiled_jar := $(intermediates.COMMON)/classes-full-debug.jar -full_classes_jarjar_jar := $(intermediates.COMMON)/classes-jarjar.jar -full_classes_proguard_jar := $(intermediates.COMMON)/proguard.classes.jar -built_dex_intermediate := $(intermediates.COMMON)/dex-dir/classes.dex +ifdef LOCAL_PROGUARD_ENABLED +proguard_jar_leaf := proguard.classes.jar +else +proguard_jar_leaf := noproguard.classes.jar +endif + +full_classes_compiled_jar := $(intermediates.COMMON)/$(full_classes_compiled_jar_leaf) +jarjar_leaf := classes-jarjar.jar +full_classes_jarjar_jar := $(intermediates.COMMON)/$(jarjar_leaf) +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/$(jarjar_leaf) +full_classes_proguard_jar := $(intermediates.COMMON)/$(proguard_jar_leaf) +built_dex_intermediate := $(intermediates.COMMON)/$(built_dex_intermediate_leaf)/classes.dex full_classes_stubs_jar := $(intermediates.COMMON)/stubs.jar ifeq ($(LOCAL_MODULE_CLASS)$(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),APPS) @@ -123,6 +143,7 @@ jack_check_timestamp := $(intermediates.COMMON)/jack.check.timestamp LOCAL_INTERMEDIATE_TARGETS += \ $(full_classes_compiled_jar) \ $(full_classes_jarjar_jar) \ + $(full_classes_emma_jar) \ $(full_classes_jar) \ $(full_classes_proguard_jar) \ $(built_dex_intermediate) \ @@ -322,7 +343,11 @@ endif # command line. ifndef LOCAL_CHECKED_MODULE ifdef full_classes_jar +ifdef LOCAL_JACK_ENABLED LOCAL_CHECKED_MODULE := $(jack_check_timestamp) +else +LOCAL_CHECKED_MODULE := $(full_classes_compiled_jar) +endif endif endif @@ -433,8 +458,31 @@ $(full_classes_jarjar_jar): $(full_classes_compiled_jar) | $(ACP) $(hide) $(ACP) -fp $< $@ endif +ifeq ($(LOCAL_EMMA_INSTRUMENT),true) +$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILE := $(intermediates.COMMON)/coverage.emma.ignore +$(full_classes_emma_jar): PRIVATE_EMMA_INTERMEDIATES_DIR := $(emma_intermediates_dir) +# module level coverage filter can be defined using LOCAL_EMMA_COVERAGE_FILTER +# in Android.mk +ifdef LOCAL_EMMA_COVERAGE_FILTER +$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILTER := $(LOCAL_EMMA_COVERAGE_FILTER) +else +# by default, avoid applying emma instrumentation onto emma classes itself, +# otherwise there will be exceptions thrown +$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILTER := *,-emma,-emmarun,-com.vladium.* +endif +# this rule will generate both $(PRIVATE_EMMA_COVERAGE_FILE) and +# $(full_classes_emma_jar) +$(full_classes_emma_jar): $(full_classes_jarjar_jar) | $(EMMA_JAR) + $(transform-classes.jar-to-emma) + +else +$(full_classes_emma_jar): $(full_classes_jarjar_jar) + @echo Copying: $@ + $(copy-file-to-target) +endif + # Keep a copy of the jar just before proguard processing. -$(full_classes_jar): $(full_classes_jarjar_jar) | $(ACP) +$(full_classes_jar): $(full_classes_emma_jar) | $(ACP) @echo Copying: $@ $(hide) $(ACP) -fp $< $@ @@ -481,7 +529,11 @@ common_proguard_flag_files := ifeq ($(filter nosystem,$(LOCAL_PROGUARD_ENABLED)),) common_proguard_flag_files += $(BUILD_SYSTEM)/proguard.flags ifeq ($(LOCAL_EMMA_INSTRUMENT),true) +ifdef LOCAL_JACK_ENABLED common_proguard_flag_files += $(BUILD_SYSTEM)/proguard.jacoco.flags +else +common_proguard_flags += -include $(BUILD_SYSTEM)/proguard.emma.flags +endif # LOCAL_JACK_ENABLED endif # If this is a test package, add proguard keep flags for tests. ifneq ($(LOCAL_INSTRUMENTATION_FOR)$(filter tests,$(LOCAL_MODULE_TAGS)),) @@ -521,9 +573,10 @@ legacy_proguard_flags := -injars $(link_instr_classes_jar) \ -applymapping $(link_instr_intermediates_dir.COMMON)/proguard_dictionary \ -verbose \ $(legacy_proguard_flags) - +ifdef LOCAL_JACK_ENABLED jack_proguard_flags += -applymapping $(link_instr_intermediates_dir.COMMON)/jack_dictionary full_jack_deps += $(link_instr_intermediates_dir.COMMON)/jack_dictionary +endif # Sometimes (test + main app) uses different keep rules from the main app - # apply the main app's dictionary anyway. @@ -556,6 +609,21 @@ $(full_classes_proguard_jar) : $(full_classes_jar) | $(ACP) endif # LOCAL_PROGUARD_ENABLED defined +ifndef LOCAL_JACK_ENABLED +$(built_dex_intermediate): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS) +# If you instrument class files that have local variable debug information in +# them emma does not correctly maintain the local variable table. +# This will cause an error when you try to convert the class files for Android. +# The workaround here is to build different dex file here based on emma switch +# then later copy into classes.dex. When emma is on, dx is run with --no-locals +# option to remove local variable information +ifeq ($(LOCAL_EMMA_INSTRUMENT),true) +$(built_dex_intermediate): PRIVATE_DX_FLAGS += --no-locals +endif +$(built_dex_intermediate): $(full_classes_proguard_jar) $(DX) + $(transform-classes.jar-to-dex) +endif # LOCAL_JACK_ENABLED is disabled + $(built_dex): $(built_dex_intermediate) | $(ACP) @echo Copying: $@ $(hide) mkdir -p $(dir $@) @@ -588,6 +656,7 @@ $(LOCAL_MODULE)-findbugs : $(findbugs_html) endif # full_classes_jar is defined +ifdef LOCAL_JACK_ENABLED $(LOCAL_INTERMEDIATE_TARGETS): \ PRIVATE_JACK_INTERMEDIATES_DIR := $(intermediates.COMMON)/jack-rsc ifeq ($(LOCAL_JACK_ENABLED),incremental) @@ -689,3 +758,4 @@ $(noshrob_classes_jack): $(jack_all_deps) $(LOCAL_JACK_PLUGIN_PATH) | setup-jack @echo Building with Jack: $@ $(java-to-jack) endif # full_classes_jar is defined +endif # LOCAL_JACK_ENABLED diff --git a/core/java_common.mk b/core/java_common.mk index dbdea26a10..8fc4fb66b4 100644 --- a/core/java_common.mk +++ b/core/java_common.mk @@ -320,6 +320,7 @@ ALL_MODULES.$(my_register_name).INTERMEDIATE_SOURCE_DIR := \ ########################################################### # JACK ########################################################### +ifdef LOCAL_JACK_ENABLED ifdef need_compile_java LOCAL_JACK_FLAGS += -D jack.java.source.version=$(LOCAL_JAVA_LANGUAGE_VERSION) @@ -373,6 +374,7 @@ $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_SHARED_LIBRARIES:= $(full_shared_jac $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES) endif # need_compile_java +endif # LOCAL_JACK_ENABLED ########################################################### diff --git a/core/java_library.mk b/core/java_library.mk index b132fa68fa..f770a54fba 100644 --- a/core/java_library.mk +++ b/core/java_library.mk @@ -29,9 +29,11 @@ LOCAL_BUILT_MODULE_STEM := javalib.jar include $(BUILD_SYSTEM)/configure_local_jack.mk ################################# +ifdef LOCAL_JACK_ENABLED ifdef LOCAL_IS_STATIC_JAVA_LIBRARY LOCAL_BUILT_MODULE_STEM := classes.jack endif +endif intermediates.COMMON := $(call local-intermediates-dir,COMMON) @@ -46,8 +48,12 @@ endif ifeq (true,$(EMMA_INSTRUMENT)) ifeq (true,$(LOCAL_EMMA_INSTRUMENT)) ifeq (true,$(EMMA_INSTRUMENT_STATIC)) +ifdef LOCAL_JACK_ENABLED # Jack supports coverage with Jacoco LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent +else +LOCAL_STATIC_JAVA_LIBRARIES += emma +endif # LOCAL_JACK_ENABLED endif # LOCAL_EMMA_INSTRUMENT endif # EMMA_INSTRUMENT_STATIC else @@ -61,21 +67,37 @@ 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) +ifdef LOCAL_PROGUARD_ENABLED +$(common_javalib.jar) : $(full_classes_proguard_jar) +else $(common_javalib.jar) : $(full_classes_jar) +endif @echo "target Static Jar: $(PRIVATE_MODULE) ($@)" $(copy-file-to-target) +ifdef LOCAL_JACK_ENABLED $(LOCAL_BUILT_MODULE) : $(full_classes_jack) +else +$(LOCAL_BUILT_MODULE) : $(common_javalib.jar) +endif $(copy-file-to-target) else # !LOCAL_IS_STATIC_JAVA_LIBRARY $(common_javalib.jar): PRIVATE_DEX_FILE := $(built_dex) +$(common_javalib.jar): PRIVATE_SOURCE_ARCHIVE := $(full_classes_jarjar_jar) +$(common_javalib.jar): PRIVATE_DONT_DELETE_JAR_DIRS := $(LOCAL_DONT_DELETE_JAR_DIRS) $(common_javalib.jar) : $(built_dex) $(java_resource_sources) | $(ZIPTIME) @echo "target Jar: $(PRIVATE_MODULE) ($@)" +ifdef LOCAL_JACK_ENABLED $(create-empty-package) +else + $(call initialize-package-file,$(PRIVATE_SOURCE_ARCHIVE),$@) +endif $(add-dex-to-package) +ifdef LOCAL_JACK_ENABLED $(add-carried-jack-resources) +endif $(remove-timestamps-from-package) ifdef LOCAL_DEX_PREOPT diff --git a/core/package_internal.mk b/core/package_internal.mk index 694716a969..2e4878d6c0 100644 --- a/core/package_internal.mk +++ b/core/package_internal.mk @@ -209,10 +209,12 @@ endif # need_compile_res endif # !custom LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS) +ifdef LOCAL_JACK_ENABLED ifndef LOCAL_JACK_PROGUARD_FLAGS LOCAL_JACK_PROGUARD_FLAGS := $(LOCAL_PROGUARD_FLAGS) endif LOCAL_JACK_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_JACK_PROGUARD_FLAGS) +endif # LOCAL_JACK_ENABLED ifeq (true,$(EMMA_INSTRUMENT)) ifndef LOCAL_EMMA_INSTRUMENT @@ -225,22 +227,35 @@ else LOCAL_EMMA_INSTRUMENT := false endif # EMMA_INSTRUMENT is true -ifneq ($(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),) -# Only add jacocoagent if the package contains some java code ifeq (true,$(LOCAL_EMMA_INSTRUMENT)) ifeq (true,$(EMMA_INSTRUMENT_STATIC)) +ifdef LOCAL_JACK_ENABLED # Jack supports coverage with Jacoco +ifneq ($(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),) +# Only add jacocoagent if the package contains some java code LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent -else # ! EMMA_INSTRUMENT_STATIC +endif # Contains java code +else +LOCAL_STATIC_JAVA_LIBRARIES += emma +endif # LOCAL_JACK_ENABLED +else ifdef LOCAL_SDK_VERSION ifdef TARGET_BUILD_APPS # In unbundled build, merge the coverage library into the apk. +ifdef LOCAL_JACK_ENABLED # Jack supports coverage with Jacoco +ifneq ($(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),) +# Only add jacocoagent if the package contains some java code LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent # Exclude jacoco classes from proguard LOCAL_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags LOCAL_JACK_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags -else # ! TARGET_BUILD_APPS +endif # Contains java code +else # ! LOCAL_JACK_ENABLED +LOCAL_STATIC_JAVA_LIBRARIES += emma +endif # ! LOCAL_JACK_ENABLED +else # ! TARGET_BUILD_APPS +ifdef LOCAL_JACK_ENABLED # If build against the SDK in full build, core.jar is not used # so coverage classes are not present. # Jack needs jacoco on the classpath but we do not want it to be in @@ -249,11 +264,16 @@ else # ! TARGET_BUILD_APPS # Note: we have nothing to do for proguard since jacoco will be # on the classpath only, thus not modified during the compilation. LOCAL_JAVA_LIBRARIES += jacocoagent -endif # TARGET_BUILD_APPS +else # ! LOCAL_JACK_ENABLED +# If build against the SDK in full build, core.jar is not used, +# we have to use prebiult emma.jar to make Proguard happy; +# Otherwise emma classes are included in core.jar. +LOCAL_PROGUARD_FLAGS += -libraryjars $(EMMA_JAR) +endif # ! LOCAL_JACK_ENABLED +endif # ! TARGET_BUILD_APPS endif # LOCAL_SDK_VERSION -endif # ! EMMA_INSTRUMENT_STATIC +endif # EMMA_INSTRUMENT_STATIC endif # LOCAL_EMMA_INSTRUMENT -endif # Contains java code rs_compatibility_jni_libs := @@ -374,13 +394,30 @@ endif endif # LOCAL_USE_AAPT2 -# Make sure to generate R.java before compiling. # Other modules should depend on the BUILT module if # they want to use this module's R.java file. -$(LOCAL_BUILT_MODULE) \ -$(full_classes_compiled_jar) \ -$(built_dex_intermediate) $(noshrob_classes_jack) $(full_classes_jack) $(jack_check_timestamp) \ - : $(R_file_stamp) +$(LOCAL_BUILT_MODULE): $(R_file_stamp) + +ifdef LOCAL_JACK_ENABLED +ifneq ($(built_dex_intermediate),) +$(built_dex_intermediate): $(R_file_stamp) +endif +ifneq ($(noshrob_classes_jack),) +$(noshrob_classes_jack): $(R_file_stamp) +endif +ifneq ($(full_classes_jack),) +$(full_classes_jack): $(R_file_stamp) +$(jack_check_timestamp): $(R_file_stamp) +endif +endif # LOCAL_JACK_ENABLED + +ifneq ($(full_classes_jar),) +# If full_classes_jar is non-empty, we're building sources. +# If we're building sources, the initial javac step (which +# produces full_classes_compiled_jar) needs to ensure the +# R.java and Manifest.java files have been generated first. +$(full_classes_compiled_jar): $(R_file_stamp) +endif endif # need_compile_res @@ -426,9 +463,12 @@ endif # LOCAL_NO_STANDARD_LIBRARIES ifneq ($(full_classes_jar),) $(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex) +# Use the jarjar processed arhive as the initial package file. +$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_jarjar_jar) $(LOCAL_BUILT_MODULE): $(built_dex) else $(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := +$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := endif # full_classes_jar include $(BUILD_SYSTEM)/install_jni_libs.mk @@ -487,6 +527,7 @@ else $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := $(PRODUCT_AAPT_PREF_CONFIG) endif endif +$(LOCAL_BUILT_MODULE): PRIVATE_DONT_DELETE_JAR_DIRS := $(LOCAL_DONT_DELETE_JAR_DIRS) $(LOCAL_BUILT_MODULE) : $(jni_shared_libraries) ifdef LOCAL_USE_AAPT2 $(LOCAL_BUILT_MODULE): PRIVATE_RES_PACKAGE := $(my_res_package) @@ -498,7 +539,13 @@ endif ifdef LOCAL_USE_AAPT2 $(call copy-file-to-new-target) else # ! LOCAL_USE_AAPT2 +ifdef LOCAL_JACK_ENABLED $(create-empty-package) +else + $(if $(PRIVATE_SOURCE_ARCHIVE),\ + $(call initialize-package-file,$(PRIVATE_SOURCE_ARCHIVE),$@),\ + $(create-empty-package)) +endif $(add-assets-to-package) endif # LOCAL_USE_AAPT2 ifneq ($(jni_shared_libraries),) @@ -510,7 +557,9 @@ ifeq ($(full_classes_jar),) else # full_classes_jar $(add-dex-to-package) endif # full_classes_jar +ifdef LOCAL_JACK_ENABLED $(add-carried-jack-resources) +endif ifdef LOCAL_DEX_PREOPT ifneq ($(BUILD_PLATFORM_ZIP),) @# Keep a copy of apk with classes.dex unstripped diff --git a/core/static_java_library.mk b/core/static_java_library.mk index 258c5f8d13..eeef4ce641 100644 --- a/core/static_java_library.mk +++ b/core/static_java_library.mk @@ -75,10 +75,12 @@ endif LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS) +ifdef LOCAL_JACK_ENABLED ifndef LOCAL_JACK_PROGUARD_FLAGS LOCAL_JACK_PROGUARD_FLAGS := $(LOCAL_PROGUARD_FLAGS) endif LOCAL_JACK_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_JACK_PROGUARD_FLAGS) +endif # LOCAL_JACK_ENABLED R_file_stamp := $(intermediates.COMMON)/src/R.stamp LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp) @@ -164,10 +166,13 @@ $(R_file_stamp) : $(all_resources) $(full_android_manifest) $(AAPT) $(framework_ $(hide) find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name R.java | xargs cat > $@ endif # LOCAL_USE_AAPT2 -$(LOCAL_BUILT_MODULE) \ -$(full_classes_compiled_jar) \ -$(noshrob_classes_jack) $(full_classes_jack) $(jack_check_timestamp) \ - : $(R_file_stamp) +$(LOCAL_BUILT_MODULE): $(R_file_stamp) +ifdef LOCAL_JACK_ENABLED +$(noshrob_classes_jack): $(R_file_stamp) +$(full_classes_jack): $(R_file_stamp) +$(jack_check_timestamp): $(R_file_stamp) +endif # LOCAL_JACK_ENABLED +$(full_classes_compiled_jar): $(R_file_stamp) # Rule to build AAR, archive including classes.jar, resource, etc. built_aar := $(intermediates.COMMON)/javalib.aar From a341bf0f8636ec42bd87058d9ba31a482cea3b6d Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 15 Feb 2017 13:42:44 -0800 Subject: [PATCH 2/2] Add soong_javac_filter to all javac commands soong_javac_filter colorizes javac output, and hides noisy messages. Test: builds Change-Id: I7e8fcd2e4e1ed3ff530a8ccfe931ceb7e411e0ad --- core/config.mk | 2 ++ core/definitions.mk | 4 ++-- core/host_dalvik_java_library.mk | 2 ++ core/host_java_library.mk | 1 + core/java.mk | 1 + 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/config.mk b/core/config.mk index f40f6973d2..9c926ddc83 100644 --- a/core/config.mk +++ b/core/config.mk @@ -496,6 +496,8 @@ MAINDEXCLASSES := $(HOST_OUT_EXECUTABLES)/mainDexClasses SOONG_ZIP := $(SOONG_HOST_OUT_EXECUTABLES)/soong_zip ZIP2ZIP := $(SOONG_HOST_OUT_EXECUTABLES)/zip2zip +JAVAC_FILTER := $(SOONG_HOST_OUT_EXECUTABLES)/soong_javac_filter + # Always use prebuilts for ckati and makeparallel prebuilt_build_tools := prebuilts/build-tools ifeq ($(filter address,$(SANITIZE_HOST)),) diff --git a/core/definitions.mk b/core/definitions.mk index dbbdd1dd82..72c4c00bde 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -2217,7 +2217,7 @@ $(if $(PRIVATE_HAS_RS_SOURCES), \ $(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \ | $(NORMALIZE_PATH) | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq $(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; then \ - $(1) -encoding UTF-8 \ + ( $(1) -encoding UTF-8 \ $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \ $(2) \ $(addprefix -classpath ,$(strip \ @@ -2226,7 +2226,7 @@ $(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; the -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \ $(PRIVATE_JAVACFLAGS) \ \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \ - || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 ) \ + || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 ) ) 2>&1 | $(JAVAC_FILTER); \ fi $(if $(PRIVATE_JAVA_LAYERS_FILE), $(hide) build/tools/java-layers.py \ $(PRIVATE_JAVA_LAYERS_FILE) \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq,) diff --git a/core/host_dalvik_java_library.mk b/core/host_dalvik_java_library.mk index 0e358447fe..503f67bdf5 100644 --- a/core/host_dalvik_java_library.mk +++ b/core/host_dalvik_java_library.mk @@ -90,6 +90,8 @@ $(full_classes_compiled_jar): \ $(full_java_lib_deps) \ $(jar_manifest_file) \ $(proto_java_sources_file_stamp) \ + $(NORMALIZE_PATH) \ + $(JAVAC_FILTER) \ $(LOCAL_ADDITIONAL_DEPENDENCIES) $(transform-host-java-to-package) diff --git a/core/host_java_library.mk b/core/host_java_library.mk index cc26d7cc9b..ba2999f078 100644 --- a/core/host_java_library.mk +++ b/core/host_java_library.mk @@ -69,6 +69,7 @@ $(full_classes_compiled_jar): \ $(jar_manifest_file) \ $(proto_java_sources_file_stamp) \ $(NORMALIZE_PATH) \ + $(JAVAC_FILTER) \ $(LOCAL_ADDITIONAL_DEPENDENCIES) $(transform-host-java-to-package) diff --git a/core/java.mk b/core/java.mk index d5fcf61a88..1ebe3b5543 100644 --- a/core/java.mk +++ b/core/java.mk @@ -440,6 +440,7 @@ $(full_classes_compiled_jar): \ $(RenderScript_file_stamp) \ $(proto_java_sources_file_stamp) \ $(NORMALIZE_PATH) \ + $(JAVAC_FILTER) \ $(LOCAL_ADDITIONAL_DEPENDENCIES) $(transform-java-to-classes.jar)