1#!/bin/bash 2 3# Copyright (C) 2024 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17# Run check-flagged-apis for public APIs and the three @SystemApi flavours. 18# 19# This script expects an argument to tell it which subcommand of 20# check-flagged-apis to execute. Run the script without any arguments to see 21# the valid options. 22# 23# Remember to lunch to select the relevant release config before running this script. 24 25source $(cd $(dirname $BASH_SOURCE) &> /dev/null && pwd)/../../shell_utils.sh 26require_top 27 28PUBLIC_XML_VERSIONS=out/target/common/obj/PACKAGING/api_versions_public_generated-api-versions.xml 29SYSTEM_XML_VERSIONS=out/target/common/obj/PACKAGING/api_versions_system_generated-api-versions.xml 30SYSTEM_SERVER_XML_VERSONS=out/target/common/obj/PACKAGING/api_versions_system_server_complete_generated-api-versions.xml 31MODULE_LIB_XML_VERSIONS=out/target/common/obj/PACKAGING/api_versions_module_lib_complete_generated-api-versions.xml 32 33function m() { 34 $(gettop)/build/soong/soong_ui.bash --build-mode --all-modules --dir="$(pwd)" "$@" 35} 36 37function build() { 38 m \ 39 check-flagged-apis \ 40 all_aconfig_declarations \ 41 frameworks-base-api-current.txt \ 42 frameworks-base-api-system-current.txt \ 43 frameworks-base-api-system-server-current.txt \ 44 frameworks-base-api-module-lib-current.txt \ 45 $PUBLIC_XML_VERSIONS \ 46 $SYSTEM_XML_VERSIONS \ 47 $SYSTEM_SERVER_XML_VERSONS \ 48 $MODULE_LIB_XML_VERSIONS 49} 50 51function noop() { 52 true 53} 54 55function aninja() { 56 local T="$(gettop)" 57 (\cd "${T}" && prebuilts/build-tools/linux-x86/bin/ninja -f out/combined-${TARGET_PRODUCT}.ninja "$@") 58} 59 60function path_to_api_signature_file { 61 aninja -t query device_"$1"_all_targets | grep -A1 -e input: | tail -n1 62} 63 64function run_check() { 65 local errors=0 66 67 echo "# current" 68 check-flagged-apis check \ 69 --api-signature $(path_to_api_signature_file "frameworks-base-api-current.txt") \ 70 --flag-values $(gettop)/out/soong/.intermediates/all_aconfig_declarations.pb \ 71 --api-versions $PUBLIC_XML_VERSIONS 72 (( errors += $? )) 73 74 echo 75 echo "# system-current" 76 check-flagged-apis check \ 77 --api-signature $(path_to_api_signature_file "frameworks-base-api-system-current.txt") \ 78 --flag-values $(gettop)/out/soong/.intermediates/all_aconfig_declarations.pb \ 79 --api-versions $SYSTEM_XML_VERSIONS 80 (( errors += $? )) 81 82 echo 83 echo "# system-server-current" 84 check-flagged-apis check \ 85 --api-signature $(path_to_api_signature_file "frameworks-base-api-system-server-current.txt") \ 86 --flag-values $(gettop)/out/soong/.intermediates/all_aconfig_declarations.pb \ 87 --api-versions $SYSTEM_SERVER_XML_VERSONS 88 (( errors += $? )) 89 90 echo 91 echo "# module-lib" 92 check-flagged-apis check \ 93 --api-signature $(path_to_api_signature_file "frameworks-base-api-module-lib-current.txt") \ 94 --flag-values $(gettop)/out/soong/.intermediates/all_aconfig_declarations.pb \ 95 --api-versions $MODULE_LIB_XML_VERSIONS 96 (( errors += $? )) 97 98 return $errors 99} 100 101function run_list() { 102 echo "# current" 103 check-flagged-apis list \ 104 --api-signature $(path_to_api_signature_file "frameworks-base-api-current.txt") \ 105 --flag-values $(gettop)/out/soong/.intermediates/all_aconfig_declarations.pb 106 107 echo 108 echo "# system-current" 109 check-flagged-apis list \ 110 --api-signature $(path_to_api_signature_file "frameworks-base-api-system-current.txt") \ 111 --flag-values $(gettop)/out/soong/.intermediates/all_aconfig_declarations.pb 112 113 echo 114 echo "# system-server-current" 115 check-flagged-apis list \ 116 --api-signature $(path_to_api_signature_file "frameworks-base-api-system-server-current.txt") \ 117 --flag-values $(gettop)/out/soong/.intermediates/all_aconfig_declarations.pb 118 119 echo 120 echo "# module-lib" 121 check-flagged-apis list \ 122 --api-signature $(path_to_api_signature_file "frameworks-base-api-module-lib-current.txt") \ 123 --flag-values $(gettop)/out/soong/.intermediates/all_aconfig_declarations.pb 124} 125 126build_cmd=build 127if [[ "$1" == "--skip-build" ]]; then 128 build_cmd=noop 129 shift 1 130fi 131 132case "$1" in 133 check) $build_cmd && run_check ;; 134 list) $build_cmd && run_list ;; 135 *) echo "usage: $(basename $0): [--skip-build] check|list"; exit 1 136esac 137