From e8ee68bb9b613d7c93c4836e0c90b5de31192dce Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 7 Apr 2017 16:28:41 -0700 Subject: [PATCH] Support java annotation proccessors The codebase is growing more uses of annotation processors, through a mixture of LOCAL_ADDITIONAL_DEPENDENCIES and LOCAL_JACK_FLAGS. Add LOCAL_ANNOTATION_PROCESSORS and handle the rest in the build system. For now we also need LOCAL_ANNOTATION_PROCESSOR_CLASSES to work around bad behavior in grok (b/25860419). Test: m -j java Change-Id: I465b021e65d25ed3ea517333a82ec4ebd63fc038 (cherry picked from commit cde14987ba2a4a054ba4e2f711a4b714dfc54853) --- core/build-system.html | 11 +++++++++++ core/clear_vars.mk | 2 ++ core/definitions.mk | 8 ++++---- core/host_dalvik_java_library.mk | 3 ++- core/host_java_library.mk | 3 ++- core/java.mk | 8 +++++--- core/java_common.mk | 15 +++++++++++++++ 7 files changed, 41 insertions(+), 9 deletions(-) diff --git a/core/build-system.html b/core/build-system.html index e72e1411b..c7938ccfb 100644 --- a/core/build-system.html +++ b/core/build-system.html @@ -592,6 +592,17 @@ alphabetically.

+

LOCAL_ANNOTATION_PROCESSORS

+

Set this to a list of modules built with BUILD_HOST_JAVA_LIBRARY +to have their jars passed to javac with -processorpath for use as annotation +processors.

+ +

LOCAL_ANNOTATION_PROCESSOR_CLASSES

+

Set this to a list of classes to be passed to javac as -processor arguments. +This list is would be unnecessary, as javac will autodetect annotation processor +classes, except that the Grok tool that is used on the Android source code +does not autodetect them and requires listing them manually.

+

LOCAL_ASSET_FILES

In Android.mk files that include $(BUILD_PACKAGE) set this to the set of files you want built into your app. Usually:

diff --git a/core/clear_vars.mk b/core/clear_vars.mk index 37d8364c8..743e73163 100644 --- a/core/clear_vars.mk +++ b/core/clear_vars.mk @@ -12,6 +12,8 @@ LOCAL_ADDITIONAL_HTML_DIR:= LOCAL_ADDITIONAL_JAVA_DIR:= LOCAL_AIDL_INCLUDES:= LOCAL_ALLOW_UNDEFINED_SYMBOLS:= +LOCAL_ANNOTATION_PROCESSORS:= +LOCAL_ANNOTATION_PROCESSOR_CLASSES:= LOCAL_APK_LIBRARIES:= LOCAL_ARM_MODE:= LOCAL_ASFLAGS:= diff --git a/core/definitions.mk b/core/definitions.mk index fab88f369..2d260a151 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -2196,9 +2196,9 @@ endef # $(2): bootclasspath define compile-java $(hide) rm -f $@ -$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) +$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) $(PRIVATE_ANNO_INTERMEDIATES_DIR) $(hide) mkdir -p $(dir $@) -$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR) +$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR) $(PRIVATE_ANNO_INTERMEDIATES_DIR) $(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)) $(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list) $(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \ @@ -2217,7 +2217,7 @@ $(hide) if [ -s $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq ] ; the $(addprefix -classpath ,$(strip \ $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \ $(if $(findstring true,$(PRIVATE_WARNINGS_ENABLE)),$(xlint_unchecked),) \ - -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \ + -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) -s $(PRIVATE_ANNO_INTERMEDIATES_DIR) \ $(PRIVATE_JAVACFLAGS) \ \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \ || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 ) \ @@ -3342,4 +3342,4 @@ $(foreach source,$(ENFORCE_RRO_SOURCES), \ $(eval include $(BUILD_SYSTEM)/generate_enforce_rro.mk) \ $(eval ALL_MODULES.$(enforce_rro_source_module).REQUIRED += $(enforce_rro_module)) \ ) -endef \ No newline at end of file +endef diff --git a/core/host_dalvik_java_library.mk b/core/host_dalvik_java_library.mk index 34e88cebf..a7c1ad692 100644 --- a/core/host_dalvik_java_library.mk +++ b/core/host_dalvik_java_library.mk @@ -86,7 +86,7 @@ $(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_JAVACFLAGS := $(GLOBAL_JAVAC_DEBUG_FLAGS) $(LOCAL_JAVACFLAGS) $(annotation_processor_flags) $(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_FILES := $(full_classes_compiled_jar): PRIVATE_JAR_PACKAGES := $(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_PACKAGES := @@ -96,6 +96,7 @@ $(full_classes_compiled_jar): \ $(full_java_lib_deps) \ $(jar_manifest_file) \ $(proto_java_sources_file_stamp) \ + $(annotation_processor_deps) \ $(LOCAL_ADDITIONAL_DEPENDENCIES) $(transform-host-java-to-package) diff --git a/core/host_java_library.mk b/core/host_java_library.mk index f1da55391..9f640b078 100644 --- a/core/host_java_library.mk +++ b/core/host_java_library.mk @@ -64,7 +64,7 @@ LOCAL_JAVACFLAGS += $(LOCAL_ERROR_PRONE_FLAGS) endif $(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_JAVACFLAGS := $(GLOBAL_JAVAC_DEBUG_FLAGS) $(LOCAL_JAVACFLAGS) $(annotation_processor_flags) $(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_FILES := $(full_classes_compiled_jar): PRIVATE_JAR_PACKAGES := $(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_PACKAGES := @@ -74,6 +74,7 @@ $(full_classes_compiled_jar): \ $(full_java_lib_deps) \ $(jar_manifest_file) \ $(proto_java_sources_file_stamp) \ + $(annotation_processor_deps) \ $(NORMALIZE_PATH) \ $(LOCAL_ADDITIONAL_DEPENDENCIES) $(transform-host-java-to-package) diff --git a/core/java.mk b/core/java.mk index 1ddd23adf..9b0b43ad2 100644 --- a/core/java.mk +++ b/core/java.mk @@ -428,7 +428,7 @@ ifeq ($(RUN_ERROR_PRONE),true) LOCAL_JAVACFLAGS += $(LOCAL_ERROR_PRONE_FLAGS) endif -$(full_classes_compiled_jar): PRIVATE_JAVACFLAGS := $(GLOBAL_JAVAC_DEBUG_FLAGS) $(LOCAL_JAVACFLAGS) +$(full_classes_compiled_jar): PRIVATE_JAVACFLAGS := $(GLOBAL_JAVAC_DEBUG_FLAGS) $(LOCAL_JAVACFLAGS) $(annotation_processor_flags) $(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_FILES := $(LOCAL_JAR_EXCLUDE_FILES) $(full_classes_compiled_jar): PRIVATE_JAR_PACKAGES := $(LOCAL_JAR_PACKAGES) $(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_PACKAGES := $(LOCAL_JAR_EXCLUDE_PACKAGES) @@ -441,6 +441,7 @@ $(full_classes_compiled_jar): \ $(layers_file) \ $(RenderScript_file_stamp) \ $(proto_java_sources_file_stamp) \ + $(annotation_processor_deps) \ $(NORMALIZE_PATH) \ $(LOCAL_ADDITIONAL_DEPENDENCIES) $(transform-java-to-classes.jar) @@ -734,13 +735,14 @@ else # LOCAL_PROGUARD_ENABLED not defined $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_PROGUARD_FLAGS := endif # LOCAL_PROGUARD_ENABLED defined -$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_FLAGS := $(GLOBAL_JAVAC_DEBUG_FLAGS) $(LOCAL_JACK_FLAGS) +$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_FLAGS := $(GLOBAL_JAVAC_DEBUG_FLAGS) $(LOCAL_JACK_FLAGS) $(annotation_processor_flags) $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_VERSION := $(LOCAL_JACK_VERSION) jack_all_deps := $(java_sources) $(java_resource_sources) $(full_jack_deps) \ $(jar_manifest_file) $(layers_file) $(RenderScript_file_stamp) \ $(common_proguard_flag_files) $(proguard_flag_files) \ - $(proto_java_sources_file_stamp) $(LOCAL_ADDITIONAL_DEPENDENCIES) $(LOCAL_JARJAR_RULES) \ + $(proto_java_sources_file_stamp) $(annotation_processor_deps) \ + $(LOCAL_ADDITIONAL_DEPENDENCIES) $(LOCAL_JARJAR_RULES) \ $(NORMALIZE_PATH) $(JACK_DEFAULT_ARGS) $(JACK) $(jack_check_timestamp): $(jack_all_deps) | setup-jack-server diff --git a/core/java_common.mk b/core/java_common.mk index 03856acce..db4ccaa0a 100644 --- a/core/java_common.mk +++ b/core/java_common.mk @@ -153,6 +153,20 @@ endif need_compile_java := $(strip $(all_java_sources)$(all_res_assets)$(java_resource_sources))$(LOCAL_STATIC_JAVA_LIBRARIES)$(filter true,$(LOCAL_SOURCE_FILES_ALL_GENERATED)) ifdef need_compile_java +annotation_processor_flags := +annotation_processor_deps := + +ifdef LOCAL_ANNOTATION_PROCESSORS + annotation_processor_jars := $(call java-lib-deps,$(LOCAL_ANNOTATION_PROCESSORS),true) + annotation_processor_flags += -processorpath $(call normalize-path-list,$(annotation_processor_jars)) + annotation_processor_deps += $(annotation_processor_jars) + + # b/25860419: annotation processors must be explicitly specified for grok + annotation_processor_flags += $(foreach class,$(LOCAL_ANNOTATION_PROCESSOR_CLASSES),-processor $(class)) + + annotation_processor_jars := +endif + full_static_java_libs := \ $(foreach lib,$(LOCAL_STATIC_JAVA_LIBRARIES), \ $(call intermediates-dir-for, \ @@ -164,6 +178,7 @@ $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR) $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASSET_DIR := $(LOCAL_ASSET_DIR) $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CLASS_INTERMEDIATES_DIR := $(intermediates.COMMON)/classes +$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ANNO_INTERMEDIATES_DIR := $(intermediates.COMMON)/anno $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/src $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HAS_PROTO_SOURCES := $(if $(proto_sources),true) $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PROTO_SOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/proto