From 3ca9298d994103549ceed4d42ae54debd922aa0b Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 20 Sep 2016 15:12:30 +0100 Subject: [PATCH] Add support for LOCAL_ERROR_PRONE_FLAGS This will allow individual modules to enable error prone checks as needed so that the change to treat an error prone check as a compiler error can be done atomically with the changes to fix the issues that check reveals. Tested with the following steps, cleaning up the targets in between to ensure that it was rebuilt everytime. Set LOCAL_ERROR_PRONE_FLAGS := -Xep:ClassCanBeStatic:WARN compiler error in junit-params-test target. Built javac-check-junit-params-test with RUN_ERROR_PRONE=true to make sure that compilation failed. Built the javac-check-junit-params-test without RUN_ERROR_PRONE set to make sure that the flag is not included unless explicitly requested. Built the junit-params-test as normal to make sure it still worked properly. Bug: 31507496 Test: See above Change-Id: I88b5800dacd0e30dd9dcfa5f42e89d1428957365 --- core/build-system.html | 5 +++++ core/clear_vars.mk | 1 + core/host_java_library.mk | 5 +++++ core/java.mk | 6 ++++++ 4 files changed, 17 insertions(+) diff --git a/core/build-system.html b/core/build-system.html index 95f35ce827..e72e1411b4 100644 --- a/core/build-system.html +++ b/core/build-system.html @@ -707,6 +707,11 @@ example.

them here. For example:

LOCAL_JAVACFLAGS += -Xlint:deprecation

+

LOCAL_ERROR_PRONE_FLAGS

+

If you have additional flags to pass into the error prone compiler, add +them here. For example:

+

LOCAL_ERROR_PRONE_FLAGS += -Xep:ClassCanBeStatic:ERROR

+

LOCAL_JAVA_LIBRARIES

When linking Java apps and libraries, LOCAL_JAVA_LIBRARIES specifies which sets of java classes to include. Currently there are diff --git a/core/clear_vars.mk b/core/clear_vars.mk index 9e50158efc..1618f42fff 100644 --- a/core/clear_vars.mk +++ b/core/clear_vars.mk @@ -71,6 +71,7 @@ LOCAL_PREBUILT_STRIP_COMMENTS:= LOCAL_INTERMEDIATE_SOURCES:= LOCAL_INTERMEDIATE_SOURCE_DIR:= LOCAL_JAVACFLAGS:= +LOCAL_ERROR_PRONE_FLAGS:= LOCAL_JAVA_LIBRARIES:= LOCAL_JAVA_LAYERS_FILE:= LOCAL_NO_STANDARD_LIBRARIES:= diff --git a/core/host_java_library.mk b/core/host_java_library.mk index cc26d7cc9b..cd12caacf6 100644 --- a/core/host_java_library.mk +++ b/core/host_java_library.mk @@ -57,6 +57,11 @@ include $(BUILD_SYSTEM)/java_common.mk # Run build/tools/java-layers.py for more details. layers_file := $(addprefix $(LOCAL_PATH)/, $(LOCAL_JAVA_LAYERS_FILE)) +# If error prone is enabled then add LOCAL_ERROR_PRONE_FLAGS to LOCAL_JAVACFLAGS +ifeq ($(RUN_ERROR_PRONE),true) +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_JAR_EXCLUDE_FILES := diff --git a/core/java.mk b/core/java.mk index 606b474c1f..a968090dcb 100644 --- a/core/java.mk +++ b/core/java.mk @@ -398,6 +398,12 @@ $(full_classes_compiled_jar): PRIVATE_WARNINGS_ENABLE := $(LOCAL_WARNINGS_ENABLE # This intentionally depends on java_sources, not all_java_sources. # Deps for generated source files must be handled separately, # via deps on the target that generates the sources. + +# If error prone is enabled then add LOCAL_ERROR_PRONE_FLAGS to LOCAL_JAVACFLAGS +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_JAR_EXCLUDE_FILES := $(LOCAL_JAR_EXCLUDE_FILES) $(full_classes_compiled_jar): PRIVATE_JAR_PACKAGES := $(LOCAL_JAR_PACKAGES)