1#!/bin/bash 2# Copyright (C) 2025 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# Use "ravehleper pta" to create a shell script which: 18# - Reads the text "policy" files 19# - Convert to java annotations (using sed) 20# 21 22set -e 23 24 25# Uncomment it to always build ravenhelper (slow) 26# ${BUILD_CMD:-m} ravenhelper 27 28# Get the target directory. Default to $ANDROID_BUILD_TOP. 29TARGET_DIR="${TARGET_DIR:-${ANDROID_BUILD_TOP?\$ANDROID_BUILD_TOP must be set}}" 30 31echo "Target dir=$TARGET_DIR" 32 33cd "$TARGET_DIR" 34 35# Add -v or -d as needed. 36extra_args="$@" 37 38OUT_SCRIPT="${OUT_SCRIPT:-/tmp/pta.sh}" 39 40rm -f "$OUT_SCRIPT" 41 42# If you want to run on other files, run this script with the following 43# env vars predefined. 44 45POLICIES="${POLICIES:- 46frameworks/base/ravenwood/texts/ravenwood-common-policies.txt 47frameworks/base/ravenwood/texts/ravenwood-framework-policies.txt 48}" 49 50SOURCES="${SOURCES:- 51frameworks/base/core/java/ 52frameworks/base/graphics/java/ 53}" 54 55AAC="${AAC:-frameworks/base/ravenwood/texts/ravenwood-annotation-allowed-classes.txt}" 56 57with_flag() { 58 local flag="$1" 59 shift 60 61 for arg in "$@"; do 62 echo "$flag $arg" 63 done 64} 65 66run() { 67 echo "Running: $*" 68 "$@" 69} 70 71run_pta() { 72 local extra_args="$@" 73 74 run ${RAVENHELPER_CMD:-ravenhelper pta} \ 75 --output-script $OUT_SCRIPT \ 76 --annotation-allowed-classes-file $AAC \ 77 $(with_flag --policy-override-file $POLICIES) \ 78 $(with_flag --src $SOURCES) \ 79 $extra_args 80 81 if ! [[ -f $OUT_SCRIPT ]] ; then 82 echo "No files need updating." 83 # no operations generated. 84 exit 0 85 fi 86 87 echo 88 echo "Created script at $OUT_SCRIPT. Run it with: sh $OUT_SCRIPT" 89 return 0 90} 91 92run_pta "$extra_args" 93