1#!/bin/bash
2#
3# Copyright (C) 2018 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
17echo "NOTE: appcompat.sh is still under development. It can report"
18echo "API uses that do not execute at runtime, and reflection uses"
19echo "that do not exist. It can also miss on reflection uses."
20
21# First check if the script is invoked from a prebuilts location.
22SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
23
24if [[ -e ${SCRIPT_DIR}/veridex && \
25      -e ${SCRIPT_DIR}/hiddenapi-flags.csv && \
26      -e ${SCRIPT_DIR}/org.apache.http.legacy-stubs.zip && \
27      -e ${SCRIPT_DIR}/system-stubs.zip ]]; then
28  exec ${SCRIPT_DIR}/veridex \
29    --core-stubs=${SCRIPT_DIR}/system-stubs.zip:${SCRIPT_DIR}/org.apache.http.legacy-stubs.zip \
30    --api-flags=${SCRIPT_DIR}/hiddenapi-flags.csv \
31    --exclude-api-lists=whitelist,invalid \
32    $@
33fi
34
35# Otherwise, we want to be at the root for simplifying the "out" detection
36# logic.
37if [ ! -d art ]; then
38  echo "Script needs to be run at the root of the android tree."
39  exit 1
40fi
41
42# Logic for setting out_dir from build/make/core/envsetup.mk:
43if [[ -z "${OUT_DIR}" ]]; then
44  if [[ -z "${OUT_DIR_COMMON_BASE}" ]]; then
45    OUT=out
46  else
47    OUT=${OUT_DIR_COMMON_BASE}/${PWD##*/}
48  fi
49else
50  OUT=${OUT_DIR}
51fi
52
53if [[ -z "${PACKAGING}" ]]; then
54  PACKAGING=${OUT}/target/common/obj/PACKAGING
55fi
56
57if [[ -z "${ANDROID_HOST_OUT}" ]]; then
58  ANDROID_HOST_OUT=${OUT}/host/linux-x86
59fi
60
61extra_flags=
62
63# If --api-flags is not passed directly, take it from the build.
64if [[ "$@" != "*--api-flags=*" ]]; then
65  file="${OUT}/soong/hiddenapi/hiddenapi-flags.csv"
66  if [ ! -f $file ]; then
67    echo "Missing API flags file $file"
68    exit 1
69  fi
70  extra_flags="--api-flags=$file"
71fi
72
73# If --exclude-api-lists is not passed directly, exclude whitelist APIs.
74if [[ "$@" != "*--exclude-api-lists=*" ]]; then
75  extra_flags="${extra_flags} --exclude-api-lists=whitelist,invalid"
76fi
77
78${ANDROID_HOST_OUT}/bin/veridex \
79    --core-stubs=${PACKAGING}/core_dex_intermediates/classes.dex:${PACKAGING}/oahl_dex_intermediates/classes.dex \
80    $extra_flags \
81    $@
82