• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# This file contains logic to enforce artifact path requirements
2# defined in product makefiles.
3
4# Fakes don't get installed, and NDK stubs aren't installed to device.
5static_allowed_patterns := $(TARGET_OUT_FAKE)/% $(SOONG_OUT_DIR)/ndk/%
6# RROs become REQUIRED by the source module, but are always placed on the vendor partition.
7static_allowed_patterns += %__auto_generated_rro_product.apk
8static_allowed_patterns += %__auto_generated_rro_vendor.apk
9# Auto-included targets are not considered
10static_allowed_patterns += $(call product-installed-files,)
11# $(PRODUCT_OUT)/apex is where shared libraries in APEXes get installed.
12# The path can be considered as a fake path, as the shared libraries
13# are installed there just to have symbols files for them under
14# $(PRODUCT_OUT)/symbols/apex for debugging purpose. The /apex directory
15# is never compiled into a filesystem image.
16static_allowed_patterns += $(PRODUCT_OUT)/apex/%
17ifeq (true,$(BOARD_USES_SYSTEM_OTHER_ODEX))
18  # Allow system_other odex space optimization.
19  static_allowed_patterns += \
20    $(TARGET_OUT_SYSTEM_OTHER)/%.odex \
21    $(TARGET_OUT_SYSTEM_OTHER)/%.vdex \
22    $(TARGET_OUT_SYSTEM_OTHER)/%.art
23endif
24
25ifneq (,$(filter-out true false relaxed strict,$(PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS))$(filter-out 1 0,$(words $(PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS))))
26  $(error PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS must be one of [true, false, relaxed, strict], found: $(PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS))
27endif
28
29all_offending_files :=
30$(foreach makefile,$(ARTIFACT_PATH_REQUIREMENT_PRODUCTS),\
31  $(eval requirements := $(PRODUCTS.$(makefile).ARTIFACT_PATH_REQUIREMENTS)) \
32  $(eval ### Verify that the product only produces files inside its path requirements.) \
33  $(eval allowed := $(PRODUCTS.$(makefile).ARTIFACT_PATH_ALLOWED_LIST)) \
34  $(eval path_patterns := $(call resolve-product-relative-paths,$(requirements),%)) \
35  $(eval allowed_patterns := $(call resolve-product-relative-paths,$(allowed))) \
36  $(eval files := $(call product-installed-files, $(makefile))) \
37  $(eval offending_files := $(filter-out $(path_patterns) $(allowed_patterns) $(static_allowed_patterns),$(files))) \
38  $(call maybe-print-list-and-error,$(offending_files),\
39    $(makefile) produces files outside its artifact path requirement. \
40    Allowed paths are $(subst $(space),$(comma)$(space),$(addsuffix *,$(requirements)))) \
41  $(eval unused_allowed := $(filter-out $(files),$(allowed_patterns))) \
42  $(if $(PRODUCTS.$(makefile).ARTIFACT_PATH_REQUIREMENT_IS_RELAXED),, \
43    $(call maybe-print-list-and-error,$(unused_allowed),$(makefile) includes redundant allowed entries in its artifact path requirement.) \
44  ) \
45  $(eval ### Optionally verify that nothing else produces files inside this artifact path requirement.) \
46  $(eval extra_files := $(filter-out $(files) $(HOST_OUT)/%,$(product_target_FILES))) \
47  $(eval files_in_requirement := $(filter $(path_patterns),$(extra_files))) \
48  $(eval all_offending_files += $(files_in_requirement)) \
49  $(eval allowed := $(PRODUCT_ARTIFACT_PATH_REQUIREMENT_ALLOWED_LIST)) \
50  $(eval allowed_patterns := $(call resolve-product-relative-paths,$(allowed))) \
51  $(eval offending_files := $(filter-out $(allowed_patterns),$(files_in_requirement))) \
52  $(eval enforcement := $(PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS)) \
53  $(if $(filter-out false,$(enforcement)),\
54    $(call maybe-print-list-and-error,$(offending_files),\
55      $(INTERNAL_PRODUCT) produces files inside $(makefile)s artifact path requirement. \
56      $(PRODUCT_ARTIFACT_PATH_REQUIREMENT_HINT)) \
57    $(eval unused_allowed := $(if $(filter true strict,$(enforcement)),\
58      $(foreach p,$(allowed_patterns),$(if $(filter $(p),$(extra_files)),,$(p))))) \
59    $(call maybe-print-list-and-error,$(unused_allowed),$(INTERNAL_PRODUCT) includes redundant artifact path requirement allowed list entries.) \
60  ) \
61)
62$(PRODUCT_OUT)/offending_artifacts.txt:
63	rm -f $@
64	$(foreach f,$(sort $(all_offending_files)),echo $(f) >> $@;)
65