Build modules from source by default.
Most branches, most of the time, will build modules from source. By
changing the default we make it easier to switch a whole branch to use
module prebuilts by requiring only one CL to be committed on that branch
and nowhere else.
Before this change, dozens of Soong targets needed to be updated when
deciding to start using prebuilts for modules and sdk stubs. In
addition, the typical need is to enable prebuilts on a single branch at
the time, which resulted in a dozens of "D0 N0T MERGE ANYWHERE" CLs,
causing a lot of confusion.
Bug: 184842499
Test: (on a branch with ModuleMetadataGoogle enabled as prebuilt):
m out/target/product/sunfish/product/app/ModuleMetadataGoogle/ModuleMetadataGoogle.apk
(verified with `aapt2 dump badging` that apk is built from source)
MODULE_BUILD_FROM_SOURCE=false m out/target/product/sunfish/product/app/ModuleMetadataGoogle/ModuleMetadataGoogle.apk
(verified with `aapt2 dump badging` that apk is prebuilt)
Change-Id: I625c48640c4bb1edf360605a1daac293a4a0a07a
diff --git a/core/android_soong_config_vars.mk b/core/android_soong_config_vars.mk
index 0befbfa..f61cfbf 100644
--- a/core/android_soong_config_vars.mk
+++ b/core/android_soong_config_vars.mk
@@ -36,17 +36,27 @@
$(call add_soong_config_var,ANDROID,BOARD_BUILD_SYSTEM_ROOT_IMAGE)
$(call add_soong_config_var,ANDROID,PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT)
-ifneq (,$(filter sdk win_sdk sdk_addon,$(MAKECMDGOALS)))
- # The artifacts in the SDK zip are OK to build with prebuilt stubs enabled,
- # even if prebuilt apexes are not enabled, because the system images in the
- # SDK stub are not currently used (and will be removed: b/205008975).
- MODULE_BUILD_FROM_SOURCE ?= false
-else ifeq (,$(findstring com.google.android.conscrypt,$(PRODUCT_PACKAGES)))
+# Default behavior for the tree wrt building modules or using prebuilts. This
+# can always be overridden by setting the environment variable
+# MODULE_BUILD_FROM_SOURCE.
+BRANCH_DEFAULT_MODULE_BUILD_FROM_SOURCE := true
+
+ifneq (,$(MODULE_BUILD_FROM_SOURCE))
+ # Keep an explicit setting.
+else ifeq (,$(filter sdk win_sdk sdk_addon,$(MAKECMDGOALS))$(findstring com.google.android.conscrypt,$(PRODUCT_PACKAGES)))
# Prebuilt module SDKs require prebuilt modules to work, and currently
# prebuilt modules are only provided for com.google.android.xxx. If we can't
# find one of them in PRODUCT_PACKAGES then assume com.android.xxx are in use,
# and disable prebuilt SDKs. In particular this applies to AOSP builds.
+ #
+ # However, sdk/win_sdk/sdk_addon builds might not include com.google.android.xxx
+ # packages, so for those we respect the default behavior.
MODULE_BUILD_FROM_SOURCE := true
+else ifeq (,$(filter-out modules_% mainline_modules_%,$(TARGET_PRODUCT)))
+ # Always build from source in unbundled builds using the module targets.
+ MODULE_BUILD_FROM_SOURCE := true
+else
+ MODULE_BUILD_FROM_SOURCE := $(BRANCH_DEFAULT_MODULE_BUILD_FROM_SOURCE)
endif
# TODO(b/172480615): Remove when platform uses ART Module prebuilts by default.