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    $@
32fi
33
34# Otherwise, we want to be at the root for simplifying the "out" detection
35# logic.
36if [ ! -d art ]; then
37  echo "Script needs to be run at the root of the android tree."
38  exit 1
39fi
40
41# Logic for setting out_dir from build/make/core/envsetup.mk:
42if [[ -z "${OUT_DIR}" ]]; then
43  if [[ -z "${OUT_DIR_COMMON_BASE}" ]]; then
44    OUT=out
45  else
46    OUT=${OUT_DIR_COMMON_BASE}/${PWD##*/}
47  fi
48else
49  OUT=${OUT_DIR}
50fi
51
52if [[ -z "${PACKAGING}" ]]; then
53  PACKAGING=${OUT}/target/common/obj/PACKAGING
54fi
55
56if [[ -z "${ANDROID_HOST_OUT}" ]]; then
57  ANDROID_HOST_OUT=${OUT}/host/linux-x86
58fi
59
60extra_flags=
61
62# If --api-flags is not passed directly, take it from the build.
63if [[ "$@" != "*--api-flags=*" ]]; then
64  file="${OUT}/soong/hiddenapi/hiddenapi-flags.csv"
65  if [ ! -f $file ]; then
66    echo "Missing API flags file $file"
67    exit 1
68  fi
69  extra_flags="--api-flags=$file"
70fi
71
72
73${ANDROID_HOST_OUT}/bin/veridex \
74    --core-stubs=${PACKAGING}/core_dex_intermediates/classes.dex:${PACKAGING}/oahl_dex_intermediates/classes.dex \
75    $extra_flags \
76    $@
77