xref: /aosp_15_r20/frameworks/base/tools/lint/utils/generate-exempt-aidl-interfaces.sh (revision d57664e9bc4670b3ecf6748a746a57c557b6bc9e)
1*d57664e9SAndroid Build Coastguard Worker#
2*d57664e9SAndroid Build Coastguard Worker# Copyright (C) 2024 The Android Open Source Project
3*d57664e9SAndroid Build Coastguard Worker#
4*d57664e9SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
5*d57664e9SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
6*d57664e9SAndroid Build Coastguard Worker# You may obtain a copy of the License at
7*d57664e9SAndroid Build Coastguard Worker#
8*d57664e9SAndroid Build Coastguard Worker#      http://www.apache.org/licenses/LICENSE-2.0
9*d57664e9SAndroid Build Coastguard Worker#
10*d57664e9SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
11*d57664e9SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
12*d57664e9SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*d57664e9SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
14*d57664e9SAndroid Build Coastguard Worker# limitations under the License.
15*d57664e9SAndroid Build Coastguard Worker#
16*d57664e9SAndroid Build Coastguard Worker
17*d57664e9SAndroid Build Coastguard Worker# Create a directory for the results and a nested temporary directory.
18*d57664e9SAndroid Build Coastguard Workermkdir -p $ANDROID_BUILD_TOP/out/soong/exempt_aidl_interfaces_generator_output/tmp
19*d57664e9SAndroid Build Coastguard Worker
20*d57664e9SAndroid Build Coastguard Worker# Create a copy of `AndroidGlobalLintChecker.jar` to restore it afterwards.
21*d57664e9SAndroid Build Coastguard Workercp $ANDROID_BUILD_TOP/prebuilts/cmdline-tools/AndroidGlobalLintChecker.jar \
22*d57664e9SAndroid Build Coastguard Worker    $ANDROID_BUILD_TOP/out/soong/exempt_aidl_interfaces_generator_output/AndroidGlobalLintChecker.jar
23*d57664e9SAndroid Build Coastguard Worker
24*d57664e9SAndroid Build Coastguard Worker# Configure the environment variable required for running the lint check on the entire source tree.
25*d57664e9SAndroid Build Coastguard Workerexport ANDROID_LINT_CHECK=PermissionAnnotationExemptAidlInterfaces
26*d57664e9SAndroid Build Coastguard Worker
27*d57664e9SAndroid Build Coastguard Worker# Build the target corresponding to the lint checks present in the `utils` directory.
28*d57664e9SAndroid Build Coastguard Workerm AndroidUtilsLintChecker
29*d57664e9SAndroid Build Coastguard Worker
30*d57664e9SAndroid Build Coastguard Worker# Replace `AndroidGlobalLintChecker.jar` with the newly built `jar` file.
31*d57664e9SAndroid Build Coastguard Workercp $ANDROID_BUILD_TOP/out/host/linux-x86/framework/AndroidUtilsLintChecker.jar \
32*d57664e9SAndroid Build Coastguard Worker    $ANDROID_BUILD_TOP/prebuilts/cmdline-tools/AndroidGlobalLintChecker.jar;
33*d57664e9SAndroid Build Coastguard Worker
34*d57664e9SAndroid Build Coastguard Worker# Run the lint check on the entire source tree.
35*d57664e9SAndroid Build Coastguard Workerm lint-check
36*d57664e9SAndroid Build Coastguard Worker
37*d57664e9SAndroid Build Coastguard Worker# Copy the archive containing the results of `lint-check` into the temporary directory.
38*d57664e9SAndroid Build Coastguard Workercp $ANDROID_BUILD_TOP/out/soong/lint-report-text.zip \
39*d57664e9SAndroid Build Coastguard Worker    $ANDROID_BUILD_TOP/out/soong/exempt_aidl_interfaces_generator_output/tmp
40*d57664e9SAndroid Build Coastguard Worker
41*d57664e9SAndroid Build Coastguard Workercd $ANDROID_BUILD_TOP/out/soong/exempt_aidl_interfaces_generator_output/tmp
42*d57664e9SAndroid Build Coastguard Worker
43*d57664e9SAndroid Build Coastguard Worker# Unzip the archive containing the results of `lint-check`.
44*d57664e9SAndroid Build Coastguard Workerunzip lint-report-text.zip
45*d57664e9SAndroid Build Coastguard Worker
46*d57664e9SAndroid Build Coastguard Worker# Concatenate the results of `lint-check` into a single string.
47*d57664e9SAndroid Build Coastguard Workerconcatenated_reports=$(find . -type f | xargs cat)
48*d57664e9SAndroid Build Coastguard Worker
49*d57664e9SAndroid Build Coastguard Worker# Extract the fully qualified names of the AIDL Interfaces from the concatenated results. Output
50*d57664e9SAndroid Build Coastguard Worker# this list into `out/soong/exempt_aidl_interfaces_generator_output/exempt_aidl_interfaces`.
51*d57664e9SAndroid Build Coastguard Workerecho $concatenated_reports | grep -Eo '\"([a-zA-Z0-9_]*\.)+[a-zA-Z0-9_]*\",' | sort | uniq > ../exempt_aidl_interfaces
52*d57664e9SAndroid Build Coastguard Worker
53*d57664e9SAndroid Build Coastguard Worker# Remove the temporary directory.
54*d57664e9SAndroid Build Coastguard Workerrm -rf $ANDROID_BUILD_TOP/out/soong/exempt_aidl_interfaces_generator_output/tmp
55*d57664e9SAndroid Build Coastguard Worker
56*d57664e9SAndroid Build Coastguard Worker# Restore the original copy of `AndroidGlobalLintChecker.jar` and delete the copy.
57*d57664e9SAndroid Build Coastguard Workercp $ANDROID_BUILD_TOP/out/soong/exempt_aidl_interfaces_generator_output/AndroidGlobalLintChecker.jar \
58*d57664e9SAndroid Build Coastguard Worker    $ANDROID_BUILD_TOP/prebuilts/cmdline-tools/AndroidGlobalLintChecker.jar
59*d57664e9SAndroid Build Coastguard Workerrm $ANDROID_BUILD_TOP/out/soong/exempt_aidl_interfaces_generator_output/AndroidGlobalLintChecker.jar
60