Allow disabling turbine

m -j TURBINE_ENABLED=false will build without turbine.  This is
primarily useful for A/B comparisions of turbine builds, but will
also be used to temporarily disable turbine for unbundled builds
until we have turbine prebuilts.

Bug: 64308460
Test: m -j TURBINE_ENABLED=false java
Test: m -j java
Change-Id: Ie48746c8bfc60c361be9634cb1805ca1c09aa1fe
diff --git a/core/definitions.mk b/core/definitions.mk
index 819a485..14e4509 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -683,9 +683,15 @@
 # Java libraries that you want to link against.
 # $(1): library name list
 # $(2): Non-empty if IS_HOST_MODULE
+ifneq ($(TURBINE_ENABLED),false)
 define java-lib-header-files
 $(foreach lib,$(1),$(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),$(2),COMMON)/classes-header.jar)
 endef
+else
+define java-lib-header-files
+$(call java-lib-files,$(1),$(2))
+endef
+endif
 
 # Get the dependency files (you can put on the right side of "|" of a build rule)
 # of the Java libraries.
@@ -709,9 +715,15 @@
 # Get the header jar files (you can pass to "javac -classpath") of static or shared
 # APK libraries that you want to link against.
 # $(1): library name list
+ifneq ($(TURBINE_ENABLED),false)
 define app-lib-header-files
 $(foreach lib,$(1),$(call intermediates-dir-for,APPS,$(lib),,COMMON)/classes-header.jar)
 endef
+else
+define app-lib-header-files
+$(call app-lib-files,$(1))
+endef
+endif
 
 ###########################################################
 ## Convert "core ext framework" to "out/.../classes.jack ..."
diff --git a/core/host_dalvik_java_library.mk b/core/host_dalvik_java_library.mk
index da80509..7ae4a0a 100644
--- a/core/host_dalvik_java_library.mk
+++ b/core/host_dalvik_java_library.mk
@@ -119,6 +119,8 @@
     | $(SOONG_JAVAC_WRAPPER)
 	$(transform-host-java-to-dalvik-package)
 
+ifneq ($(TURBINE_ENABLED),false)
+
 $(full_classes_turbine_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS) $(annotation_processor_flags)
 $(full_classes_turbine_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
 $(full_classes_turbine_jar): \
@@ -147,6 +149,8 @@
 
 $(eval $(call copy-one-file,$(full_classes_header_jarjar),$(full_classes_header_jar)))
 
+endif # TURBINE_ENABLED != false
+
 $(full_classes_combined_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
 $(full_classes_combined_jar): $(full_classes_compiled_jar) \
                               $(jar_manifest_file) \
diff --git a/core/host_java_library.mk b/core/host_java_library.mk
index 43a04cc..c9499ea 100644
--- a/core/host_java_library.mk
+++ b/core/host_java_library.mk
@@ -122,4 +122,6 @@
 $(eval $(call copy-one-file,$(LOCAL_FULL_CLASSES_JACOCO_JAR),$(LOCAL_BUILT_MODULE)))
 $(eval $(call copy-one-file,$(LOCAL_FULL_CLASSES_JACOCO_JAR),$(full_classes_jar)))
 
+ifneq ($(TURBINE_DISABLED),false)
 $(eval $(call copy-one-file,$(LOCAL_FULL_CLASSES_JACOCO_JAR),$(full_classes_header_jar)))
+endif
diff --git a/core/java.mk b/core/java.mk
index d6c37e5..827176a 100644
--- a/core/java.mk
+++ b/core/java.mk
@@ -499,6 +499,8 @@
     | $(SOONG_JAVAC_WRAPPER)
 	$(transform-java-to-classes.jar)
 
+ifneq ($(TURBINE_ENABLED),false)
+
 $(full_classes_turbine_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS) $(annotation_processor_flags)
 $(full_classes_turbine_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
 $(full_classes_turbine_jar): \
@@ -527,6 +529,8 @@
 
 $(eval $(call copy-one-file,$(full_classes_header_jarjar),$(full_classes_header_jar)))
 
+endif # TURBINE_ENABLED != false
+
 javac-check : $(full_classes_compiled_jar)
 javac-check-$(LOCAL_MODULE) : $(full_classes_compiled_jar)
 
diff --git a/core/java_common.mk b/core/java_common.mk
index 6914667..7107364 100644
--- a/core/java_common.mk
+++ b/core/java_common.mk
@@ -300,7 +300,11 @@
       APPS,$(LOCAL_INSTRUMENTATION_FOR),,COMMON)
   # link against the jar with full original names (before proguard processing).
   link_instr_classes_jar := $(link_instr_intermediates_dir.COMMON)/classes-pre-proguard.jar
-  link_instr_classes_header_jar := $(link_instr_intermediates_dir.COMMON)/classes-header.jar
+  ifneq ($(TURBINE_ENABLED),false)
+    link_instr_classes_header_jar := $(link_instr_intermediates_dir.COMMON)/classes-header.jar
+  else
+    link_instr_classes_header_jar := $(link_instr_intermediates_dir.COMMON)/classes.jar
+  endif
   full_java_libs += $(link_instr_classes_jar)
   full_java_header_libs += $(link_instr_classes_header_jar)
 endif  # LOCAL_INSTRUMENTATION_FOR
diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk
index 24816e9..f1ea70e 100644
--- a/core/prebuilt_internal.mk
+++ b/core/prebuilt_internal.mk
@@ -468,8 +468,10 @@
 $(common_classes_jar) : $(my_src_jar)
 	$(transform-prebuilt-to-target)
 
+ifneq ($(TURBINE_ENABLED),false)
 $(common_header_jar) : $(my_src_jar)
 	$(transform-prebuilt-to-target)
+endif
 
 else # !LOCAL_IS_HOST_MODULE
 # for target java libraries, the LOCAL_BUILT_MODULE is in a product-specific dir,
@@ -520,8 +522,10 @@
 $(common_classes_jar) : $(my_src_jar)
 	$(transform-prebuilt-to-target)
 
+ifneq ($(TURBINE_ENABLED),false)
 $(common_header_jar) : $(my_src_jar)
 	$(transform-prebuilt-to-target)
+endif
 
 $(common_classes_pre_proguard_jar) : $(my_src_jar)
 	$(transform-prebuilt-to-target)
diff --git a/core/soong_java_prebuilt.mk b/core/soong_java_prebuilt.mk
index ce09eb1..9198d68 100644
--- a/core/soong_java_prebuilt.mk
+++ b/core/soong_java_prebuilt.mk
@@ -26,11 +26,13 @@
 
 $(eval $(call copy-one-file,$(LOCAL_FULL_CLASSES_JACOCO_JAR),$(full_classes_jar)))
 
+ifneq ($(TURBINE_DISABLED),false)
 ifdef LOCAL_SOONG_HEADER_JAR
 $(eval $(call copy-one-file,$(LOCAL_SOONG_HEADER_JAR),$(full_classes_header_jar)))
 else
 $(eval $(call copy-one-file,$(full_classes_jar),$(full_classes_header_jar)))
 endif
+endif # TURBINE_DISABLED != false
 
 ifdef LOCAL_SOONG_DEX_JAR
 $(eval $(call copy-one-file,$(LOCAL_SOONG_DEX_JAR),$(common_javalib.jar)))