2012-03-08 02:15:06 +01:00
|
|
|
function hmm() {
|
2008-10-21 16:00:00 +02:00
|
|
|
cat <<EOF
|
2008-12-18 03:03:49 +01:00
|
|
|
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
|
2012-08-22 19:25:20 +02:00
|
|
|
- lunch: lunch <product_name>-<build_variant>
|
2014-05-30 02:57:40 +02:00
|
|
|
- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user]
|
2008-10-21 16:00:00 +02:00
|
|
|
- croot: Changes directory to the top of the tree.
|
|
|
|
- m: Makes from the top of the tree.
|
2013-02-09 03:01:04 +01:00
|
|
|
- mm: Builds all of the modules in the current directory, but not their dependencies.
|
|
|
|
- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
|
2014-02-26 12:09:19 +01:00
|
|
|
To limit the modules being built use the syntax: mmm dir/:target1,target2.
|
2013-02-09 03:01:04 +01:00
|
|
|
- mma: Builds all of the modules in the current directory, and their dependencies.
|
|
|
|
- mmma: Builds all of the modules in the supplied directories, and their dependencies.
|
2008-10-21 16:00:00 +02:00
|
|
|
- cgrep: Greps on all local C/C++ files.
|
2014-04-07 19:57:38 +02:00
|
|
|
- ggrep: Greps on all local Gradle files.
|
2008-10-21 16:00:00 +02:00
|
|
|
- jgrep: Greps on all local Java files.
|
|
|
|
- resgrep: Greps on all local res/*.xml files.
|
2014-07-27 00:15:41 +02:00
|
|
|
- sgrep: Greps on all local source files.
|
2009-03-04 04:28:42 +01:00
|
|
|
- godir: Go to the directory containing a file.
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2014-11-01 00:23:08 +01:00
|
|
|
Environemnt options:
|
|
|
|
- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
|
|
|
|
ASAN_OPTIONS=detect_leaks=0 will be set by default until the
|
|
|
|
build is leak-check clean.
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
Look at the source to view more functions. The complete list is:
|
|
|
|
EOF
|
|
|
|
T=$(gettop)
|
|
|
|
local A
|
|
|
|
A=""
|
2014-07-27 00:15:41 +02:00
|
|
|
for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
|
2008-10-21 16:00:00 +02:00
|
|
|
A="$A $i"
|
|
|
|
done
|
|
|
|
echo $A
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get the value of a build variable as an absolute path.
|
|
|
|
function get_abs_build_var()
|
|
|
|
{
|
|
|
|
T=$(gettop)
|
|
|
|
if [ ! "$T" ]; then
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP." >&2
|
|
|
|
return
|
|
|
|
fi
|
2012-12-13 19:52:07 +01:00
|
|
|
(\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
|
2014-06-27 22:32:39 +02:00
|
|
|
command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Get the exact value of a build variable.
|
|
|
|
function get_build_var()
|
|
|
|
{
|
|
|
|
T=$(gettop)
|
|
|
|
if [ ! "$T" ]; then
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP." >&2
|
|
|
|
return
|
|
|
|
fi
|
2013-12-19 22:21:46 +01:00
|
|
|
(\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
|
2014-06-27 22:32:39 +02:00
|
|
|
command make --no-print-directory -f build/core/config.mk dumpvar-$1)
|
2008-12-18 03:03:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# check to see if the supplied product is one we can build
|
|
|
|
function check_product()
|
|
|
|
{
|
|
|
|
T=$(gettop)
|
|
|
|
if [ ! "$T" ]; then
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP." >&2
|
|
|
|
return
|
|
|
|
fi
|
2011-07-12 07:11:46 +02:00
|
|
|
TARGET_PRODUCT=$1 \
|
|
|
|
TARGET_BUILD_VARIANT= \
|
|
|
|
TARGET_BUILD_TYPE= \
|
2010-06-10 03:18:31 +02:00
|
|
|
TARGET_BUILD_APPS= \
|
2008-12-18 03:03:49 +01:00
|
|
|
get_build_var TARGET_DEVICE > /dev/null
|
|
|
|
# hide successful answers, but allow the errors to show
|
|
|
|
}
|
|
|
|
|
|
|
|
VARIANT_CHOICES=(user userdebug eng)
|
|
|
|
|
|
|
|
# check to see if the supplied variant is valid
|
|
|
|
function check_variant()
|
|
|
|
{
|
|
|
|
for v in ${VARIANT_CHOICES[@]}
|
|
|
|
do
|
|
|
|
if [ "$v" = "$1" ]
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 1
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function setpaths()
|
|
|
|
{
|
|
|
|
T=$(gettop)
|
|
|
|
if [ ! "$T" ]; then
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
##################################################################
|
|
|
|
# #
|
|
|
|
# Read me before you modify this code #
|
|
|
|
# #
|
|
|
|
# This function sets ANDROID_BUILD_PATHS to what it is adding #
|
|
|
|
# to PATH, and the next time it is run, it removes that from #
|
|
|
|
# PATH. This is required so lunch can be run more than once #
|
|
|
|
# and still have working paths. #
|
|
|
|
# #
|
|
|
|
##################################################################
|
|
|
|
|
2011-06-21 02:25:01 +02:00
|
|
|
# Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
|
|
|
|
# due to "C:\Program Files" being in the path.
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
# out with the old
|
2011-06-21 02:25:01 +02:00
|
|
|
if [ -n "$ANDROID_BUILD_PATHS" ] ; then
|
2008-10-21 16:00:00 +02:00
|
|
|
export PATH=${PATH/$ANDROID_BUILD_PATHS/}
|
|
|
|
fi
|
2011-06-21 02:25:01 +02:00
|
|
|
if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
|
2011-04-22 17:16:56 +02:00
|
|
|
export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
|
2012-11-27 05:51:59 +01:00
|
|
|
# strip leading ':', if any
|
|
|
|
export PATH=${PATH/:%/}
|
2010-06-22 01:26:38 +02:00
|
|
|
fi
|
2008-10-21 16:00:00 +02:00
|
|
|
|
|
|
|
# and in with the new
|
|
|
|
prebuiltdir=$(getprebuilt)
|
2012-03-30 05:45:50 +02:00
|
|
|
gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
|
2011-06-22 23:35:32 +02:00
|
|
|
|
2012-11-16 22:29:13 +01:00
|
|
|
# defined in core/config.mk
|
|
|
|
targetgccversion=$(get_build_var TARGET_GCC_VERSION)
|
2014-05-22 20:57:43 +02:00
|
|
|
targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
|
2012-12-11 01:04:39 +01:00
|
|
|
export TARGET_GCC_VERSION=$targetgccversion
|
2012-11-16 22:29:13 +01:00
|
|
|
|
2011-06-21 02:25:01 +02:00
|
|
|
# The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
|
2014-02-25 19:27:07 +01:00
|
|
|
export ANDROID_TOOLCHAIN=
|
|
|
|
export ANDROID_TOOLCHAIN_2ND_ARCH=
|
2012-04-17 14:50:47 +02:00
|
|
|
local ARCH=$(get_build_var TARGET_ARCH)
|
|
|
|
case $ARCH in
|
2013-08-23 14:49:21 +02:00
|
|
|
x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
|
2012-03-14 22:20:30 +01:00
|
|
|
;;
|
2012-11-26 06:50:07 +01:00
|
|
|
x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
|
|
|
|
;;
|
2012-11-16 22:29:13 +01:00
|
|
|
arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
|
2012-04-17 14:50:47 +02:00
|
|
|
;;
|
2014-02-25 19:27:07 +01:00
|
|
|
arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
|
2014-05-22 20:57:43 +02:00
|
|
|
toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
|
2013-10-05 01:02:59 +02:00
|
|
|
;;
|
2014-07-22 23:34:00 +02:00
|
|
|
mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
|
2014-01-14 11:33:53 +01:00
|
|
|
;;
|
2012-04-17 14:50:47 +02:00
|
|
|
*)
|
|
|
|
echo "Can't find toolchain for unknown architecture: $ARCH"
|
|
|
|
toolchaindir=xxxxxxxxx
|
2012-03-14 22:20:30 +01:00
|
|
|
;;
|
|
|
|
esac
|
2012-03-30 05:45:50 +02:00
|
|
|
if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
|
2014-02-25 19:27:07 +01:00
|
|
|
export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
|
2011-06-21 02:25:01 +02:00
|
|
|
fi
|
2011-06-22 23:35:32 +02:00
|
|
|
|
2014-02-25 19:27:07 +01:00
|
|
|
if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
|
|
|
|
export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
|
|
|
|
fi
|
|
|
|
|
|
|
|
unset ANDROID_KERNEL_TOOLCHAIN_PATH
|
2012-04-18 03:10:11 +02:00
|
|
|
case $ARCH in
|
2012-07-18 06:40:01 +02:00
|
|
|
arm)
|
2014-02-25 19:27:07 +01:00
|
|
|
# Legacy toolchain configuration used for ARM kernel compilation
|
2012-11-16 22:29:13 +01:00
|
|
|
toolchaindir=arm/arm-eabi-$targetgccversion/bin
|
2012-07-18 06:40:01 +02:00
|
|
|
if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
|
2014-04-25 17:24:22 +02:00
|
|
|
export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
|
|
|
|
ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
|
2012-07-18 06:40:01 +02:00
|
|
|
fi
|
2012-04-18 03:10:11 +02:00
|
|
|
;;
|
|
|
|
*)
|
2012-07-18 06:40:01 +02:00
|
|
|
# No need to set ARM_EABI_TOOLCHAIN for other ARCHs
|
2012-04-18 03:10:11 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2013-03-30 01:40:14 +01:00
|
|
|
export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
|
2014-06-30 19:25:33 +02:00
|
|
|
export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_KERNEL_TOOLCHAIN_PATH$ANDROID_DEV_SCRIPTS:
|
2014-05-05 16:13:50 +02:00
|
|
|
|
|
|
|
# If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
|
|
|
|
# to ensure that the corresponding 'emulator' binaries are used.
|
|
|
|
case $(uname -s) in
|
|
|
|
Darwin)
|
|
|
|
ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
|
|
|
|
;;
|
|
|
|
Linux)
|
|
|
|
ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
ANDROID_EMULATOR_PREBUILTS=
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
|
2014-05-20 22:56:00 +02:00
|
|
|
ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
|
2014-05-05 16:13:50 +02:00
|
|
|
export ANDROID_EMULATOR_PREBUILTS
|
|
|
|
fi
|
|
|
|
|
2012-11-27 05:51:59 +01:00
|
|
|
export PATH=$ANDROID_BUILD_PATHS$PATH
|
2008-12-18 03:03:49 +01:00
|
|
|
|
2010-06-22 01:26:38 +02:00
|
|
|
unset ANDROID_JAVA_TOOLCHAIN
|
2011-07-04 07:09:47 +02:00
|
|
|
unset ANDROID_PRE_BUILD_PATHS
|
2010-06-22 01:26:38 +02:00
|
|
|
if [ -n "$JAVA_HOME" ]; then
|
|
|
|
export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
|
2011-07-04 07:09:47 +02:00
|
|
|
export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
|
|
|
|
export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
|
2010-06-22 01:26:38 +02:00
|
|
|
fi
|
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
unset ANDROID_PRODUCT_OUT
|
2008-10-21 16:00:00 +02:00
|
|
|
export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
|
|
|
|
export OUT=$ANDROID_PRODUCT_OUT
|
|
|
|
|
2011-03-25 01:03:06 +01:00
|
|
|
unset ANDROID_HOST_OUT
|
|
|
|
export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
|
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
# needed for building linux on MacOS
|
2008-10-21 16:00:00 +02:00
|
|
|
# TODO: fix the path
|
|
|
|
#export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
|
|
|
|
}
|
|
|
|
|
|
|
|
function printconfig()
|
|
|
|
{
|
2008-12-18 03:03:49 +01:00
|
|
|
T=$(gettop)
|
|
|
|
if [ ! "$T" ]; then
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP." >&2
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
get_build_var report_config
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function set_stuff_for_environment()
|
|
|
|
{
|
2008-12-18 03:03:49 +01:00
|
|
|
settitle
|
2010-06-22 01:26:38 +02:00
|
|
|
set_java_home
|
2008-12-18 03:03:49 +01:00
|
|
|
setpaths
|
|
|
|
set_sequence_number
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
export ANDROID_BUILD_TOP=$(gettop)
|
2013-08-13 23:38:15 +02:00
|
|
|
# With this environment variable new GCC can apply colors to warnings/errors
|
|
|
|
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
|
2014-11-01 00:23:08 +01:00
|
|
|
export ASAN_OPTIONS=detect_leaks=0
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function set_sequence_number()
|
|
|
|
{
|
2010-06-23 23:03:13 +02:00
|
|
|
export BUILD_ENV_SEQUENCE_NUMBER=10
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function settitle()
|
|
|
|
{
|
2008-12-18 03:03:49 +01:00
|
|
|
if [ "$STAY_OFF_MY_LAWN" = "" ]; then
|
2012-07-26 04:57:22 +02:00
|
|
|
local arch=$(gettargetarch)
|
2010-06-10 03:18:31 +02:00
|
|
|
local product=$TARGET_PRODUCT
|
|
|
|
local variant=$TARGET_BUILD_VARIANT
|
|
|
|
local apps=$TARGET_BUILD_APPS
|
|
|
|
if [ -z "$apps" ]; then
|
2012-07-26 04:57:22 +02:00
|
|
|
export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
|
2010-06-10 03:18:31 +02:00
|
|
|
else
|
2012-07-26 04:57:22 +02:00
|
|
|
export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
|
2010-06-10 03:18:31 +02:00
|
|
|
fi
|
2008-12-18 03:03:49 +01:00
|
|
|
fi
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
2011-07-15 20:07:06 +02:00
|
|
|
function addcompletions()
|
|
|
|
{
|
|
|
|
local T dir f
|
|
|
|
|
|
|
|
# Keep us from trying to run in something that isn't bash.
|
|
|
|
if [ -z "${BASH_VERSION}" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Keep us from trying to run in bash that's too old.
|
|
|
|
if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
dir="sdk/bash_completion"
|
|
|
|
if [ -d ${dir} ]; then
|
2011-07-18 22:11:34 +02:00
|
|
|
for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
|
2011-07-15 20:07:06 +02:00
|
|
|
echo "including $f"
|
|
|
|
. $f
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
function choosetype()
|
|
|
|
{
|
|
|
|
echo "Build type choices are:"
|
|
|
|
echo " 1. release"
|
|
|
|
echo " 2. debug"
|
|
|
|
echo
|
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
local DEFAULT_NUM DEFAULT_VALUE
|
2011-07-12 07:11:46 +02:00
|
|
|
DEFAULT_NUM=1
|
|
|
|
DEFAULT_VALUE=release
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
export TARGET_BUILD_TYPE=
|
|
|
|
local ANSWER
|
2008-10-21 16:00:00 +02:00
|
|
|
while [ -z $TARGET_BUILD_TYPE ]
|
|
|
|
do
|
|
|
|
echo -n "Which would you like? ["$DEFAULT_NUM"] "
|
2008-12-18 03:03:49 +01:00
|
|
|
if [ -z "$1" ] ; then
|
|
|
|
read ANSWER
|
|
|
|
else
|
|
|
|
echo $1
|
|
|
|
ANSWER=$1
|
|
|
|
fi
|
2008-10-21 16:00:00 +02:00
|
|
|
case $ANSWER in
|
|
|
|
"")
|
|
|
|
export TARGET_BUILD_TYPE=$DEFAULT_VALUE
|
|
|
|
;;
|
|
|
|
1)
|
|
|
|
export TARGET_BUILD_TYPE=release
|
|
|
|
;;
|
2008-12-18 03:03:49 +01:00
|
|
|
release)
|
|
|
|
export TARGET_BUILD_TYPE=release
|
|
|
|
;;
|
2008-10-21 16:00:00 +02:00
|
|
|
2)
|
|
|
|
export TARGET_BUILD_TYPE=debug
|
|
|
|
;;
|
2008-12-18 03:03:49 +01:00
|
|
|
debug)
|
|
|
|
export TARGET_BUILD_TYPE=debug
|
|
|
|
;;
|
2008-10-21 16:00:00 +02:00
|
|
|
*)
|
|
|
|
echo
|
|
|
|
echo "I didn't understand your response. Please try again."
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
esac
|
2008-12-18 03:03:49 +01:00
|
|
|
if [ -n "$1" ] ; then
|
|
|
|
break
|
|
|
|
fi
|
2008-10-21 16:00:00 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
set_stuff_for_environment
|
|
|
|
}
|
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
#
|
|
|
|
# This function isn't really right: It chooses a TARGET_PRODUCT
|
|
|
|
# based on the list of boards. Usually, that gets you something
|
|
|
|
# that kinda works with a generic product, but really, you should
|
|
|
|
# pick a product by name.
|
|
|
|
#
|
2008-10-21 16:00:00 +02:00
|
|
|
function chooseproduct()
|
|
|
|
{
|
|
|
|
if [ "x$TARGET_PRODUCT" != x ] ; then
|
|
|
|
default_value=$TARGET_PRODUCT
|
|
|
|
else
|
2011-07-12 07:11:46 +02:00
|
|
|
default_value=full
|
2008-10-21 16:00:00 +02:00
|
|
|
fi
|
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
export TARGET_PRODUCT=
|
|
|
|
local ANSWER
|
2008-10-21 16:00:00 +02:00
|
|
|
while [ -z "$TARGET_PRODUCT" ]
|
|
|
|
do
|
2009-04-30 00:56:47 +02:00
|
|
|
echo -n "Which product would you like? [$default_value] "
|
2008-12-18 03:03:49 +01:00
|
|
|
if [ -z "$1" ] ; then
|
|
|
|
read ANSWER
|
|
|
|
else
|
|
|
|
echo $1
|
|
|
|
ANSWER=$1
|
|
|
|
fi
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ -z "$ANSWER" ] ; then
|
|
|
|
export TARGET_PRODUCT=$default_value
|
2008-12-18 03:03:49 +01:00
|
|
|
else
|
|
|
|
if check_product $ANSWER
|
|
|
|
then
|
|
|
|
export TARGET_PRODUCT=$ANSWER
|
|
|
|
else
|
|
|
|
echo "** Not a valid product: $ANSWER"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ -n "$1" ] ; then
|
|
|
|
break
|
2008-10-21 16:00:00 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
set_stuff_for_environment
|
|
|
|
}
|
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
function choosevariant()
|
|
|
|
{
|
|
|
|
echo "Variant choices are:"
|
|
|
|
local index=1
|
|
|
|
local v
|
|
|
|
for v in ${VARIANT_CHOICES[@]}
|
|
|
|
do
|
|
|
|
# The product name is the name of the directory containing
|
|
|
|
# the makefile we found, above.
|
|
|
|
echo " $index. $v"
|
|
|
|
index=$(($index+1))
|
|
|
|
done
|
|
|
|
|
|
|
|
local default_value=eng
|
|
|
|
local ANSWER
|
|
|
|
|
|
|
|
export TARGET_BUILD_VARIANT=
|
|
|
|
while [ -z "$TARGET_BUILD_VARIANT" ]
|
|
|
|
do
|
|
|
|
echo -n "Which would you like? [$default_value] "
|
|
|
|
if [ -z "$1" ] ; then
|
|
|
|
read ANSWER
|
|
|
|
else
|
|
|
|
echo $1
|
|
|
|
ANSWER=$1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$ANSWER" ] ; then
|
|
|
|
export TARGET_BUILD_VARIANT=$default_value
|
|
|
|
elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
|
|
|
|
if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
|
2010-07-05 09:53:47 +02:00
|
|
|
export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
|
2008-12-18 03:03:49 +01:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
if check_variant $ANSWER
|
|
|
|
then
|
|
|
|
export TARGET_BUILD_VARIANT=$ANSWER
|
|
|
|
else
|
|
|
|
echo "** Not a valid variant: $ANSWER"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ -n "$1" ] ; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
function choosecombo()
|
|
|
|
{
|
2011-07-12 07:11:46 +02:00
|
|
|
choosetype $1
|
2008-10-21 16:00:00 +02:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo
|
2011-07-12 07:11:46 +02:00
|
|
|
chooseproduct $2
|
2008-10-21 16:00:00 +02:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo
|
2011-07-12 07:11:46 +02:00
|
|
|
choosevariant $3
|
2008-12-18 03:03:49 +01:00
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
echo
|
|
|
|
set_stuff_for_environment
|
2008-12-18 03:03:49 +01:00
|
|
|
printconfig
|
|
|
|
}
|
|
|
|
|
|
|
|
# Clear this variable. It will be built up again when the vendorsetup.sh
|
|
|
|
# files are included at the end of this file.
|
|
|
|
unset LUNCH_MENU_CHOICES
|
|
|
|
function add_lunch_combo()
|
|
|
|
{
|
|
|
|
local new_combo=$1
|
|
|
|
local c
|
|
|
|
for c in ${LUNCH_MENU_CHOICES[@]} ; do
|
|
|
|
if [ "$new_combo" = "$c" ] ; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
# add the default one here
|
2013-03-22 23:53:54 +01:00
|
|
|
add_lunch_combo aosp_arm-eng
|
2014-01-14 11:33:53 +01:00
|
|
|
add_lunch_combo aosp_arm64-eng
|
2013-03-22 23:53:54 +01:00
|
|
|
add_lunch_combo aosp_mips-eng
|
2014-02-04 00:01:24 +01:00
|
|
|
add_lunch_combo aosp_mips64-eng
|
2014-01-14 11:33:53 +01:00
|
|
|
add_lunch_combo aosp_x86-eng
|
2012-11-26 06:50:07 +01:00
|
|
|
add_lunch_combo aosp_x86_64-eng
|
2008-12-18 03:03:49 +01:00
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
function print_lunch_menu()
|
|
|
|
{
|
|
|
|
local uname=$(uname)
|
|
|
|
echo
|
|
|
|
echo "You're building on" $uname
|
|
|
|
echo
|
|
|
|
echo "Lunch menu... pick a combo:"
|
2008-12-18 03:03:49 +01:00
|
|
|
|
|
|
|
local i=1
|
|
|
|
local choice
|
|
|
|
for choice in ${LUNCH_MENU_CHOICES[@]}
|
|
|
|
do
|
|
|
|
echo " $i. $choice"
|
|
|
|
i=$(($i+1))
|
|
|
|
done
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
function lunch()
|
|
|
|
{
|
2008-12-18 03:03:49 +01:00
|
|
|
local answer
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ "$1" ] ; then
|
2008-12-18 03:03:49 +01:00
|
|
|
answer=$1
|
2008-10-21 16:00:00 +02:00
|
|
|
else
|
|
|
|
print_lunch_menu
|
2013-03-22 23:53:54 +01:00
|
|
|
echo -n "Which would you like? [aosp_arm-eng] "
|
2008-12-18 03:03:49 +01:00
|
|
|
read answer
|
2008-10-21 16:00:00 +02:00
|
|
|
fi
|
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
local selection=
|
|
|
|
|
|
|
|
if [ -z "$answer" ]
|
|
|
|
then
|
2013-03-22 23:53:54 +01:00
|
|
|
selection=aosp_arm-eng
|
2008-12-18 03:03:49 +01:00
|
|
|
elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
|
|
|
|
then
|
|
|
|
if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
|
|
|
|
then
|
2010-07-05 09:53:47 +02:00
|
|
|
selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
|
2008-12-18 03:03:49 +01:00
|
|
|
fi
|
|
|
|
elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
|
2008-10-21 16:00:00 +02:00
|
|
|
then
|
2008-12-18 03:03:49 +01:00
|
|
|
selection=$answer
|
2008-10-21 16:00:00 +02:00
|
|
|
fi
|
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
if [ -z "$selection" ]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
echo "Invalid lunch combo: $answer"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2010-06-10 03:18:31 +02:00
|
|
|
export TARGET_BUILD_APPS=
|
|
|
|
|
2011-07-12 07:11:46 +02:00
|
|
|
local product=$(echo -n $selection | sed -e "s/-.*$//")
|
|
|
|
check_product $product
|
|
|
|
if [ $? -ne 0 ]
|
2008-12-18 03:03:49 +01:00
|
|
|
then
|
2011-07-12 07:11:46 +02:00
|
|
|
echo
|
|
|
|
echo "** Don't have a product spec for: '$product'"
|
|
|
|
echo "** Do you have the right repo manifest?"
|
|
|
|
product=
|
|
|
|
fi
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2011-07-12 07:11:46 +02:00
|
|
|
local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
|
|
|
|
check_variant $variant
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
echo "** Invalid variant: '$variant'"
|
|
|
|
echo "** Must be one of ${VARIANT_CHOICES[@]}"
|
|
|
|
variant=
|
|
|
|
fi
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2011-07-12 07:11:46 +02:00
|
|
|
if [ -z "$product" -o -z "$variant" ]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
return 1
|
|
|
|
fi
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2011-07-12 07:11:46 +02:00
|
|
|
export TARGET_PRODUCT=$product
|
|
|
|
export TARGET_BUILD_VARIANT=$variant
|
|
|
|
export TARGET_BUILD_TYPE=release
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
echo
|
|
|
|
|
|
|
|
set_stuff_for_environment
|
|
|
|
printconfig
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
2010-08-02 19:00:44 +02:00
|
|
|
# Tab completion for lunch.
|
|
|
|
function _lunch()
|
|
|
|
{
|
|
|
|
local cur prev opts
|
|
|
|
COMPREPLY=()
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
|
|
|
|
COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
complete -F _lunch lunch
|
|
|
|
|
2010-06-10 03:18:31 +02:00
|
|
|
# Configures the build to build unbundled apps.
|
2014-04-16 20:34:34 +02:00
|
|
|
# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
|
2010-06-10 03:18:31 +02:00
|
|
|
function tapas()
|
|
|
|
{
|
2014-05-30 02:57:40 +02:00
|
|
|
local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
|
2014-04-16 20:34:34 +02:00
|
|
|
local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
|
2014-09-05 06:28:00 +02:00
|
|
|
local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
|
|
|
|
local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5|arm64|x86_64|mips64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
|
2010-06-10 03:18:31 +02:00
|
|
|
|
2012-08-22 19:25:20 +02:00
|
|
|
if [ $(echo $arch | wc -w) -gt 1 ]; then
|
|
|
|
echo "tapas: Error: Multiple build archs supplied: $arch"
|
|
|
|
return
|
|
|
|
fi
|
2010-06-10 03:18:31 +02:00
|
|
|
if [ $(echo $variant | wc -w) -gt 1 ]; then
|
|
|
|
echo "tapas: Error: Multiple build variants supplied: $variant"
|
|
|
|
return
|
|
|
|
fi
|
2014-09-05 06:28:00 +02:00
|
|
|
if [ $(echo $density | wc -w) -gt 1 ]; then
|
|
|
|
echo "tapas: Error: Multiple densities supplied: $density"
|
|
|
|
return
|
|
|
|
fi
|
2012-08-22 19:25:20 +02:00
|
|
|
|
|
|
|
local product=full
|
|
|
|
case $arch in
|
2014-05-30 02:57:40 +02:00
|
|
|
x86) product=full_x86;;
|
|
|
|
mips) product=full_mips;;
|
|
|
|
armv5) product=generic_armv5;;
|
|
|
|
arm64) product=aosp_arm64;;
|
|
|
|
x86_64) product=aosp_x86_64;;
|
|
|
|
mips64) product=aosp_mips64;;
|
2012-08-22 19:25:20 +02:00
|
|
|
esac
|
2010-06-10 03:18:31 +02:00
|
|
|
if [ -z "$variant" ]; then
|
|
|
|
variant=eng
|
|
|
|
fi
|
2010-06-25 00:08:33 +02:00
|
|
|
if [ -z "$apps" ]; then
|
|
|
|
apps=all
|
|
|
|
fi
|
2014-11-04 20:35:51 +01:00
|
|
|
if [ -z "$density" ]; then
|
|
|
|
density=alldpi
|
|
|
|
fi
|
2010-06-10 03:18:31 +02:00
|
|
|
|
2012-08-22 19:25:20 +02:00
|
|
|
export TARGET_PRODUCT=$product
|
2010-06-10 03:18:31 +02:00
|
|
|
export TARGET_BUILD_VARIANT=$variant
|
2014-09-05 06:28:00 +02:00
|
|
|
export TARGET_BUILD_DENSITY=$density
|
2010-06-10 03:18:31 +02:00
|
|
|
export TARGET_BUILD_TYPE=release
|
|
|
|
export TARGET_BUILD_APPS=$apps
|
|
|
|
|
|
|
|
set_stuff_for_environment
|
|
|
|
printconfig
|
|
|
|
}
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
function gettop
|
|
|
|
{
|
2008-12-18 03:03:49 +01:00
|
|
|
local TOPFILE=build/core/envsetup.mk
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
|
2014-09-12 09:33:25 +02:00
|
|
|
# The following circumlocution ensures we remove symlinks from TOP.
|
|
|
|
(cd $TOP; PWD= /bin/pwd)
|
2008-10-21 16:00:00 +02:00
|
|
|
else
|
|
|
|
if [ -f $TOPFILE ] ; then
|
2009-11-25 00:48:50 +01:00
|
|
|
# The following circumlocution (repeated below as well) ensures
|
|
|
|
# that we record the true directory name and not one that is
|
|
|
|
# faked up with symlink names.
|
|
|
|
PWD= /bin/pwd
|
2008-10-21 16:00:00 +02:00
|
|
|
else
|
2008-12-18 03:03:49 +01:00
|
|
|
local HERE=$PWD
|
2008-10-21 16:00:00 +02:00
|
|
|
T=
|
|
|
|
while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
|
2012-12-13 19:52:07 +01:00
|
|
|
\cd ..
|
2013-07-06 04:47:47 +02:00
|
|
|
T=`PWD= /bin/pwd -P`
|
2008-10-21 16:00:00 +02:00
|
|
|
done
|
2012-12-13 19:52:07 +01:00
|
|
|
\cd $HERE
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ -f "$T/$TOPFILE" ]; then
|
|
|
|
echo $T
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-09-10 11:37:14 +02:00
|
|
|
# Return driver for "make", if any (eg. static analyzer)
|
|
|
|
function getdriver()
|
|
|
|
{
|
|
|
|
local T="$1"
|
|
|
|
test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
|
|
|
|
if [ -n "$WITH_STATIC_ANALYZER" ]; then
|
|
|
|
echo "\
|
2014-03-03 09:53:17 +01:00
|
|
|
$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
|
|
|
|
--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
|
2013-09-10 11:37:14 +02:00
|
|
|
--status-bugs \
|
|
|
|
--top=$T"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
function m()
|
|
|
|
{
|
2013-09-10 11:37:14 +02:00
|
|
|
local T=$(gettop)
|
|
|
|
local DRV=$(getdriver $T)
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ "$T" ]; then
|
2013-09-10 11:37:14 +02:00
|
|
|
$DRV make -C $T -f build/core/main.mk $@
|
2008-10-21 16:00:00 +02:00
|
|
|
else
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function findmakefile()
|
|
|
|
{
|
|
|
|
TOPFILE=build/core/envsetup.mk
|
2008-12-18 03:03:49 +01:00
|
|
|
local HERE=$PWD
|
2008-10-21 16:00:00 +02:00
|
|
|
T=
|
|
|
|
while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
|
2012-10-12 00:05:07 +02:00
|
|
|
T=`PWD= /bin/pwd`
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ -f "$T/Android.mk" ]; then
|
|
|
|
echo $T/Android.mk
|
2012-12-13 19:52:07 +01:00
|
|
|
\cd $HERE
|
2008-10-21 16:00:00 +02:00
|
|
|
return
|
|
|
|
fi
|
2012-12-13 19:52:07 +01:00
|
|
|
\cd ..
|
2008-10-21 16:00:00 +02:00
|
|
|
done
|
2012-12-13 19:52:07 +01:00
|
|
|
\cd $HERE
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function mm()
|
|
|
|
{
|
2013-09-10 11:37:14 +02:00
|
|
|
local T=$(gettop)
|
|
|
|
local DRV=$(getdriver $T)
|
2008-10-21 16:00:00 +02:00
|
|
|
# If we're sitting in the root of the build tree, just do a
|
|
|
|
# normal make.
|
|
|
|
if [ -f build/core/envsetup.mk -a -f Makefile ]; then
|
2013-09-10 11:37:14 +02:00
|
|
|
$DRV make $@
|
2008-10-21 16:00:00 +02:00
|
|
|
else
|
|
|
|
# Find the closest Android.mk file.
|
2008-12-18 03:03:49 +01:00
|
|
|
local M=$(findmakefile)
|
2013-08-16 22:24:47 +02:00
|
|
|
local MODULES=
|
|
|
|
local GET_INSTALL_PATH=
|
|
|
|
local ARGS=
|
2009-07-16 00:07:44 +02:00
|
|
|
# Remove the path to top as the makefilepath needs to be relative
|
|
|
|
local M=`echo $M|sed 's:'$T'/::'`
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ ! "$T" ]; then
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP."
|
|
|
|
elif [ ! "$M" ]; then
|
|
|
|
echo "Couldn't locate a makefile from the current directory."
|
|
|
|
else
|
2013-08-16 22:24:47 +02:00
|
|
|
for ARG in $@; do
|
|
|
|
case $ARG in
|
|
|
|
GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
if [ -n "$GET_INSTALL_PATH" ]; then
|
|
|
|
MODULES=
|
|
|
|
ARGS=GET-INSTALL-PATH
|
|
|
|
else
|
|
|
|
MODULES=all_modules
|
|
|
|
ARGS=$@
|
|
|
|
fi
|
2013-09-11 03:07:23 +02:00
|
|
|
ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES $ARGS
|
2008-10-21 16:00:00 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function mmm()
|
|
|
|
{
|
2013-09-10 11:37:14 +02:00
|
|
|
local T=$(gettop)
|
|
|
|
local DRV=$(getdriver $T)
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ "$T" ]; then
|
2008-12-18 03:03:49 +01:00
|
|
|
local MAKEFILE=
|
2011-11-30 21:40:19 +01:00
|
|
|
local MODULES=
|
2008-12-18 03:03:49 +01:00
|
|
|
local ARGS=
|
|
|
|
local DIR TO_CHOP
|
2013-08-16 22:24:47 +02:00
|
|
|
local GET_INSTALL_PATH=
|
2009-03-04 04:28:42 +01:00
|
|
|
local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
|
|
|
|
local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
|
|
|
|
for DIR in $DIRS ; do
|
2011-11-30 21:40:19 +01:00
|
|
|
MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
|
|
|
|
if [ "$MODULES" = "" ]; then
|
|
|
|
MODULES=all_modules
|
|
|
|
fi
|
|
|
|
DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ -f $DIR/Android.mk ]; then
|
2013-08-16 22:24:47 +02:00
|
|
|
local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
|
|
|
|
local TO_CHOP=`expr $TO_CHOP + 1`
|
|
|
|
local START=`PWD= /bin/pwd`
|
|
|
|
local MFILE=`echo $START | cut -c${TO_CHOP}-`
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ "$MFILE" = "" ] ; then
|
|
|
|
MFILE=$DIR/Android.mk
|
|
|
|
else
|
|
|
|
MFILE=$MFILE/$DIR/Android.mk
|
|
|
|
fi
|
|
|
|
MAKEFILE="$MAKEFILE $MFILE"
|
|
|
|
else
|
2013-08-16 22:24:47 +02:00
|
|
|
case $DIR in
|
|
|
|
showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
|
|
|
|
GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
|
|
|
|
*) echo "No Android.mk in $DIR."; return 1;;
|
|
|
|
esac
|
2008-10-21 16:00:00 +02:00
|
|
|
fi
|
|
|
|
done
|
2013-08-16 22:24:47 +02:00
|
|
|
if [ -n "$GET_INSTALL_PATH" ]; then
|
|
|
|
ARGS=$GET_INSTALL_PATH
|
|
|
|
MODULES=
|
|
|
|
fi
|
2013-09-10 11:37:14 +02:00
|
|
|
ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
|
2008-10-21 16:00:00 +02:00
|
|
|
else
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-02-09 03:01:04 +01:00
|
|
|
function mma()
|
|
|
|
{
|
2013-09-10 11:37:14 +02:00
|
|
|
local T=$(gettop)
|
|
|
|
local DRV=$(getdriver $T)
|
2013-02-09 03:01:04 +01:00
|
|
|
if [ -f build/core/envsetup.mk -a -f Makefile ]; then
|
2013-09-10 11:37:14 +02:00
|
|
|
$DRV make $@
|
2013-02-09 03:01:04 +01:00
|
|
|
else
|
|
|
|
if [ ! "$T" ]; then
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP."
|
|
|
|
fi
|
|
|
|
local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
|
2013-09-10 11:37:14 +02:00
|
|
|
$DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
|
2013-02-09 03:01:04 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function mmma()
|
|
|
|
{
|
2013-09-10 11:37:14 +02:00
|
|
|
local T=$(gettop)
|
|
|
|
local DRV=$(getdriver $T)
|
2013-02-09 03:01:04 +01:00
|
|
|
if [ "$T" ]; then
|
|
|
|
local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
|
|
|
|
local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
|
|
|
|
local MY_PWD=`PWD= /bin/pwd`
|
|
|
|
if [ "$MY_PWD" = "$T" ]; then
|
|
|
|
MY_PWD=
|
|
|
|
else
|
|
|
|
MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
|
|
|
|
fi
|
|
|
|
local DIR=
|
|
|
|
local MODULE_PATHS=
|
|
|
|
local ARGS=
|
|
|
|
for DIR in $DIRS ; do
|
|
|
|
if [ -d $DIR ]; then
|
|
|
|
if [ "$MY_PWD" = "" ]; then
|
|
|
|
MODULE_PATHS="$MODULE_PATHS $DIR"
|
|
|
|
else
|
|
|
|
MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
case $DIR in
|
|
|
|
showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
|
|
|
|
*) echo "Couldn't find directory $DIR"; return 1;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
done
|
2013-09-10 11:37:14 +02:00
|
|
|
$DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS"
|
2013-02-09 03:01:04 +01:00
|
|
|
else
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
function croot()
|
|
|
|
{
|
|
|
|
T=$(gettop)
|
|
|
|
if [ "$T" ]; then
|
2012-12-13 19:52:07 +01:00
|
|
|
\cd $(gettop)
|
2008-10-21 16:00:00 +02:00
|
|
|
else
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2009-07-30 19:23:21 +02:00
|
|
|
function cproj()
|
|
|
|
{
|
|
|
|
TOPFILE=build/core/envsetup.mk
|
|
|
|
local HERE=$PWD
|
|
|
|
T=
|
|
|
|
while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
|
|
|
|
T=$PWD
|
|
|
|
if [ -f "$T/Android.mk" ]; then
|
2012-12-13 19:52:07 +01:00
|
|
|
\cd $T
|
2009-07-30 19:23:21 +02:00
|
|
|
return
|
|
|
|
fi
|
2012-12-13 19:52:07 +01:00
|
|
|
\cd ..
|
2009-07-30 19:23:21 +02:00
|
|
|
done
|
2012-12-13 19:52:07 +01:00
|
|
|
\cd $HERE
|
2009-07-30 19:23:21 +02:00
|
|
|
echo "can't find Android.mk"
|
|
|
|
}
|
|
|
|
|
2013-07-30 19:23:52 +02:00
|
|
|
# simplified version of ps; output in the form
|
|
|
|
# <pid> <procname>
|
|
|
|
function qpid() {
|
|
|
|
local prepend=''
|
|
|
|
local append=''
|
|
|
|
if [ "$1" = "--exact" ]; then
|
|
|
|
prepend=' '
|
|
|
|
append='$'
|
|
|
|
shift
|
|
|
|
elif [ "$1" = "--help" -o "$1" = "-h" ]; then
|
|
|
|
echo "usage: qpid [[--exact] <process name|pid>"
|
|
|
|
return 255
|
|
|
|
fi
|
|
|
|
|
|
|
|
local EXE="$1"
|
|
|
|
if [ "$EXE" ] ; then
|
2013-08-27 23:15:50 +02:00
|
|
|
qpid | \grep "$prepend$EXE$append"
|
2013-07-30 19:23:52 +02:00
|
|
|
else
|
|
|
|
adb shell ps \
|
|
|
|
| tr -d '\r' \
|
|
|
|
| sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
function pid()
|
|
|
|
{
|
2013-07-30 19:23:52 +02:00
|
|
|
local prepend=''
|
|
|
|
local append=''
|
|
|
|
if [ "$1" = "--exact" ]; then
|
|
|
|
prepend=' '
|
|
|
|
append='$'
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
local EXE="$1"
|
|
|
|
if [ "$EXE" ] ; then
|
|
|
|
local PID=`adb shell ps \
|
|
|
|
| tr -d '\r' \
|
2013-08-27 23:15:50 +02:00
|
|
|
| \grep "$prepend$EXE$append" \
|
2013-07-30 19:23:52 +02:00
|
|
|
| sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
|
|
|
|
echo "$PID"
|
|
|
|
else
|
|
|
|
echo "usage: pid [--exact] <process name>"
|
|
|
|
return 255
|
|
|
|
fi
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
2014-11-04 02:04:47 +01:00
|
|
|
# coredump_setup - enable core dumps globally for any process
|
2014-10-29 02:00:42 +01:00
|
|
|
# that has the core-file-size limit set correctly
|
|
|
|
#
|
2014-11-05 05:57:37 +01:00
|
|
|
# NOTE: You must call also coredump_enable for a specific process
|
2014-10-29 02:00:42 +01:00
|
|
|
# if its core-file-size limit is not set already.
|
|
|
|
# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
|
|
|
|
|
2014-11-04 02:04:47 +01:00
|
|
|
function coredump_setup()
|
2014-10-29 02:00:42 +01:00
|
|
|
{
|
|
|
|
echo "Getting root...";
|
|
|
|
adb root;
|
|
|
|
adb wait-for-device;
|
|
|
|
|
|
|
|
echo "Remounting root parition read-write...";
|
|
|
|
adb shell mount -w -o remount -t rootfs rootfs;
|
|
|
|
sleep 1;
|
|
|
|
adb wait-for-device;
|
|
|
|
adb shell mkdir -p /cores;
|
2014-11-04 20:17:20 +01:00
|
|
|
adb shell mount -t tmpfs tmpfs /cores;
|
2014-10-29 02:00:42 +01:00
|
|
|
adb shell chmod 0777 /cores;
|
|
|
|
|
|
|
|
echo "Granting SELinux permission to dump in /cores...";
|
|
|
|
adb shell restorecon -R /cores;
|
|
|
|
|
|
|
|
echo "Set core pattern.";
|
|
|
|
adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
|
|
|
|
|
|
|
|
echo "Done."
|
|
|
|
}
|
|
|
|
|
2014-11-05 05:57:37 +01:00
|
|
|
# coredump_enable - enable core dumps for the specified process
|
2014-10-29 02:00:42 +01:00
|
|
|
# $1 = PID of process (e.g., $(pid mediaserver))
|
|
|
|
#
|
2014-11-05 05:57:37 +01:00
|
|
|
# NOTE: coredump_setup must have been called as well for a core
|
2014-10-29 02:00:42 +01:00
|
|
|
# dump to actually be generated.
|
|
|
|
|
2014-11-05 05:57:37 +01:00
|
|
|
function coredump_enable()
|
2014-10-29 02:00:42 +01:00
|
|
|
{
|
|
|
|
local PID=$1;
|
|
|
|
if [ -z "$PID" ]; then
|
|
|
|
printf "Expecting a PID!\n";
|
|
|
|
return;
|
|
|
|
fi;
|
|
|
|
echo "Setting core limit for $PID to infinite...";
|
|
|
|
adb shell prlimit $PID 4 -1 -1
|
|
|
|
}
|
|
|
|
|
|
|
|
# core - send SIGV and pull the core for process
|
|
|
|
# $1 = PID of process (e.g., $(pid mediaserver))
|
|
|
|
#
|
2014-11-05 05:57:37 +01:00
|
|
|
# NOTE: coredump_setup must be called once per boot for core dumps to be
|
2014-10-29 02:00:42 +01:00
|
|
|
# enabled globally.
|
|
|
|
|
|
|
|
function core()
|
|
|
|
{
|
|
|
|
local PID=$1;
|
|
|
|
|
|
|
|
if [ -z "$PID" ]; then
|
|
|
|
printf "Expecting a PID!\n";
|
|
|
|
return;
|
|
|
|
fi;
|
|
|
|
|
|
|
|
local CORENAME=core.$PID;
|
|
|
|
local COREPATH=/cores/$CORENAME;
|
|
|
|
local SIG=SEGV;
|
|
|
|
|
2014-11-05 05:57:37 +01:00
|
|
|
coredump_enable $1;
|
2014-10-29 02:00:42 +01:00
|
|
|
|
|
|
|
local done=0;
|
|
|
|
while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
|
|
|
|
printf "\tSending SIG%s to %d...\n" $SIG $PID;
|
|
|
|
adb shell kill -$SIG $PID;
|
|
|
|
sleep 1;
|
|
|
|
done;
|
|
|
|
|
|
|
|
adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
|
|
|
|
echo "Done: core is under $COREPATH on device.";
|
|
|
|
}
|
|
|
|
|
2009-11-13 00:33:08 +01:00
|
|
|
# systemstack - dump the current stack trace of all threads in the system process
|
|
|
|
# to the usual ANR traces file
|
|
|
|
function systemstack()
|
|
|
|
{
|
2013-02-20 02:00:46 +01:00
|
|
|
stacks system_server
|
|
|
|
}
|
|
|
|
|
|
|
|
function stacks()
|
|
|
|
{
|
|
|
|
if [[ $1 =~ ^[0-9]+$ ]] ; then
|
|
|
|
local PID="$1"
|
|
|
|
elif [ "$1" ] ; then
|
2013-08-20 00:14:16 +02:00
|
|
|
local PIDLIST="$(pid $1)"
|
|
|
|
if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
|
|
|
|
local PID="$PIDLIST"
|
|
|
|
elif [ "$PIDLIST" ] ; then
|
|
|
|
echo "more than one process: $1"
|
|
|
|
else
|
|
|
|
echo "no such process: $1"
|
|
|
|
fi
|
2013-02-20 02:00:46 +01:00
|
|
|
else
|
|
|
|
echo "usage: stacks [pid|process name]"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$PID" ] ; then
|
2013-08-20 00:14:16 +02:00
|
|
|
# Determine whether the process is native
|
|
|
|
if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
|
|
|
|
# Dump stacks of Dalvik process
|
|
|
|
local TRACES=/data/anr/traces.txt
|
|
|
|
local ORIG=/data/anr/traces.orig
|
|
|
|
local TMP=/data/anr/traces.tmp
|
|
|
|
|
|
|
|
# Keep original traces to avoid clobbering
|
|
|
|
adb shell mv $TRACES $ORIG
|
|
|
|
|
|
|
|
# Make sure we have a usable file
|
|
|
|
adb shell touch $TRACES
|
|
|
|
adb shell chmod 666 $TRACES
|
|
|
|
|
|
|
|
# Dump stacks and wait for dump to finish
|
|
|
|
adb shell kill -3 $PID
|
|
|
|
adb shell notify $TRACES >/dev/null
|
|
|
|
|
|
|
|
# Restore original stacks, and show current output
|
|
|
|
adb shell mv $TRACES $TMP
|
|
|
|
adb shell mv $ORIG $TRACES
|
|
|
|
adb shell cat $TMP
|
|
|
|
else
|
|
|
|
# Dump stacks of native process
|
2014-06-20 04:58:12 +02:00
|
|
|
local USE64BIT="$(is64bit $PID)"
|
|
|
|
adb shell debuggerd$USE64BIT -b $PID
|
2013-08-20 00:14:16 +02:00
|
|
|
fi
|
2013-02-20 02:00:46 +01:00
|
|
|
fi
|
2009-11-13 00:33:08 +01:00
|
|
|
}
|
|
|
|
|
2012-11-09 18:48:04 +01:00
|
|
|
function gdbwrapper()
|
|
|
|
{
|
2014-02-25 19:27:07 +01:00
|
|
|
local GDB_CMD="$1"
|
|
|
|
shift 1
|
|
|
|
$GDB_CMD -x "$@"
|
|
|
|
}
|
|
|
|
|
2014-05-28 23:36:43 +02:00
|
|
|
function get_symbols_directory()
|
|
|
|
{
|
|
|
|
echo $(get_abs_build_var TARGET_OUT_UNSTRIPPED)
|
|
|
|
}
|
|
|
|
|
2014-06-20 04:58:12 +02:00
|
|
|
# Read the ELF header from /proc/$PID/exe to determine if the process is
|
|
|
|
# 64-bit.
|
2014-02-25 19:27:07 +01:00
|
|
|
function is64bit()
|
|
|
|
{
|
|
|
|
local PID="$1"
|
|
|
|
if [ "$PID" ] ; then
|
2014-06-20 04:58:12 +02:00
|
|
|
if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
|
2014-02-25 19:27:07 +01:00
|
|
|
echo "64"
|
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
fi
|
2012-11-09 18:48:04 +01:00
|
|
|
}
|
|
|
|
|
2014-10-31 06:00:17 +01:00
|
|
|
function adb_get_product_device() {
|
2014-11-12 23:16:12 +01:00
|
|
|
local candidate=`adb shell getprop ro.product.device | sed s/.$//`
|
|
|
|
if [ -z $candidate ]; then
|
|
|
|
candidate=`adb shell getprop ro.hardware | sed s/.$//`
|
|
|
|
fi
|
|
|
|
echo $candidate
|
2014-10-31 06:00:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# returns 0 when process is not traced
|
|
|
|
function adb_get_traced_by() {
|
|
|
|
echo `adb shell cat /proc/$1/status | grep -e "^TracerPid:" | sed "s/^TracerPid:\t//" | sed s/.$//`
|
|
|
|
}
|
|
|
|
|
|
|
|
function gdbclient() {
|
|
|
|
# TODO:
|
|
|
|
# 1. Check for ANDROID_SERIAL/multiple devices
|
|
|
|
local PROCESS_NAME="n/a"
|
|
|
|
local PID=$1
|
|
|
|
local PORT=5039
|
|
|
|
if [ -z "$PID" ]; then
|
|
|
|
echo "Usage: gdbclient <pid|processname> [port number]"
|
|
|
|
return -1
|
|
|
|
fi
|
|
|
|
local DEVICE=$(adb_get_product_device)
|
|
|
|
|
|
|
|
if [ -z "$DEVICE" ]; then
|
|
|
|
echo "Error: Unable to get device name. Please check if device is connected and ANDROID_SERIAL is set."
|
|
|
|
return -2
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$2" ]; then
|
|
|
|
PORT=$2
|
|
|
|
fi
|
|
|
|
|
|
|
|
local ROOT=$(gettop)
|
|
|
|
if [ -z "$ROOT" ]; then
|
|
|
|
# This is for the situation with downloaded symbols (from the build server)
|
|
|
|
# we check if they are available.
|
|
|
|
ROOT=`realpath .`
|
|
|
|
fi
|
|
|
|
|
|
|
|
local OUT_ROOT="$ROOT/out/target/product/$DEVICE"
|
|
|
|
local SYMBOLS_DIR="$OUT_ROOT/symbols"
|
2014-11-12 23:16:12 +01:00
|
|
|
local IS_TAPAS_USER="$(get_build_var TARGET_BUILD_APPS)"
|
|
|
|
local TAPAS_SYMBOLS_DIR=
|
|
|
|
|
|
|
|
if [ $IS_TAPAS_USER ]; then
|
|
|
|
TAPAS_SYMBOLS_DIR=$(get_symbols_directory)
|
|
|
|
fi
|
2014-10-31 06:00:17 +01:00
|
|
|
|
|
|
|
if [ ! -d $SYMBOLS_DIR ]; then
|
2014-11-12 23:16:12 +01:00
|
|
|
if [ $IS_TAPAS_USER ]; then
|
|
|
|
mkdir -p $SYMBOLS_DIR/system/bin
|
|
|
|
else
|
|
|
|
echo "Error: couldn't find symbols: $SYMBOLS_DIR does not exist or is not a directory."
|
|
|
|
return -3
|
|
|
|
fi
|
2014-10-31 06:00:17 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# let's figure out which executable we are about to debug
|
|
|
|
|
|
|
|
# check if user specified a name -> resolve to pid
|
|
|
|
if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
|
|
|
|
PROCESS_NAME=$PID
|
|
|
|
PID=$(pid --exact $PROCESS_NAME)
|
|
|
|
if [ -z "$PID" ]; then
|
|
|
|
echo "Error: couldn't resolve pid by process name: $PROCESS_NAME"
|
|
|
|
return -4
|
2015-01-22 22:22:17 +01:00
|
|
|
else
|
|
|
|
echo "Resolved pid for $PROCESS_NAME is $PID"
|
2014-10-31 06:00:17 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
local EXE=`adb shell readlink /proc/$PID/exe | sed s/.$//`
|
2015-01-22 22:22:17 +01:00
|
|
|
|
|
|
|
if [ -z "$EXE" ]; then
|
|
|
|
echo "Error: no such pid=$PID - is process still alive?"
|
|
|
|
return -4
|
|
|
|
fi
|
|
|
|
|
2014-10-31 06:00:17 +01:00
|
|
|
local LOCAL_EXE_PATH=$SYMBOLS_DIR$EXE
|
|
|
|
|
|
|
|
if [ ! -f $LOCAL_EXE_PATH ]; then
|
2014-11-12 23:16:12 +01:00
|
|
|
if [ $IS_TAPAS_USER ]; then
|
|
|
|
adb pull $EXE $LOCAL_EXE_PATH
|
|
|
|
else
|
|
|
|
echo "Error: unable to find symbols for executable $EXE: file $LOCAL_EXE_PATH does not exist"
|
|
|
|
return -5
|
|
|
|
fi
|
2014-10-31 06:00:17 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
local USE64BIT=""
|
|
|
|
|
|
|
|
if [[ "$(file $LOCAL_EXE_PATH)" =~ 64-bit ]]; then
|
|
|
|
USE64BIT="64"
|
|
|
|
fi
|
|
|
|
|
2014-11-12 23:16:12 +01:00
|
|
|
# and now linker for tapas users...
|
|
|
|
if [ -n "$IS_TAPAS_USER" -a ! -f "$SYMBOLS_DIR/system/bin/linker$USE64BIT" ]; then
|
|
|
|
adb pull /system/bin/linker$USE64BIT $SYMBOLS_DIR/system/bin/linker$USE64BIT
|
|
|
|
fi
|
|
|
|
|
2014-10-31 06:00:17 +01:00
|
|
|
local GDB=
|
|
|
|
local GDB64=
|
|
|
|
local CPU_ABI=`adb shell getprop ro.product.cpu.abilist | sed s/.$//`
|
|
|
|
# TODO: we assume these are available via $PATH
|
|
|
|
if [[ $CPU_ABI =~ (^|,)arm64 ]]; then
|
|
|
|
GDB=arm-linux-androideabi-gdb
|
|
|
|
GDB64=aarch64-linux-android-gdb
|
|
|
|
elif [[ $CPU_ABI =~ (^|,)arm ]]; then
|
|
|
|
GDB=arm-linux-androideabi-gdb
|
|
|
|
elif [[ $CPU_ABI =~ (^|,)x86_64 ]]; then
|
2015-01-05 23:33:33 +01:00
|
|
|
GDB=x86_64-linux-android-gdb
|
2014-10-31 06:00:17 +01:00
|
|
|
elif [[ $CPU_ABI =~ (^|,)x86 ]]; then
|
2015-01-05 23:33:33 +01:00
|
|
|
GDB=x86_64-linux-android-gdb
|
2014-10-31 06:00:17 +01:00
|
|
|
elif [[ $CPU_ABI =~ (^|,)mips64 ]]; then
|
|
|
|
GDB=mipsel-linux-android-gdb
|
|
|
|
GDB64=mips64el-linux-android-gdb
|
|
|
|
elif [[ $CPU_ABI =~ (^|,)mips ]]; then
|
|
|
|
GDB=mipsel-linux-android-gdb
|
|
|
|
else
|
|
|
|
echo "Error: unrecognized cpu.abilist: $CPU_ABI"
|
|
|
|
return -6
|
|
|
|
fi
|
|
|
|
|
|
|
|
# TODO: check if tracing process is gdbserver and not some random strace...
|
2014-11-12 23:16:12 +01:00
|
|
|
if [ "$(adb_get_traced_by $PID)" -eq 0 ]; then
|
2014-10-31 06:00:17 +01:00
|
|
|
# start gdbserver
|
|
|
|
echo "Starting gdbserver..."
|
|
|
|
# TODO: check if adb is already listening $PORT
|
|
|
|
# to avoid unnecessary calls
|
|
|
|
echo ". adb forward for port=$PORT..."
|
|
|
|
adb forward tcp:$PORT tcp:$PORT
|
|
|
|
echo ". starting gdbserver to attach to pid=$PID..."
|
|
|
|
adb shell gdbserver$USE64BIT :$PORT --attach $PID &
|
|
|
|
echo ". give it couple of seconds to start..."
|
|
|
|
sleep 2
|
|
|
|
echo ". done"
|
|
|
|
else
|
|
|
|
echo "It looks like gdbserver is already attached to $PID (process is traced), trying to connect to it using local port=$PORT"
|
2014-11-12 23:16:12 +01:00
|
|
|
adb forward tcp:$PORT tcp:$PORT
|
2014-10-31 06:00:17 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
local OUT_SO_SYMBOLS=$SYMBOLS_DIR/system/lib$USE64BIT
|
2014-11-12 23:16:12 +01:00
|
|
|
local TAPAS_OUT_SO_SYMBOLS=$TAPAS_SYMBOLS_DIR/system/lib$USE64BIT
|
2014-10-31 06:00:17 +01:00
|
|
|
local OUT_VENDOR_SO_SYMBOLS=$SYMBOLS_DIR/vendor/lib$USE64BIT
|
|
|
|
local ART_CMD=""
|
|
|
|
|
2014-11-12 23:16:12 +01:00
|
|
|
local SOLIB_SYSROOT=$SYMBOLS_DIR
|
|
|
|
local SOLIB_SEARCHPATH=$OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines:$OUT_SO_SYMBOLS/drm:$OUT_SO_SYMBOLS/egl:$OUT_SO_SYMBOLS/soundfx:$OUT_VENDOR_SO_SYMBOLS:$OUT_VENDOR_SO_SYMBOLS/hw:$OUT_VENDOR_SO_SYMBOLS/egl
|
|
|
|
|
|
|
|
if [ $IS_TAPAS_USER ]; then
|
|
|
|
SOLIB_SYSROOT=$TAPAS_SYMBOLS_DIR:$SOLIB_SYSROOT
|
|
|
|
SOLIB_SEARCHPATH=$TAPAS_OUT_SO_SYMBOLS:$SOLIB_SEARCHPATH
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $SOLIB_SYSROOT"
|
|
|
|
echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $SOLIB_SEARCHPATH"
|
2014-10-31 06:00:17 +01:00
|
|
|
local DALVIK_GDB_SCRIPT=$ROOT/development/scripts/gdb/dalvik.gdb
|
|
|
|
if [ -f $DALVIK_GDB_SCRIPT ]; then
|
|
|
|
echo >>"$OUT_ROOT/gdbclient.cmds" "source $DALVIK_GDB_SCRIPT"
|
|
|
|
ART_CMD="art-on"
|
|
|
|
else
|
|
|
|
echo "Warning: couldn't find $DALVIK_GDB_SCRIPT - ART debugging options will not be available"
|
|
|
|
fi
|
|
|
|
echo >>"$OUT_ROOT/gdbclient.cmds" "target remote :$PORT"
|
|
|
|
if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
|
|
|
|
echo >> "$OUT_ROOT/gdbclient.cmds" $ART_CMD
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo >>"$OUT_ROOT/gdbclient.cmds" ""
|
|
|
|
|
|
|
|
local WHICH_GDB=$GDB
|
|
|
|
|
|
|
|
if [ -n "$USE64BIT" -a -n "$GDB64" ]; then
|
|
|
|
WHICH_GDB=$GDB64
|
|
|
|
fi
|
|
|
|
|
|
|
|
gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$LOCAL_EXE_PATH"
|
|
|
|
}
|
|
|
|
|
2014-02-25 19:27:07 +01:00
|
|
|
# gdbclient now determines whether the user wants to debug a 32-bit or 64-bit
|
|
|
|
# executable, set up the approriate gdbserver, then invokes the proper host
|
|
|
|
# gdb.
|
2014-10-31 06:00:17 +01:00
|
|
|
function gdbclient_old()
|
2008-10-21 16:00:00 +02:00
|
|
|
{
|
2008-12-18 03:03:49 +01:00
|
|
|
local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
|
|
|
|
local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
|
|
|
|
local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
|
2014-05-22 20:59:10 +02:00
|
|
|
local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
|
2014-05-28 23:36:43 +02:00
|
|
|
local OUT_EXE_SYMBOLS=$(get_symbols_directory)
|
2008-12-18 03:03:49 +01:00
|
|
|
local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
|
2011-11-11 18:02:01 +01:00
|
|
|
local ARCH=$(get_build_var TARGET_ARCH)
|
|
|
|
local GDB
|
|
|
|
case "$ARCH" in
|
|
|
|
arm) GDB=arm-linux-androideabi-gdb;;
|
2014-02-25 19:27:07 +01:00
|
|
|
arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
|
2014-07-22 23:34:00 +02:00
|
|
|
mips|mips64) GDB=mips64el-linux-android-gdb;;
|
2014-01-14 11:33:53 +01:00
|
|
|
x86) GDB=x86_64-linux-android-gdb;;
|
|
|
|
x86_64) GDB=x86_64-linux-android-gdb;;
|
2011-11-11 18:02:01 +01:00
|
|
|
*) echo "Unknown arch $ARCH"; return 1;;
|
|
|
|
esac
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
|
|
|
|
local EXE="$1"
|
|
|
|
if [ "$EXE" ] ; then
|
|
|
|
EXE=$1
|
2014-06-20 23:12:12 +02:00
|
|
|
if [[ $EXE =~ ^[^/].* ]] ; then
|
|
|
|
EXE="system/bin/"$EXE
|
|
|
|
fi
|
2008-10-21 16:00:00 +02:00
|
|
|
else
|
|
|
|
EXE="app_process"
|
|
|
|
fi
|
|
|
|
|
|
|
|
local PORT="$2"
|
|
|
|
if [ "$PORT" ] ; then
|
|
|
|
PORT=$2
|
|
|
|
else
|
|
|
|
PORT=":5039"
|
|
|
|
fi
|
|
|
|
|
2012-11-10 03:02:19 +01:00
|
|
|
local PID="$3"
|
|
|
|
if [ "$PID" ] ; then
|
|
|
|
if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
|
2011-04-30 20:04:05 +02:00
|
|
|
PID=`pid $3`
|
2012-11-10 03:02:19 +01:00
|
|
|
if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
|
|
|
|
# that likely didn't work because of returning multiple processes
|
|
|
|
# try again, filtering by root processes (don't contain colon)
|
2013-08-27 23:15:50 +02:00
|
|
|
PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
|
2012-11-10 03:02:19 +01:00
|
|
|
if [[ ! "$PID" =~ ^[0-9]+$ ]]
|
|
|
|
then
|
|
|
|
echo "Couldn't resolve '$3' to single PID"
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
echo "WARNING: multiple processes matching '$3' observed, using root process"
|
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
fi
|
2011-04-30 20:04:05 +02:00
|
|
|
fi
|
2008-10-21 16:00:00 +02:00
|
|
|
adb forward "tcp$PORT" "tcp$PORT"
|
2014-02-25 19:27:07 +01:00
|
|
|
local USE64BIT="$(is64bit $PID)"
|
|
|
|
adb shell gdbserver$USE64BIT $PORT --attach $PID &
|
2008-10-21 16:00:00 +02:00
|
|
|
sleep 2
|
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
echo "If you haven't done so already, do this first on the device:"
|
|
|
|
echo " gdbserver $PORT /system/bin/$EXE"
|
|
|
|
echo " or"
|
2012-11-10 03:02:19 +01:00
|
|
|
echo " gdbserver $PORT --attach <PID>"
|
2008-10-21 16:00:00 +02:00
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
|
2014-04-10 21:51:39 +02:00
|
|
|
OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
|
2014-06-20 22:33:36 +02:00
|
|
|
OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
|
2014-04-10 21:51:39 +02:00
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
|
2014-05-22 20:59:10 +02:00
|
|
|
echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines:$OUT_SO_SYMBOLS/drm:$OUT_SO_SYMBOLS/egl:$OUT_SO_SYMBOLS/soundfx:$OUT_VENDOR_SO_SYMBOLS:$OUT_VENDOR_SO_SYMBOLS/hw:$OUT_VENDOR_SO_SYMBOLS/egl"
|
2013-06-24 23:36:21 +02:00
|
|
|
echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
|
2008-10-21 16:00:00 +02:00
|
|
|
echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
|
2014-10-04 02:29:27 +02:00
|
|
|
# Enable special debugging for ART processes.
|
|
|
|
if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
|
|
|
|
echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
|
|
|
|
fi
|
2008-10-21 16:00:00 +02:00
|
|
|
echo >>"$OUT_ROOT/gdbclient.cmds" ""
|
|
|
|
|
2014-02-25 19:27:07 +01:00
|
|
|
local WHICH_GDB=
|
|
|
|
# 64-bit exe found
|
|
|
|
if [ "$USE64BIT" != "" ] ; then
|
|
|
|
WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
|
|
|
|
# 32-bit exe / 32-bit platform
|
|
|
|
elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
|
|
|
|
WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
|
|
|
|
# 32-bit exe / 64-bit platform
|
|
|
|
else
|
|
|
|
WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
|
|
|
|
fi
|
2014-05-28 23:36:43 +02:00
|
|
|
|
2014-02-25 19:27:07 +01:00
|
|
|
gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
|
2008-10-21 16:00:00 +02:00
|
|
|
else
|
|
|
|
echo "Unable to determine build system output dir."
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case `uname -s` in
|
|
|
|
Darwin)
|
|
|
|
function sgrep()
|
|
|
|
{
|
2014-07-27 00:15:41 +02:00
|
|
|
find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl)' -print0 | xargs -0 grep --color -n "$@"
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
function sgrep()
|
|
|
|
{
|
2014-07-27 00:15:41 +02:00
|
|
|
find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\)' -print0 | xargs -0 grep --color -n "$@"
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2012-07-26 04:57:22 +02:00
|
|
|
function gettargetarch
|
|
|
|
{
|
|
|
|
get_build_var TARGET_ARCH
|
|
|
|
}
|
|
|
|
|
2014-04-07 19:57:38 +02:00
|
|
|
function ggrep()
|
|
|
|
{
|
|
|
|
find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
|
|
|
|
}
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
function jgrep()
|
|
|
|
{
|
2013-07-05 15:09:25 +02:00
|
|
|
find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function cgrep()
|
|
|
|
{
|
2014-11-22 19:16:01 +01:00
|
|
|
find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) -print0 | xargs -0 grep --color -n "$@"
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function resgrep()
|
|
|
|
{
|
2013-07-05 15:09:25 +02:00
|
|
|
for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
2013-03-08 19:20:47 +01:00
|
|
|
function mangrep()
|
|
|
|
{
|
|
|
|
find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
|
|
|
|
}
|
|
|
|
|
2013-05-06 23:11:48 +02:00
|
|
|
function sepgrep()
|
|
|
|
{
|
|
|
|
find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d -print0 | xargs -0 grep --color -n -r --exclude-dir=\.git "$@"
|
|
|
|
}
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
case `uname -s` in
|
|
|
|
Darwin)
|
|
|
|
function mgrep()
|
|
|
|
{
|
2012-08-18 00:03:20 +02:00
|
|
|
find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@"
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function treegrep()
|
|
|
|
{
|
2011-03-15 22:15:46 +01:00
|
|
|
find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@"
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
function mgrep()
|
|
|
|
{
|
2012-08-18 00:03:20 +02:00
|
|
|
find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f -print0 | xargs -0 grep --color -n "$@"
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function treegrep()
|
|
|
|
{
|
2011-03-15 22:15:46 +01:00
|
|
|
find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@"
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
function getprebuilt
|
|
|
|
{
|
|
|
|
get_abs_build_var ANDROID_PREBUILTS
|
|
|
|
}
|
|
|
|
|
|
|
|
function tracedmdump()
|
|
|
|
{
|
|
|
|
T=$(gettop)
|
|
|
|
if [ ! "$T" ]; then
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP."
|
|
|
|
return
|
|
|
|
fi
|
2008-12-18 03:03:49 +01:00
|
|
|
local prebuiltdir=$(getprebuilt)
|
2012-07-26 04:57:22 +02:00
|
|
|
local arch=$(gettargetarch)
|
|
|
|
local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
local TRACE=$1
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ ! "$TRACE" ] ; then
|
|
|
|
echo "usage: tracedmdump tracename"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2009-04-10 03:12:34 +02:00
|
|
|
if [ ! -r "$KERNEL" ] ; then
|
|
|
|
echo "Error: cannot find kernel: '$KERNEL'"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
local BASETRACE=$(basename $TRACE)
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ "$BASETRACE" = "$TRACE" ] ; then
|
|
|
|
TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "post-processing traces..."
|
|
|
|
rm -f $TRACE/qtrace.dexlist
|
|
|
|
post_trace $TRACE
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "***"
|
|
|
|
echo "*** Error: malformed trace. Did you remember to exit the emulator?"
|
|
|
|
echo "***"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
echo "generating dexlist output..."
|
|
|
|
/bin/ls $ANDROID_PRODUCT_OUT/system/framework/*.jar $ANDROID_PRODUCT_OUT/system/app/*.apk $ANDROID_PRODUCT_OUT/data/app/*.apk 2>/dev/null | xargs dexlist > $TRACE/qtrace.dexlist
|
|
|
|
echo "generating dmtrace data..."
|
|
|
|
q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
|
|
|
|
echo "generating html file..."
|
|
|
|
dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
|
|
|
|
echo "done, see $TRACE/dmtrace.html for details"
|
|
|
|
echo "or run:"
|
|
|
|
echo " traceview $TRACE/dmtrace"
|
|
|
|
}
|
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
# communicate with a running device or emulator, set up necessary state,
|
|
|
|
# and run the hat command.
|
2008-10-21 16:00:00 +02:00
|
|
|
function runhat()
|
|
|
|
{
|
2008-12-18 03:03:49 +01:00
|
|
|
# process standard adb options
|
|
|
|
local adbTarget=""
|
2010-07-12 17:00:19 +02:00
|
|
|
if [ "$1" = "-d" -o "$1" = "-e" ]; then
|
2008-12-18 03:03:49 +01:00
|
|
|
adbTarget=$1
|
|
|
|
shift 1
|
2010-07-12 17:00:19 +02:00
|
|
|
elif [ "$1" = "-s" ]; then
|
2008-12-18 03:03:49 +01:00
|
|
|
adbTarget="$1 $2"
|
|
|
|
shift 2
|
|
|
|
fi
|
|
|
|
local adbOptions=${adbTarget}
|
2012-09-27 00:00:59 +02:00
|
|
|
#echo adbOptions = ${adbOptions}
|
2008-12-18 03:03:49 +01:00
|
|
|
|
|
|
|
# runhat options
|
|
|
|
local targetPid=$1
|
2008-10-21 16:00:00 +02:00
|
|
|
|
|
|
|
if [ "$targetPid" = "" ]; then
|
2010-07-12 17:00:19 +02:00
|
|
|
echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
|
2008-10-21 16:00:00 +02:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
# confirm hat is available
|
|
|
|
if [ -z $(which hat) ]; then
|
|
|
|
echo "hat is not available in this configuration."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2010-07-12 17:00:19 +02:00
|
|
|
# issue "am" command to cause the hprof dump
|
2014-07-19 00:45:38 +02:00
|
|
|
local devFile=/data/local/tmp/hprof-$targetPid
|
2008-10-21 16:00:00 +02:00
|
|
|
echo "Poking $targetPid and waiting for data..."
|
2012-09-27 00:00:59 +02:00
|
|
|
echo "Storing data at $devFile"
|
2010-07-12 17:00:19 +02:00
|
|
|
adb ${adbOptions} shell am dumpheap $targetPid $devFile
|
2009-03-04 04:28:42 +01:00
|
|
|
echo "Press enter when logcat shows \"hprof: heap dump completed\""
|
2008-10-21 16:00:00 +02:00
|
|
|
echo -n "> "
|
|
|
|
read
|
|
|
|
|
2009-03-04 04:28:42 +01:00
|
|
|
local localFile=/tmp/$$-hprof
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2009-03-04 04:28:42 +01:00
|
|
|
echo "Retrieving file $devFile..."
|
|
|
|
adb ${adbOptions} pull $devFile $localFile
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2009-03-04 04:28:42 +01:00
|
|
|
adb ${adbOptions} shell rm $devFile
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2009-03-04 04:28:42 +01:00
|
|
|
echo "Running hat on $localFile"
|
2008-10-21 16:00:00 +02:00
|
|
|
echo "View the output by pointing your browser at http://localhost:7000/"
|
|
|
|
echo ""
|
2011-11-11 00:19:51 +01:00
|
|
|
hat -JXmx512m $localFile
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getbugreports()
|
|
|
|
{
|
2008-12-18 03:03:49 +01:00
|
|
|
local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
|
2008-10-21 16:00:00 +02:00
|
|
|
|
|
|
|
if [ ! "$reports" ]; then
|
|
|
|
echo "Could not locate any bugreports."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
local report
|
|
|
|
for report in ${reports[@]}
|
2008-10-21 16:00:00 +02:00
|
|
|
do
|
2008-12-18 03:03:49 +01:00
|
|
|
echo "/sdcard/bugreports/${report}"
|
|
|
|
adb pull /sdcard/bugreports/${report} ${report}
|
|
|
|
gunzip ${report}
|
2008-10-21 16:00:00 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2012-08-22 00:44:06 +02:00
|
|
|
function getsdcardpath()
|
|
|
|
{
|
|
|
|
adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getscreenshotpath()
|
|
|
|
{
|
|
|
|
echo "$(getsdcardpath)/Pictures/Screenshots"
|
|
|
|
}
|
|
|
|
|
|
|
|
function getlastscreenshot()
|
|
|
|
{
|
|
|
|
local screenshot_path=$(getscreenshotpath)
|
|
|
|
local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
|
|
|
|
if [ "$screenshot" = "" ]; then
|
|
|
|
echo "No screenshots found."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
echo "${screenshot}"
|
|
|
|
adb ${adbOptions} pull ${screenshot_path}/${screenshot}
|
|
|
|
}
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
function startviewserver()
|
|
|
|
{
|
2008-12-18 03:03:49 +01:00
|
|
|
local port=4939
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
port=$1
|
|
|
|
fi
|
|
|
|
adb shell service call window 1 i32 $port
|
|
|
|
}
|
|
|
|
|
|
|
|
function stopviewserver()
|
|
|
|
{
|
|
|
|
adb shell service call window 2
|
|
|
|
}
|
|
|
|
|
|
|
|
function isviewserverstarted()
|
|
|
|
{
|
|
|
|
adb shell service call window 3
|
|
|
|
}
|
|
|
|
|
2010-10-05 01:56:11 +02:00
|
|
|
function key_home()
|
|
|
|
{
|
|
|
|
adb shell input keyevent 3
|
|
|
|
}
|
|
|
|
|
|
|
|
function key_back()
|
|
|
|
{
|
|
|
|
adb shell input keyevent 4
|
|
|
|
}
|
|
|
|
|
|
|
|
function key_menu()
|
|
|
|
{
|
|
|
|
adb shell input keyevent 82
|
|
|
|
}
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
function smoketest()
|
|
|
|
{
|
|
|
|
if [ ! "$ANDROID_PRODUCT_OUT" ]; then
|
|
|
|
echo "Couldn't locate output files. Try running 'lunch' first." >&2
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
T=$(gettop)
|
|
|
|
if [ ! "$T" ]; then
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP." >&2
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2012-12-13 19:52:07 +01:00
|
|
|
(\cd "$T" && mmm tests/SmokeTest) &&
|
2008-10-21 16:00:00 +02:00
|
|
|
adb uninstall com.android.smoketest > /dev/null &&
|
|
|
|
adb uninstall com.android.smoketest.tests > /dev/null &&
|
|
|
|
adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
|
|
|
|
adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
|
|
|
|
adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
|
|
|
|
}
|
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
# simple shortcut to the runtest command
|
|
|
|
function runtest()
|
|
|
|
{
|
|
|
|
T=$(gettop)
|
|
|
|
if [ ! "$T" ]; then
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP." >&2
|
|
|
|
return
|
|
|
|
fi
|
2009-10-22 05:05:26 +02:00
|
|
|
("$T"/development/testrunner/runtest.py $@)
|
2009-03-27 18:25:11 +01:00
|
|
|
}
|
|
|
|
|
2009-03-04 04:28:42 +01:00
|
|
|
function godir () {
|
|
|
|
if [[ -z "$1" ]]; then
|
|
|
|
echo "Usage: godir <regex>"
|
|
|
|
return
|
|
|
|
fi
|
2010-01-30 01:39:32 +01:00
|
|
|
T=$(gettop)
|
2009-03-04 04:28:42 +01:00
|
|
|
if [[ ! -f $T/filelist ]]; then
|
|
|
|
echo -n "Creating index..."
|
2012-12-13 19:52:07 +01:00
|
|
|
(\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
|
2009-03-04 04:28:42 +01:00
|
|
|
echo " Done"
|
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
local lines
|
2011-11-19 00:15:25 +01:00
|
|
|
lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
|
2009-03-04 04:28:42 +01:00
|
|
|
if [[ ${#lines[@]} = 0 ]]; then
|
|
|
|
echo "Not found"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
local pathname
|
|
|
|
local choice
|
|
|
|
if [[ ${#lines[@]} > 1 ]]; then
|
|
|
|
while [[ -z "$pathname" ]]; do
|
|
|
|
local index=1
|
|
|
|
local line
|
|
|
|
for line in ${lines[@]}; do
|
|
|
|
printf "%6s %s\n" "[$index]" $line
|
2011-04-22 17:16:56 +02:00
|
|
|
index=$(($index + 1))
|
2009-03-04 04:28:42 +01:00
|
|
|
done
|
|
|
|
echo
|
|
|
|
echo -n "Select one: "
|
|
|
|
unset choice
|
|
|
|
read choice
|
|
|
|
if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
|
|
|
|
echo "Invalid choice"
|
|
|
|
continue
|
|
|
|
fi
|
2010-07-05 09:53:47 +02:00
|
|
|
pathname=${lines[$(($choice-1))]}
|
2009-03-04 04:28:42 +01:00
|
|
|
done
|
|
|
|
else
|
|
|
|
pathname=${lines[0]}
|
|
|
|
fi
|
2012-12-13 19:52:07 +01:00
|
|
|
\cd $T/$pathname
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
2014-10-16 11:23:03 +02:00
|
|
|
# Force JAVA_HOME to point to java 1.7 if it isn't already set.
|
2014-01-17 11:05:25 +01:00
|
|
|
#
|
|
|
|
# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
|
|
|
|
# For some reason, installing the JDK doesn't make it show up in the
|
|
|
|
# JavaVM.framework/Versions/1.7/ folder.
|
2010-06-22 01:26:38 +02:00
|
|
|
function set_java_home() {
|
2014-01-17 11:05:25 +01:00
|
|
|
# Clear the existing JAVA_HOME value if we set it ourselves, so that
|
2014-04-01 15:16:26 +02:00
|
|
|
# we can reset it later, depending on the version of java the build
|
|
|
|
# system needs.
|
2014-01-17 11:05:25 +01:00
|
|
|
#
|
|
|
|
# If we don't do this, the JAVA_HOME value set by the first call to
|
|
|
|
# build/envsetup.sh will persist forever.
|
|
|
|
if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
|
|
|
|
export JAVA_HOME=""
|
|
|
|
fi
|
|
|
|
|
2010-06-24 21:52:51 +02:00
|
|
|
if [ ! "$JAVA_HOME" ]; then
|
2014-10-16 11:23:03 +02:00
|
|
|
case `uname -s` in
|
|
|
|
Darwin)
|
|
|
|
export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
|
|
|
|
;;
|
|
|
|
esac
|
2014-01-17 11:05:25 +01:00
|
|
|
|
|
|
|
# Keep track of the fact that we set JAVA_HOME ourselves, so that
|
|
|
|
# we can change it on the next envsetup.sh, if required.
|
|
|
|
export ANDROID_SET_JAVA_HOME=true
|
2010-06-07 22:03:54 +02:00
|
|
|
fi
|
2010-06-22 01:26:38 +02:00
|
|
|
}
|
2010-06-07 22:03:54 +02:00
|
|
|
|
2013-03-09 00:15:06 +01:00
|
|
|
# Print colored exit condition
|
|
|
|
function pez {
|
2013-03-09 02:34:02 +01:00
|
|
|
"$@"
|
|
|
|
local retval=$?
|
|
|
|
if [ $retval -ne 0 ]
|
|
|
|
then
|
|
|
|
echo -e "\e[0;31mFAILURE\e[00m"
|
|
|
|
else
|
|
|
|
echo -e "\e[0;32mSUCCESS\e[00m"
|
|
|
|
fi
|
|
|
|
return $retval
|
2013-03-09 00:15:06 +01:00
|
|
|
}
|
|
|
|
|
2014-08-25 07:14:19 +02:00
|
|
|
function get_make_command()
|
|
|
|
{
|
|
|
|
echo command make
|
|
|
|
}
|
|
|
|
|
2014-06-18 23:55:58 +02:00
|
|
|
function make()
|
|
|
|
{
|
|
|
|
local start_time=$(date +"%s")
|
2014-08-25 07:14:19 +02:00
|
|
|
$(get_make_command) "$@"
|
2014-06-18 23:55:58 +02:00
|
|
|
local ret=$?
|
|
|
|
local end_time=$(date +"%s")
|
|
|
|
local tdiff=$(($end_time-$start_time))
|
|
|
|
local hours=$(($tdiff / 3600 ))
|
|
|
|
local mins=$((($tdiff % 3600) / 60))
|
|
|
|
local secs=$(($tdiff % 60))
|
|
|
|
echo
|
|
|
|
if [ $ret -eq 0 ] ; then
|
2014-11-09 07:41:52 +01:00
|
|
|
if [ $(uname) != "Darwin" ]; then
|
|
|
|
echo -n -e "\e[0;32m#### make completed successfully "
|
|
|
|
else
|
|
|
|
echo -n -e "#### make completed successfully "
|
|
|
|
fi
|
2014-06-18 23:55:58 +02:00
|
|
|
else
|
2014-11-09 07:41:52 +01:00
|
|
|
if [ $(uname) != "Darwin" ]; then
|
|
|
|
echo -n -e "\e[0;31m#### make failed to build some targets "
|
|
|
|
else
|
|
|
|
echo -n -e "#### make failed to build some targets "
|
|
|
|
fi
|
2014-06-18 23:55:58 +02:00
|
|
|
fi
|
|
|
|
if [ $hours -gt 0 ] ; then
|
|
|
|
printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
|
|
|
|
elif [ $mins -gt 0 ] ; then
|
|
|
|
printf "(%02g:%02g (mm:ss))" $mins $secs
|
|
|
|
elif [ $secs -gt 0 ] ; then
|
|
|
|
printf "(%s seconds)" $secs
|
|
|
|
fi
|
2014-11-09 07:41:52 +01:00
|
|
|
if [ $(uname) != "Darwin" ]; then
|
|
|
|
echo -e " ####\e[00m"
|
|
|
|
fi
|
2014-06-18 23:55:58 +02:00
|
|
|
echo
|
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|
2011-06-21 01:03:14 +02:00
|
|
|
if [ "x$SHELL" != "x/bin/bash" ]; then
|
|
|
|
case `ps -o command -p $$` in
|
|
|
|
*bash*)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2008-12-18 03:03:49 +01:00
|
|
|
|
|
|
|
# Execute the contents of any vendorsetup.sh files we can find.
|
2014-07-10 00:37:34 +02:00
|
|
|
for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
|
|
|
|
`test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
|
2008-12-18 03:03:49 +01:00
|
|
|
do
|
|
|
|
echo "including $f"
|
|
|
|
. $f
|
|
|
|
done
|
|
|
|
unset f
|
2011-07-15 20:07:06 +02:00
|
|
|
|
|
|
|
addcompletions
|