Add a new macro for products to make artifact path requirements.
When a product adds a path requirement, the build system will verify
that all its artifacts are produced inside these paths, and fail
otherwise.
The paths are all relative to PRODUCT_OUT, and the macro also supports
giving a whitelist, for known existing offenders in the hierarchy. The
build will fail if redundant whitelist entries are present.
Example invocation:
_paths := $(TARGET_COPY_OUT_SYSTEM)/
_whitelist := root/init root/init.rc
$(call require-artifacts-in-path $(_paths), $(_whitelist))
Bug: 80410283
Test: Downstream with a new product definition.
Change-Id: I235de681f65254087a42e345af69b2113b682072
diff --git a/core/product.mk b/core/product.mk
index f9174cc..3cf521a 100644
--- a/core/product.mk
+++ b/core/product.mk
@@ -234,6 +234,16 @@
$(eval PARENT_PRODUCT_FILES := $(sort $(PARENT_PRODUCT_FILES) $(current_mk)))
endef
+# Specifies a number of path prefixes, relative to PRODUCT_OUT, where the
+# product makefile hierarchy rooted in the current node places its artifacts.
+# Creating artifacts outside the specified paths will cause a build-time error.
+define require-artifacts-in-path
+ $(eval current_mk := $(strip $(word 1,$(_include_stack)))) \
+ $(eval PRODUCTS.$(current_mk).ARTIFACT_PATH_REQUIREMENTS := $(strip $(1))) \
+ $(eval PRODUCTS.$(current_mk).ARTIFACT_PATH_WHITELIST := $(strip $(2))) \
+ $(eval ARTIFACT_PATH_REQUIREMENT_PRODUCTS := \
+ $(sort $(ARTIFACT_PATH_REQUIREMENT_PRODUCTS) $(current_mk)))
+endef
#
# Do inherit-product only if $(1) exists