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