Delay platform availability error for ALLOW_MISSING_DEPENDENCIES=true
The platform availability check was erroring incorrectly for the
libstatssocket module in master-art-host builds. Nothing being
built depended on libstatssocket, but the check would still
error because libstatspull_test was defined in the branch but
unused in the build.
When ALLOW_MISSING_DEPENDENCIES=true is set and a module fails
the check add an additional dependency on a rule that prints
the error message. This will show the error and fail the build
if an unavailable module is requested to be installed, while
allowing the build to proceed if there are no unavailable
modules in the dependency graph.
Fixes: 154888298
Test: m build-art-host TARGET_BUILD_UNBUNDLED=true ALLOW_MISSING_DEPENDENCIES=true libstatspull_test -k
Test: m build-art-host TARGET_BUILD_UNBUNDLED=true ALLOW_MISSING_DEPENDENCIES=true
Change-Id: I1d57afe60a75d65128e59f794243a0414cbc82f6
diff --git a/core/tasks/platform_availability_check.mk b/core/tasks/platform_availability_check.mk
index 043d130..f252ff5 100644
--- a/core/tasks/platform_availability_check.mk
+++ b/core/tasks/platform_availability_check.mk
@@ -26,11 +26,31 @@
$(if $(filter true,$(ALL_MODULES.$(m).NOT_AVAILABLE_FOR_PLATFORM)),\
$(m))))))
-_violators_with_path := $(foreach m,$(sort $(_modules_not_available_for_platform)),\
+ifndef ALLOW_MISSING_DEPENDENCIES
+ _violators_with_path := $(foreach m,$(sort $(_modules_not_available_for_platform)),\
$(m):$(word 1,$(ALL_MODULES.$(m).PATH))\
-)
+ )
-$(call maybe-print-list-and-error,$(_violators_with_path),\
+ $(call maybe-print-list-and-error,$(_violators_with_path),\
Following modules are requested to be installed. But are not available \
for platform because they do not have "//apex_available:platform" or \
they depend on other modules that are not available for platform)
+
+else
+
+# Don't error out immediately when ALLOW_MISSING_DEPENDENCIES is set.
+# Instead, add a dependency on a rule that prints the error message.
+ define not_available_for_platform_rule
+ not_installable_file := $(patsubst $(OUT_DIR)/%,$(OUT_DIR)/NOT_AVAILABLE_FOR_PLATFORM/%,$(1)))
+ $(1): $$(not_installable_file)
+ $$(not_installable_file):
+ $(call echo-error,$(2),Module is requested to be installed but is not \
+available for platform because it does not have "//apex_available:platform" or \
+it depends on other modules that are not available for platform.)
+ exit 1
+ endef
+
+ $(foreach m,$(_modules_not_available_for_platform),\
+ $(foreach i,$(ALL_MODULES.$(m).INSTALLED),\
+ $(eval $(call not_available_for_platform_rule,$(i),$(m)))))
+endif