Anton Hansson | fae0f97 | 2020-12-08 21:12:13 +0000 | [diff] [blame] | 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. |
| 5 | static_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. |
Inseob Kim | d8cde77 | 2023-11-07 13:36:59 +0900 | [diff] [blame] | 7 | static_allowed_patterns += %__auto_generated_characteristics_rro.apk |
Anton Hansson | fae0f97 | 2020-12-08 21:12:13 +0000 | [diff] [blame] | 8 | static_allowed_patterns += %__auto_generated_rro_product.apk |
| 9 | static_allowed_patterns += %__auto_generated_rro_vendor.apk |
| 10 | # Auto-included targets are not considered |
| 11 | static_allowed_patterns += $(call product-installed-files,) |
| 12 | # $(PRODUCT_OUT)/apex is where shared libraries in APEXes get installed. |
| 13 | # The path can be considered as a fake path, as the shared libraries |
| 14 | # are installed there just to have symbols files for them under |
| 15 | # $(PRODUCT_OUT)/symbols/apex for debugging purpose. The /apex directory |
| 16 | # is never compiled into a filesystem image. |
| 17 | static_allowed_patterns += $(PRODUCT_OUT)/apex/% |
| 18 | ifeq (true,$(BOARD_USES_SYSTEM_OTHER_ODEX)) |
| 19 | # Allow system_other odex space optimization. |
| 20 | static_allowed_patterns += \ |
| 21 | $(TARGET_OUT_SYSTEM_OTHER)/%.odex \ |
| 22 | $(TARGET_OUT_SYSTEM_OTHER)/%.vdex \ |
| 23 | $(TARGET_OUT_SYSTEM_OTHER)/%.art |
| 24 | endif |
| 25 | |
Cole Faust | 5d46c61 | 2022-04-12 13:23:04 -0700 | [diff] [blame] | 26 | ifneq (,$(filter-out true false relaxed strict,$(PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS))$(filter-out 1 0,$(words $(PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS)))) |
| 27 | $(error PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS must be one of [true, false, relaxed, strict], found: $(PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS)) |
| 28 | endif |
| 29 | |
Anton Hansson | fae0f97 | 2020-12-08 21:12:13 +0000 | [diff] [blame] | 30 | all_offending_files := |
| 31 | $(foreach makefile,$(ARTIFACT_PATH_REQUIREMENT_PRODUCTS),\ |
| 32 | $(eval requirements := $(PRODUCTS.$(makefile).ARTIFACT_PATH_REQUIREMENTS)) \ |
| 33 | $(eval ### Verify that the product only produces files inside its path requirements.) \ |
| 34 | $(eval allowed := $(PRODUCTS.$(makefile).ARTIFACT_PATH_ALLOWED_LIST)) \ |
| 35 | $(eval path_patterns := $(call resolve-product-relative-paths,$(requirements),%)) \ |
| 36 | $(eval allowed_patterns := $(call resolve-product-relative-paths,$(allowed))) \ |
| 37 | $(eval files := $(call product-installed-files, $(makefile))) \ |
| 38 | $(eval offending_files := $(filter-out $(path_patterns) $(allowed_patterns) $(static_allowed_patterns),$(files))) \ |
| 39 | $(call maybe-print-list-and-error,$(offending_files),\ |
| 40 | $(makefile) produces files outside its artifact path requirement. \ |
| 41 | Allowed paths are $(subst $(space),$(comma)$(space),$(addsuffix *,$(requirements)))) \ |
| 42 | $(eval unused_allowed := $(filter-out $(files),$(allowed_patterns))) \ |
Anton Hansson | d1258eb | 2020-12-08 12:13:50 +0000 | [diff] [blame] | 43 | $(if $(PRODUCTS.$(makefile).ARTIFACT_PATH_REQUIREMENT_IS_RELAXED),, \ |
| 44 | $(call maybe-print-list-and-error,$(unused_allowed),$(makefile) includes redundant allowed entries in its artifact path requirement.) \ |
| 45 | ) \ |
Anton Hansson | fae0f97 | 2020-12-08 21:12:13 +0000 | [diff] [blame] | 46 | $(eval ### Optionally verify that nothing else produces files inside this artifact path requirement.) \ |
| 47 | $(eval extra_files := $(filter-out $(files) $(HOST_OUT)/%,$(product_target_FILES))) \ |
| 48 | $(eval files_in_requirement := $(filter $(path_patterns),$(extra_files))) \ |
| 49 | $(eval all_offending_files += $(files_in_requirement)) \ |
| 50 | $(eval allowed := $(PRODUCT_ARTIFACT_PATH_REQUIREMENT_ALLOWED_LIST)) \ |
| 51 | $(eval allowed_patterns := $(call resolve-product-relative-paths,$(allowed))) \ |
| 52 | $(eval offending_files := $(filter-out $(allowed_patterns),$(files_in_requirement))) \ |
| 53 | $(eval enforcement := $(PRODUCT_ENFORCE_ARTIFACT_PATH_REQUIREMENTS)) \ |
Cole Faust | 5d46c61 | 2022-04-12 13:23:04 -0700 | [diff] [blame] | 54 | $(if $(filter-out false,$(enforcement)),\ |
Anton Hansson | fae0f97 | 2020-12-08 21:12:13 +0000 | [diff] [blame] | 55 | $(call maybe-print-list-and-error,$(offending_files),\ |
| 56 | $(INTERNAL_PRODUCT) produces files inside $(makefile)s artifact path requirement. \ |
| 57 | $(PRODUCT_ARTIFACT_PATH_REQUIREMENT_HINT)) \ |
| 58 | $(eval unused_allowed := $(if $(filter true strict,$(enforcement)),\ |
| 59 | $(foreach p,$(allowed_patterns),$(if $(filter $(p),$(extra_files)),,$(p))))) \ |
| 60 | $(call maybe-print-list-and-error,$(unused_allowed),$(INTERNAL_PRODUCT) includes redundant artifact path requirement allowed list entries.) \ |
| 61 | ) \ |
| 62 | ) |
| 63 | $(PRODUCT_OUT)/offending_artifacts.txt: |
| 64 | rm -f $@ |
| 65 | $(foreach f,$(sort $(all_offending_files)),echo $(f) >> $@;) |