1# Copyright (C) 2024 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15##################################################################### 16# Check the generate list against the latest list stored in the 17# source tree 18.PHONY: check-abi-dump-list 19 20# Check if vndk list is changed 21droidcore: check-abi-dump-list 22 23check-abi-dump-list-timestamp := $(call intermediates-dir-for,PACKAGING,vndk)/check-abi-dump-list-timestamp 24 25# The ABI tool does not support sanitizer and coverage builds. 26ifeq (,$(filter true,$(SKIP_ABI_CHECKS) $(CLANG_COVERAGE))) 27ifeq (,$(SANITIZE_TARGET)) 28check-abi-dump-list: $(check-abi-dump-list-timestamp) 29endif 30endif 31 32##################################################################### 33# ABI reference dumps. 34 35# LSDUMP_PATHS is a list of tag:path. They are written to LSDUMP_PATHS_FILE. 36LSDUMP_PATHS_FILE := $(PRODUCT_OUT)/lsdump_paths.txt 37 38$(LSDUMP_PATHS_FILE): PRIVATE_LSDUMP_PATHS := $(LSDUMP_PATHS) 39$(LSDUMP_PATHS_FILE): 40 @echo "Generate $@" 41 @rm -rf $@ && echo -e "$(subst :,:$(space),$(subst $(space),\n,$(PRIVATE_LSDUMP_PATHS)))" > $@ 42 43# $(1): A list of tags. 44# $(2): A list of tag:path. 45# Return the file paths of the ABI dumps that match the tags. 46define filter-abi-dump-paths 47$(eval tag_patterns := $(addsuffix :%,$(1))) 48$(patsubst $(tag_patterns),%,$(filter $(tag_patterns),$(2))) 49endef 50 51# Subsets of LSDUMP_PATHS. 52.PHONY: findlsdumps_APEX 53findlsdumps_APEX: $(LSDUMP_PATHS_FILE) $(call filter-abi-dump-paths,APEX,$(LSDUMP_PATHS)) 54 55.PHONY: findlsdumps_LLNDK 56findlsdumps_LLNDK: $(LSDUMP_PATHS_FILE) $(call filter-abi-dump-paths,LLNDK,$(LSDUMP_PATHS)) 57 58.PHONY: findlsdumps_NDK 59findlsdumps_NDK: $(LSDUMP_PATHS_FILE) $(call filter-abi-dump-paths,NDK,$(LSDUMP_PATHS)) 60 61.PHONY: findlsdumps_PLATFORM 62findlsdumps_PLATFORM: $(LSDUMP_PATHS_FILE) $(call filter-abi-dump-paths,PLATFORM,$(LSDUMP_PATHS)) 63 64.PHONY: findlsdumps 65findlsdumps: $(LSDUMP_PATHS_FILE) $(foreach p,$(LSDUMP_PATHS),$(call word-colon,2,$(p))) 66 67##################################################################### 68# Check that all ABI reference dumps have corresponding 69# APEX/LLNDK/PLATFORM libraries. 70 71# $(1): The directory containing ABI dumps. 72# Return a list of ABI dump paths ending with .so.lsdump. 73define find-abi-dump-paths 74$(if $(wildcard $(1)), \ 75 $(addprefix $(1)/, \ 76 $(call find-files-in-subdirs,$(1),"*.so.lsdump" -and -type f,.))) 77endef 78 79# $(1): A list of tags. 80# $(2): A list of tag:path. 81# Return the file names of the ABI dumps that match the tags, and replace the 82# file name extensions with .so.lsdump. 83define filter-abi-dump-names 84$(patsubst %.so.llndk.lsdump,%.so.lsdump, \ 85 $(patsubst %.so.apex.lsdump,%.so.lsdump, \ 86 $(notdir $(call filter-abi-dump-paths,$(1),$(2))))) 87endef 88 89VNDK_ABI_DUMP_DIR := prebuilts/abi-dumps/vndk/$(RELEASE_BOARD_API_LEVEL) 90ifeq (REL,$(PLATFORM_VERSION_CODENAME)) 91 PLATFORM_ABI_DUMP_DIR := prebuilts/abi-dumps/platform/$(PLATFORM_SDK_VERSION) 92else 93 PLATFORM_ABI_DUMP_DIR := prebuilts/abi-dumps/platform/current 94endif 95VNDK_ABI_DUMPS := $(call find-abi-dump-paths,$(VNDK_ABI_DUMP_DIR)) 96PLATFORM_ABI_DUMPS := $(call find-abi-dump-paths,$(PLATFORM_ABI_DUMP_DIR)) 97 98# Check for superfluous lsdump files. Since LSDUMP_PATHS only covers the 99# libraries that can be built from source in the current build, and prebuilts of 100# Mainline modules may be in use, we also allow the libs in STUB_LIBRARIES for 101# platform ABIs. 102# In addition, libRS is allowed because it's disabled for RISC-V. 103 104$(check-abi-dump-list-timestamp): PRIVATE_LSDUMP_PATHS := $(LSDUMP_PATHS) 105$(check-abi-dump-list-timestamp): PRIVATE_STUB_LIBRARIES := $(STUB_LIBRARIES) 106$(check-abi-dump-list-timestamp): 107 $(eval added_vndk_abi_dumps := $(strip $(sort $(filter-out \ 108 $(call filter-abi-dump-names,LLNDK,$(PRIVATE_LSDUMP_PATHS)) libRS.so.lsdump, \ 109 $(notdir $(VNDK_ABI_DUMPS)))))) 110 $(if $(added_vndk_abi_dumps), \ 111 echo -e "Found unexpected ABI reference dump files under $(VNDK_ABI_DUMP_DIR). It is caused by mismatch between Android.bp and the dump files. Run \`find \$${ANDROID_BUILD_TOP}/$(VNDK_ABI_DUMP_DIR) '(' -name $(subst $(space), -or -name ,$(added_vndk_abi_dumps)) ')' -delete\` to delete the dump files.") 112 113 # TODO(b/314010764): Remove LLNDK tag after PLATFORM_SDK_VERSION is upgraded to 35. 114 $(eval added_platform_abi_dumps := $(strip $(sort $(filter-out \ 115 $(call filter-abi-dump-names,APEX LLNDK PLATFORM,$(PRIVATE_LSDUMP_PATHS)) \ 116 $(addsuffix .lsdump,$(PRIVATE_STUB_LIBRARIES)) libRS.so.lsdump, \ 117 $(notdir $(PLATFORM_ABI_DUMPS)))))) 118 $(if $(added_platform_abi_dumps), \ 119 echo -e "Found unexpected ABI reference dump files under $(PLATFORM_ABI_DUMP_DIR). It is caused by mismatch between Android.bp and the dump files. Run \`find \$${ANDROID_BUILD_TOP}/$(PLATFORM_ABI_DUMP_DIR) '(' -name $(subst $(space), -or -name ,$(added_platform_abi_dumps)) ')' -delete\` to delete the dump files.") 120 121 $(if $(added_vndk_abi_dumps)$(added_platform_abi_dumps),exit 1) 122 $(hide) mkdir -p $(dir $@) 123 $(hide) touch $@ 124