2012-03-08 02:15:06 +01:00
|
|
|
function hmm() {
|
2008-10-21 16:00:00 +02:00
|
|
|
cat <<EOF
|
2017-05-31 02:12:37 +02:00
|
|
|
|
|
|
|
Run "m help" for help with the build system itself.
|
|
|
|
|
2008-12-18 03:03:49 +01:00
|
|
|
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
|
2018-12-06 19:11:40 +01:00
|
|
|
- lunch: lunch <product_name>-<build_variant>
|
|
|
|
Selects <product_name> as the product to build, and <build_variant> as the variant to
|
|
|
|
build, and stores those selections in the environment to be read by subsequent
|
|
|
|
invocations of 'm' etc.
|
2020-03-07 01:46:59 +01:00
|
|
|
- tapas: tapas [<App1> <App2> ...] [arm|x86|arm64|x86_64] [eng|userdebug|user]
|
2019-02-04 19:15:39 +01:00
|
|
|
- croot: Changes directory to the top of the tree, or a subdirectory thereof.
|
2018-12-06 19:11:40 +01:00
|
|
|
- m: Makes from the top of the tree.
|
2019-10-30 20:35:34 +01:00
|
|
|
- mm: Builds and installs all of the modules in the current directory, and their
|
|
|
|
dependencies.
|
|
|
|
- mmm: Builds and installs all of the modules in the supplied directories, and their
|
|
|
|
dependencies.
|
2018-12-06 19:11:40 +01:00
|
|
|
To limit the modules being built use the syntax: mmm dir/:target1,target2.
|
2019-10-30 20:35:34 +01:00
|
|
|
- mma: Same as 'mm'
|
|
|
|
- mmma: Same as 'mmm'
|
2018-12-06 19:11:40 +01:00
|
|
|
- provision: Flash device with all required partitions. Options will be passed on to fastboot.
|
|
|
|
- cgrep: Greps on all local C/C++ files.
|
|
|
|
- ggrep: Greps on all local Gradle files.
|
2019-10-25 12:35:15 +02:00
|
|
|
- gogrep: Greps on all local Go files.
|
2018-12-06 19:11:40 +01:00
|
|
|
- jgrep: Greps on all local Java files.
|
|
|
|
- resgrep: Greps on all local res/*.xml files.
|
|
|
|
- mangrep: Greps on all local AndroidManifest.xml files.
|
2019-05-04 19:06:28 +02:00
|
|
|
- mgrep: Greps on all local Makefiles and *.bp files.
|
2019-08-21 20:51:26 +02:00
|
|
|
- owngrep: Greps on all local OWNERS files.
|
2018-12-06 19:11:40 +01:00
|
|
|
- sepgrep: Greps on all local sepolicy files.
|
|
|
|
- sgrep: Greps on all local source files.
|
|
|
|
- godir: Go to the directory containing a file.
|
|
|
|
- allmod: List all modules.
|
|
|
|
- gomod: Go to the directory containing a module.
|
2019-01-24 23:34:23 +01:00
|
|
|
- pathmod: Get the directory containing a module.
|
2020-04-09 21:05:34 +02:00
|
|
|
- refreshmod: Refresh list of modules for allmod/gomod/pathmod.
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2015-10-20 13:48:19 +02:00
|
|
|
Environment options:
|
2019-09-27 01:30:28 +02:00
|
|
|
- SANITIZE_HOST: Set to 'address' to use ASAN for all host modules.
|
2019-01-31 22:25:31 +01:00
|
|
|
- ANDROID_QUIET_BUILD: set to 'true' to display only the essential messages.
|
2014-11-01 00:23:08 +01:00
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
Look at the source to view more functions. The complete list is:
|
|
|
|
EOF
|
2017-03-23 19:08:58 +01:00
|
|
|
local T=$(gettop)
|
|
|
|
local A=""
|
|
|
|
local i
|
2015-05-15 16:12:53 +02:00
|
|
|
for i in `cat $T/build/envsetup.sh | sed -n "/^[[:blank:]]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
|
2008-10-21 16:00:00 +02:00
|
|
|
A="$A $i"
|
|
|
|
done
|
|
|
|
echo $A
|
|
|
|
}
|
|
|
|
|
2016-03-04 05:57:21 +01:00
|
|
|
# Get all the build variables needed by this script in a single call to the build system.
|
|
|
|
function build_build_var_cache()
|
|
|
|
{
|
2017-03-23 19:08:58 +01:00
|
|
|
local T=$(gettop)
|
2016-03-04 05:57:21 +01:00
|
|
|
# Grep out the variable names from the script.
|
2018-06-19 10:34:41 +02:00
|
|
|
cached_vars=(`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`)
|
|
|
|
cached_abs_vars=(`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_abs_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`)
|
2016-03-04 05:57:21 +01:00
|
|
|
# Call the build system to dump the "<val>=<value>" pairs as a shell script.
|
2018-01-05 21:13:11 +01:00
|
|
|
build_dicts_script=`\builtin cd $T; build/soong/soong_ui.bash --dumpvars-mode \
|
2018-06-19 10:34:41 +02:00
|
|
|
--vars="${cached_vars[*]}" \
|
|
|
|
--abs-vars="${cached_abs_vars[*]}" \
|
2017-07-14 20:29:44 +02:00
|
|
|
--var-prefix=var_cache_ \
|
|
|
|
--abs-var-prefix=abs_var_cache_`
|
2016-03-04 05:57:21 +01:00
|
|
|
local ret=$?
|
|
|
|
if [ $ret -ne 0 ]
|
|
|
|
then
|
|
|
|
unset build_dicts_script
|
|
|
|
return $ret
|
|
|
|
fi
|
2017-07-14 20:29:44 +02:00
|
|
|
# Execute the script to store the "<val>=<value>" pairs as shell variables.
|
2016-03-04 05:57:21 +01:00
|
|
|
eval "$build_dicts_script"
|
|
|
|
ret=$?
|
2016-03-04 22:56:23 +01:00
|
|
|
unset build_dicts_script
|
2016-03-04 05:57:21 +01:00
|
|
|
if [ $ret -ne 0 ]
|
|
|
|
then
|
|
|
|
return $ret
|
|
|
|
fi
|
|
|
|
BUILD_VAR_CACHE_READY="true"
|
|
|
|
}
|
|
|
|
|
2016-03-04 22:56:23 +01:00
|
|
|
# Delete the build var cache, so that we can still call into the build system
|
2016-03-04 05:57:21 +01:00
|
|
|
# to get build variables not listed in this script.
|
|
|
|
function destroy_build_var_cache()
|
|
|
|
{
|
|
|
|
unset BUILD_VAR_CACHE_READY
|
2017-03-23 19:08:58 +01:00
|
|
|
local v
|
2016-03-04 05:57:21 +01:00
|
|
|
for v in $cached_vars; do
|
|
|
|
unset var_cache_$v
|
|
|
|
done
|
|
|
|
unset cached_vars
|
|
|
|
for v in $cached_abs_vars; do
|
|
|
|
unset abs_var_cache_$v
|
|
|
|
done
|
|
|
|
unset cached_abs_vars
|
|
|
|
}
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
# Get the value of a build variable as an absolute path.
|
|
|
|
function get_abs_build_var()
|
|
|
|
{
|
2016-03-04 05:57:21 +01:00
|
|
|
if [ "$BUILD_VAR_CACHE_READY" = "true" ]
|
|
|
|
then
|
2016-03-11 19:00:40 +01:00
|
|
|
eval "echo \"\${abs_var_cache_$1}\""
|
2016-03-04 05:57:21 +01:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2017-03-23 19:08:58 +01:00
|
|
|
local T=$(gettop)
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ ! "$T" ]; then
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP." >&2
|
|
|
|
return
|
|
|
|
fi
|
2017-07-14 20:29:44 +02:00
|
|
|
(\cd $T; build/soong/soong_ui.bash --dumpvar-mode --abs $1)
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Get the exact value of a build variable.
|
|
|
|
function get_build_var()
|
|
|
|
{
|
2016-03-04 05:57:21 +01:00
|
|
|
if [ "$BUILD_VAR_CACHE_READY" = "true" ]
|
|
|
|
then
|
2016-03-11 19:00:40 +01:00
|
|
|
eval "echo \"\${var_cache_$1}\""
|
2020-03-31 17:11:05 +02:00
|
|
|
return 0
|
2016-03-04 05:57:21 +01:00
|
|
|
fi
|
|
|
|
|
2017-03-23 19:08:58 +01:00
|
|
|
local T=$(gettop)
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ ! "$T" ]; then
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP." >&2
|
2020-03-31 17:11:05 +02:00
|
|
|
return 1
|
2008-10-21 16:00:00 +02:00
|
|
|
fi
|
2017-07-14 20:29:44 +02:00
|
|
|
(\cd $T; build/soong/soong_ui.bash --dumpvar-mode $1)
|
2008-12-18 03:03:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# check to see if the supplied product is one we can build
|
|
|
|
function check_product()
|
|
|
|
{
|
2017-03-23 19:08:58 +01:00
|
|
|
local T=$(gettop)
|
2008-12-18 03:03:49 +01:00
|
|
|
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()
|
|
|
|
{
|
2017-03-23 19:08:58 +01:00
|
|
|
local v
|
2008-12-18 03:03:49 +01:00
|
|
|
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()
|
|
|
|
{
|
2017-03-23 19:08:58 +01:00
|
|
|
local T=$(gettop)
|
2008-10-21 16:00:00 +02:00
|
|
|
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
|
2017-03-23 19:08:58 +01:00
|
|
|
local prebuiltdir=$(getprebuilt)
|
|
|
|
local 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
|
2017-03-23 19:08:58 +01:00
|
|
|
local targetgccversion=$(get_build_var TARGET_GCC_VERSION)
|
|
|
|
local 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)
|
2017-03-23 19:08:58 +01:00
|
|
|
local toolchaindir toolchaindir2=
|
2012-04-17 14:50:47 +02:00
|
|
|
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
|
|
|
;;
|
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
|
|
|
|
2017-03-23 19:08:58 +01:00
|
|
|
if [ "$toolchaindir2" -a -d "$gccprebuiltdir/$toolchaindir2" ]; then
|
2014-02-25 19:27:07 +01:00
|
|
|
export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
|
|
|
|
fi
|
|
|
|
|
2015-06-12 18:56:39 +02:00
|
|
|
export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
|
2017-04-07 23:11:54 +02:00
|
|
|
|
|
|
|
# add kernel specific binaries
|
|
|
|
case $(uname -s) in
|
|
|
|
Linux)
|
|
|
|
export ANDROID_DEV_SCRIPTS=$ANDROID_DEV_SCRIPTS:$T/prebuilts/misc/linux-x86/dtc:$T/prebuilts/misc/linux-x86/libufdt
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2017-10-03 22:31:18 +02:00
|
|
|
ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN
|
|
|
|
if [ -n "$ANDROID_TOOLCHAIN_2ND_ARCH" ]; then
|
|
|
|
ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_TOOLCHAIN_2ND_ARCH
|
|
|
|
fi
|
2019-05-22 01:00:04 +02:00
|
|
|
ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_DEV_SCRIPTS
|
|
|
|
|
|
|
|
# Append llvm binutils prebuilts path to ANDROID_BUILD_PATHS.
|
|
|
|
local ANDROID_LLVM_BINUTILS=$(get_abs_build_var ANDROID_CLANG_PREBUILTS)/llvm-binutils-stable
|
|
|
|
ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_LLVM_BINUTILS
|
2014-05-05 16:13:50 +02:00
|
|
|
|
2020-02-04 18:15:18 +01:00
|
|
|
# Set up ASAN_SYMBOLIZER_PATH for SANITIZE_HOST=address builds.
|
|
|
|
export ASAN_SYMBOLIZER_PATH=$ANDROID_LLVM_BINUTILS/llvm-symbolizer
|
|
|
|
|
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
|
2019-05-22 01:00:04 +02:00
|
|
|
ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_EMULATOR_PREBUILTS
|
2014-05-05 16:13:50 +02:00
|
|
|
export ANDROID_EMULATOR_PREBUILTS
|
|
|
|
fi
|
|
|
|
|
2018-12-22 03:24:55 +01:00
|
|
|
# Append asuite prebuilts path to ANDROID_BUILD_PATHS.
|
|
|
|
local os_arch=$(get_build_var HOST_PREBUILT_TAG)
|
2019-07-16 03:05:29 +02:00
|
|
|
local ACLOUD_PATH="$T/prebuilts/asuite/acloud/$os_arch"
|
|
|
|
local AIDEGEN_PATH="$T/prebuilts/asuite/aidegen/$os_arch"
|
|
|
|
local ATEST_PATH="$T/prebuilts/asuite/atest/$os_arch"
|
|
|
|
export ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ACLOUD_PATH:$AIDEGEN_PATH:$ATEST_PATH:
|
2018-12-22 03:24:55 +01:00
|
|
|
|
2019-07-16 03:05:29 +02:00
|
|
|
export PATH=$ANDROID_BUILD_PATHS$PATH
|
2018-12-17 08:21:53 +01:00
|
|
|
|
|
|
|
# out with the duplicate old
|
|
|
|
if [ -n $ANDROID_PYTHONPATH ]; then
|
|
|
|
export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/}
|
|
|
|
fi
|
|
|
|
# and in with the new
|
|
|
|
export ANDROID_PYTHONPATH=$T/development/python-packages:
|
2019-07-25 10:54:27 +02:00
|
|
|
if [ -n $VENDOR_PYTHONPATH ]; then
|
|
|
|
ANDROID_PYTHONPATH=$ANDROID_PYTHONPATH$VENDOR_PYTHONPATH
|
|
|
|
fi
|
2018-12-17 08:21:53 +01:00
|
|
|
export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH
|
2008-12-18 03:03:49 +01:00
|
|
|
|
2017-07-01 01:01:45 +02:00
|
|
|
export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME)
|
|
|
|
export JAVA_HOME=$ANDROID_JAVA_HOME
|
|
|
|
export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN)
|
|
|
|
export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
|
|
|
|
export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
|
2010-06-22 01:26:38 +02:00
|
|
|
|
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)
|
|
|
|
|
2017-02-13 22:46:48 +01:00
|
|
|
unset ANDROID_HOST_OUT_TESTCASES
|
|
|
|
export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
|
|
|
|
|
|
|
|
unset ANDROID_TARGET_OUT_TESTCASES
|
|
|
|
export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
|
|
|
|
|
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()
|
|
|
|
{
|
2017-03-23 19:08:58 +01:00
|
|
|
local T=$(gettop)
|
2008-12-18 03:03:49 +01:00
|
|
|
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
|
|
|
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'
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function set_sequence_number()
|
|
|
|
{
|
2017-03-22 01:41:03 +01:00
|
|
|
export BUILD_ENV_SEQUENCE_NUMBER=13
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
2018-06-18 19:15:19 +02:00
|
|
|
# Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not.
|
|
|
|
function should_add_completion() {
|
2018-06-19 10:34:41 +02:00
|
|
|
local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')"
|
2018-06-18 19:15:19 +02:00
|
|
|
case :"$ENVSETUP_NO_COMPLETION": in
|
2018-06-19 10:34:41 +02:00
|
|
|
*:"$cmd":*)
|
|
|
|
return 1
|
|
|
|
;;
|
2018-06-18 19:15:19 +02:00
|
|
|
esac
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2011-07-15 20:07:06 +02:00
|
|
|
function addcompletions()
|
|
|
|
{
|
|
|
|
local T dir f
|
|
|
|
|
2018-06-19 10:34:41 +02:00
|
|
|
# Keep us from trying to run in something that's neither bash nor zsh.
|
|
|
|
if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then
|
2011-07-15 20:07:06 +02:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Keep us from trying to run in bash that's too old.
|
2018-06-19 10:34:41 +02:00
|
|
|
if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then
|
2011-07-15 20:07:06 +02:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2018-06-19 10:34:41 +02:00
|
|
|
local completion_files=(
|
|
|
|
system/core/adb/adb.bash
|
|
|
|
system/core/fastboot/fastboot.bash
|
2018-12-22 03:24:55 +01:00
|
|
|
tools/asuite/asuite.sh
|
2018-06-19 10:34:41 +02:00
|
|
|
)
|
2018-06-18 19:15:19 +02:00
|
|
|
# Completion can be disabled selectively to allow users to use non-standard completion.
|
|
|
|
# e.g.
|
|
|
|
# ENVSETUP_NO_COMPLETION=adb # -> disable adb completion
|
|
|
|
# ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion
|
2018-06-19 10:34:41 +02:00
|
|
|
for f in ${completion_files[*]}; do
|
|
|
|
if [ -f "$f" ] && should_add_completion "$f"; then
|
2011-07-15 20:07:06 +02:00
|
|
|
. $f
|
2018-04-03 22:49:48 +02:00
|
|
|
fi
|
|
|
|
done
|
2016-10-21 01:39:49 +02:00
|
|
|
|
2018-06-18 19:15:19 +02:00
|
|
|
if should_add_completion bit ; then
|
|
|
|
complete -C "bit --tab" bit
|
|
|
|
fi
|
2019-02-04 19:15:39 +01:00
|
|
|
if [ -z "$ZSH_VERSION" ]; then
|
|
|
|
# Doesn't work in zsh.
|
|
|
|
complete -o nospace -F _croot croot
|
|
|
|
fi
|
2018-06-19 10:34:41 +02:00
|
|
|
complete -F _lunch lunch
|
2018-12-06 19:11:40 +01:00
|
|
|
|
2018-12-11 18:06:00 +01:00
|
|
|
complete -F _complete_android_module_names gomod
|
|
|
|
complete -F _complete_android_module_names m
|
2011-07-15 20:07:06 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2016-03-04 05:57:21 +01:00
|
|
|
build_build_var_cache
|
2008-10-21 16:00:00 +02:00
|
|
|
set_stuff_for_environment
|
2016-03-04 05:57:21 +01:00
|
|
|
destroy_build_var_cache
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2017-03-23 19:08:58 +01:00
|
|
|
local default_value
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ "x$TARGET_PRODUCT" != x ] ; then
|
|
|
|
default_value=$TARGET_PRODUCT
|
|
|
|
else
|
2015-06-08 20:57:26 +02:00
|
|
|
default_value=aosp_arm
|
2008-10-21 16:00:00 +02:00
|
|
|
fi
|
|
|
|
|
2016-03-04 05:57:21 +01:00
|
|
|
export TARGET_BUILD_APPS=
|
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
|
|
|
|
|
2016-03-04 05:57:21 +01:00
|
|
|
build_build_var_cache
|
2008-10-21 16:00:00 +02:00
|
|
|
set_stuff_for_environment
|
2016-03-04 05:57:21 +01:00
|
|
|
destroy_build_var_cache
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
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
|
2019-10-03 12:02:46 +02:00
|
|
|
export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[@]:$(($ANSWER-1)):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
|
2016-03-04 05:57:21 +01:00
|
|
|
build_build_var_cache
|
2008-10-21 16:00:00 +02:00
|
|
|
set_stuff_for_environment
|
2008-12-18 03:03:49 +01:00
|
|
|
printconfig
|
2016-03-04 05:57:21 +01:00
|
|
|
destroy_build_var_cache
|
2008-12-18 03:03:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function add_lunch_combo()
|
|
|
|
{
|
2019-02-12 06:31:47 +01:00
|
|
|
if [ -n "$ZSH_VERSION" ]; then
|
|
|
|
echo -n "${funcfiletrace[1]}: "
|
|
|
|
else
|
|
|
|
echo -n "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: "
|
|
|
|
fi
|
|
|
|
echo "add_lunch_combo is obsolete. Use COMMON_LUNCH_CHOICES in your AndroidProducts.mk instead."
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function print_lunch_menu()
|
|
|
|
{
|
|
|
|
local uname=$(uname)
|
2020-03-31 17:11:05 +02:00
|
|
|
local choices
|
|
|
|
choices=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES 2>/dev/null)
|
|
|
|
local ret=$?
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
echo
|
|
|
|
echo "You're building on" $uname
|
|
|
|
echo
|
2020-03-31 17:11:05 +02:00
|
|
|
|
|
|
|
if [ $ret -ne 0 ]
|
|
|
|
then
|
|
|
|
echo "Warning: Cannot display lunch menu."
|
|
|
|
echo
|
|
|
|
echo "Note: You can invoke lunch with an explicit target:"
|
|
|
|
echo
|
|
|
|
echo " usage: lunch [target]" >&2
|
|
|
|
echo
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
echo "Lunch menu... pick a combo:"
|
2008-12-18 03:03:49 +01:00
|
|
|
|
|
|
|
local i=1
|
|
|
|
local choice
|
2019-10-04 00:13:12 +02:00
|
|
|
for choice in $(echo $choices)
|
2008-12-18 03:03:49 +01:00
|
|
|
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
|
|
|
|
|
2020-02-26 03:30:18 +01:00
|
|
|
if [[ $# -gt 1 ]]; then
|
|
|
|
echo "usage: lunch [target]" >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
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
|
2019-02-12 06:31:47 +01:00
|
|
|
local choices=($(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES))
|
2018-04-05 00:41:41 +02:00
|
|
|
if [ $answer -le ${#choices[@]} ]
|
2008-12-18 03:03:49 +01:00
|
|
|
then
|
2018-10-03 12:25:50 +02:00
|
|
|
# array in zsh starts from 1 instead of 0.
|
|
|
|
if [ -n "$ZSH_VERSION" ]
|
|
|
|
then
|
|
|
|
selection=${choices[$(($answer))]}
|
|
|
|
else
|
|
|
|
selection=${choices[$(($answer-1))]}
|
|
|
|
fi
|
2008-12-18 03:03:49 +01:00
|
|
|
fi
|
2017-03-22 01:41:03 +01:00
|
|
|
else
|
2008-12-18 03:03:49 +01:00
|
|
|
selection=$answer
|
2008-10-21 16:00:00 +02:00
|
|
|
fi
|
|
|
|
|
2010-06-10 03:18:31 +02:00
|
|
|
export TARGET_BUILD_APPS=
|
|
|
|
|
2017-03-22 01:41:03 +01:00
|
|
|
local product variant_and_version variant version
|
|
|
|
|
|
|
|
product=${selection%%-*} # Trim everything after first dash
|
|
|
|
variant_and_version=${selection#*-} # Trim everything up to first dash
|
|
|
|
if [ "$variant_and_version" != "$selection" ]; then
|
|
|
|
variant=${variant_and_version%%-*}
|
|
|
|
if [ "$variant" != "$variant_and_version" ]; then
|
|
|
|
version=${variant_and_version#*-}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$product" ]
|
2011-07-12 07:11:46 +02:00
|
|
|
then
|
|
|
|
echo
|
2017-03-22 01:41:03 +01:00
|
|
|
echo "Invalid lunch combo: $selection"
|
|
|
|
return 1
|
2011-07-12 07:11:46 +02:00
|
|
|
fi
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2016-03-04 05:57:21 +01:00
|
|
|
TARGET_PRODUCT=$product \
|
|
|
|
TARGET_BUILD_VARIANT=$variant \
|
2017-03-22 01:41:03 +01:00
|
|
|
TARGET_PLATFORM_VERSION=$version \
|
2016-03-04 05:57:21 +01:00
|
|
|
build_build_var_cache
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
2011-07-12 07:11:46 +02:00
|
|
|
return 1
|
|
|
|
fi
|
2008-10-21 16:00:00 +02:00
|
|
|
|
2017-03-22 01:41:03 +01:00
|
|
|
export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
|
|
|
|
export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
|
2017-05-01 23:21:28 +02:00
|
|
|
if [ -n "$version" ]; then
|
|
|
|
export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
|
|
|
|
else
|
|
|
|
unset TARGET_PLATFORM_VERSION
|
|
|
|
fi
|
2011-07-12 07:11:46 +02:00
|
|
|
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
|
2016-03-04 05:57:21 +01:00
|
|
|
destroy_build_var_cache
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
2018-04-05 00:41:41 +02:00
|
|
|
unset COMMON_LUNCH_CHOICES_CACHE
|
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]}"
|
|
|
|
|
2018-04-05 00:41:41 +02:00
|
|
|
if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then
|
2019-02-12 06:31:47 +01:00
|
|
|
COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES)
|
2018-04-05 00:41:41 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) )
|
2010-08-02 19:00:44 +02:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2017-08-22 03:27:00 +02:00
|
|
|
local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)"
|
2020-03-07 01:46:59 +01:00
|
|
|
local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|arm64|x86_64)$' | 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)"
|
2020-03-07 01:46:59 +01:00
|
|
|
local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|arm64|x86_64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
|
2010-06-10 03:18:31 +02:00
|
|
|
|
2017-08-22 03:27:00 +02:00
|
|
|
if [ "$showHelp" != "" ]; then
|
|
|
|
$(gettop)/build/make/tapasHelp.sh
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
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
|
|
|
|
2015-06-08 20:57:26 +02:00
|
|
|
local product=aosp_arm
|
2012-08-22 19:25:20 +02:00
|
|
|
case $arch in
|
2015-06-08 20:57:26 +02:00
|
|
|
x86) product=aosp_x86;;
|
2014-05-30 02:57:40 +02:00
|
|
|
arm64) product=aosp_arm64;;
|
|
|
|
x86_64) product=aosp_x86_64;;
|
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
|
|
|
|
|
2016-03-04 05:57:21 +01:00
|
|
|
build_build_var_cache
|
2010-06-10 03:18:31 +02:00
|
|
|
set_stuff_for_environment
|
|
|
|
printconfig
|
2016-03-04 05:57:21 +01:00
|
|
|
destroy_build_var_cache
|
2010-06-10 03:18:31 +02:00
|
|
|
}
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
function gettop
|
|
|
|
{
|
2017-10-20 20:37:33 +02:00
|
|
|
local TOPFILE=build/make/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
|
2017-03-23 19:08:58 +01:00
|
|
|
local T=
|
2008-10-21 16:00:00 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
function croot()
|
|
|
|
{
|
2017-03-23 19:08:58 +01:00
|
|
|
local T=$(gettop)
|
2008-10-21 16:00:00 +02:00
|
|
|
if [ "$T" ]; then
|
2016-04-22 01:53:39 +02:00
|
|
|
if [ "$1" ]; then
|
|
|
|
\cd $(gettop)/$1
|
|
|
|
else
|
|
|
|
\cd $(gettop)
|
|
|
|
fi
|
2008-10-21 16:00:00 +02:00
|
|
|
else
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-02-04 19:15:39 +01:00
|
|
|
function _croot()
|
|
|
|
{
|
|
|
|
local T=$(gettop)
|
|
|
|
if [ "$T" ]; then
|
|
|
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
k=0
|
|
|
|
for c in $(compgen -d ${T}/${cur}); do
|
|
|
|
COMPREPLY[k++]=${c#${T}/}/
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2009-07-30 19:23:21 +02:00
|
|
|
function cproj()
|
|
|
|
{
|
2017-10-20 20:37:33 +02:00
|
|
|
local TOPFILE=build/make/core/envsetup.mk
|
2009-07-30 19:23:21 +02:00
|
|
|
local HERE=$PWD
|
2017-03-23 19:08:58 +01:00
|
|
|
local T=
|
2009-07-30 19:23:21 +02:00
|
|
|
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
|
2016-03-04 05:57:21 +01:00
|
|
|
echo "usage: qpid [[--exact] <process name|pid>"
|
|
|
|
return 255
|
|
|
|
fi
|
2013-07-30 19:23:52 +02:00
|
|
|
|
|
|
|
local EXE="$1"
|
|
|
|
if [ "$EXE" ] ; then
|
2016-03-04 05:57:21 +01:00
|
|
|
qpid | \grep "$prepend$EXE$append"
|
|
|
|
else
|
|
|
|
adb shell ps \
|
|
|
|
| tr -d '\r' \
|
|
|
|
| sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
|
|
|
|
fi
|
2013-07-30 19:23:52 +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
|
|
|
{
|
2016-03-04 05:57:21 +01:00
|
|
|
echo "Getting root...";
|
|
|
|
adb root;
|
|
|
|
adb wait-for-device;
|
2014-10-29 02:00:42 +01:00
|
|
|
|
2016-03-04 05:57:21 +01:00
|
|
|
echo "Remounting root partition read-write...";
|
|
|
|
adb shell mount -w -o remount -t rootfs rootfs;
|
|
|
|
sleep 1;
|
|
|
|
adb wait-for-device;
|
|
|
|
adb shell mkdir -p /cores;
|
|
|
|
adb shell mount -t tmpfs tmpfs /cores;
|
|
|
|
adb shell chmod 0777 /cores;
|
2014-10-29 02:00:42 +01:00
|
|
|
|
2016-03-04 05:57:21 +01:00
|
|
|
echo "Granting SELinux permission to dump in /cores...";
|
|
|
|
adb shell restorecon -R /cores;
|
2014-10-29 02:00:42 +01:00
|
|
|
|
2016-03-04 05:57:21 +01:00
|
|
|
echo "Set core pattern.";
|
|
|
|
adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
|
2014-10-29 02:00:42 +01:00
|
|
|
|
2016-03-04 05:57:21 +01:00
|
|
|
echo "Done."
|
2014-10-29 02:00:42 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2016-03-04 05:57:21 +01:00
|
|
|
local PID=$1;
|
|
|
|
if [ -z "$PID" ]; then
|
|
|
|
printf "Expecting a PID!\n";
|
|
|
|
return;
|
|
|
|
fi;
|
|
|
|
echo "Setting core limit for $PID to infinite...";
|
2016-03-07 22:53:53 +01:00
|
|
|
adb shell /system/bin/ulimit -p $PID -c unlimited
|
2014-10-29 02:00:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# 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()
|
|
|
|
{
|
2016-03-04 05:57:21 +01:00
|
|
|
local PID=$1;
|
2014-10-29 02:00:42 +01:00
|
|
|
|
2016-03-04 05:57:21 +01:00
|
|
|
if [ -z "$PID" ]; then
|
|
|
|
printf "Expecting a PID!\n";
|
|
|
|
return;
|
|
|
|
fi;
|
2014-10-29 02:00:42 +01:00
|
|
|
|
2016-03-04 05:57:21 +01:00
|
|
|
local CORENAME=core.$PID;
|
|
|
|
local COREPATH=/cores/$CORENAME;
|
|
|
|
local SIG=SEGV;
|
2014-10-29 02:00:42 +01:00
|
|
|
|
2016-03-04 05:57:21 +01:00
|
|
|
coredump_enable $1;
|
2014-10-29 02:00:42 +01:00
|
|
|
|
2016-03-04 05:57:21 +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;
|
2014-10-29 02:00:42 +01:00
|
|
|
|
2016-03-04 05:57:21 +01:00
|
|
|
adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
|
|
|
|
echo "Done: core is under $COREPATH on device.";
|
2014-10-29 02:00:42 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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
|
2018-11-16 01:32:14 +01:00
|
|
|
if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -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
|
|
|
}
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
case `uname -s` in
|
|
|
|
Darwin)
|
|
|
|
function sgrep()
|
|
|
|
{
|
2020-03-05 20:34:16 +01:00
|
|
|
find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|hpp|S|java|xml|sh|mk|aidl|vts|proto)' \
|
2015-09-23 00:13:48 +02:00
|
|
|
-exec grep --color -n "$@" {} +
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
function sgrep()
|
|
|
|
{
|
2020-03-05 20:34:16 +01:00
|
|
|
find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|hpp\|S\|java\|xml\|sh\|mk\|aidl\|vts\|proto\)' \
|
2015-09-23 00:13:48 +02:00
|
|
|
-exec 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()
|
|
|
|
{
|
2015-09-23 00:13:48 +02:00
|
|
|
find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
|
|
|
|
-exec grep --color -n "$@" {} +
|
2014-04-07 19:57:38 +02:00
|
|
|
}
|
|
|
|
|
2019-10-25 12:35:15 +02:00
|
|
|
function gogrep()
|
|
|
|
{
|
|
|
|
find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.go" \
|
|
|
|
-exec grep --color -n "$@" {} +
|
|
|
|
}
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
function jgrep()
|
|
|
|
{
|
2015-09-23 00:13:48 +02:00
|
|
|
find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
|
|
|
|
-exec grep --color -n "$@" {} +
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function cgrep()
|
|
|
|
{
|
2015-09-23 00:13:48 +02: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' \) \
|
|
|
|
-exec grep --color -n "$@" {} +
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function resgrep()
|
|
|
|
{
|
2017-03-23 19:08:58 +01:00
|
|
|
local dir
|
2015-09-23 00:13:48 +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' -exec grep --color -n "$@" {} +
|
|
|
|
done
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
2013-03-08 19:20:47 +01:00
|
|
|
function mangrep()
|
|
|
|
{
|
2015-09-23 00:13:48 +02:00
|
|
|
find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
|
|
|
|
-exec grep --color -n "$@" {} +
|
2013-03-08 19:20:47 +01:00
|
|
|
}
|
|
|
|
|
2019-08-21 20:51:26 +02:00
|
|
|
function owngrep()
|
|
|
|
{
|
|
|
|
find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'OWNERS' \
|
|
|
|
-exec grep --color -n "$@" {} +
|
|
|
|
}
|
|
|
|
|
2013-05-06 23:11:48 +02:00
|
|
|
function sepgrep()
|
|
|
|
{
|
2015-09-23 00:13:48 +02:00
|
|
|
find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \
|
|
|
|
-exec grep --color -n -r --exclude-dir=\.git "$@" {} +
|
2013-05-06 23:11:48 +02:00
|
|
|
}
|
|
|
|
|
2015-02-26 23:13:46 +01:00
|
|
|
function rcgrep()
|
|
|
|
{
|
2015-09-23 00:13:48 +02:00
|
|
|
find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \
|
|
|
|
-exec grep --color -n "$@" {} +
|
2015-02-26 23:13:46 +01:00
|
|
|
}
|
|
|
|
|
2008-10-21 16:00:00 +02:00
|
|
|
case `uname -s` in
|
|
|
|
Darwin)
|
|
|
|
function mgrep()
|
|
|
|
{
|
2019-10-25 12:35:15 +02:00
|
|
|
find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o \( -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk|.*\.bp)' -o -regex '(.*/)?(build|soong)/.*[^/]*\.go' \) -type f \
|
2015-09-23 00:13:48 +02:00
|
|
|
-exec grep --color -n "$@" {} +
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function treegrep()
|
|
|
|
{
|
2018-11-06 17:25:11 +01:00
|
|
|
find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|hpp|S|java|xml)' \
|
2015-09-23 00:13:48 +02:00
|
|
|
-exec grep --color -n -i "$@" {} +
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
function mgrep()
|
|
|
|
{
|
2019-10-25 12:35:15 +02:00
|
|
|
find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o \( -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk|.*\.bp)' -o -regextype posix-extended -regex '(.*/)?(build|soong)/.*[^/]*\.go' \) -type f \
|
2015-09-23 00:13:48 +02:00
|
|
|
-exec grep --color -n "$@" {} +
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function treegrep()
|
|
|
|
{
|
2018-11-06 17:25:11 +01:00
|
|
|
find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|hpp|S|java|xml)' -type f \
|
2015-09-23 00:13:48 +02:00
|
|
|
-exec grep --color -n -i "$@" {} +
|
2008-10-21 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
function getprebuilt
|
|
|
|
{
|
|
|
|
get_abs_build_var ANDROID_PREBUILTS
|
|
|
|
}
|
|
|
|
|
|
|
|
function tracedmdump()
|
|
|
|
{
|
2017-03-23 19:08:58 +01:00
|
|
|
local T=$(gettop)
|
2008-10-21 16:00:00 +02:00
|
|
|
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
|
2017-03-23 19:08:58 +01:00
|
|
|
local T=$(gettop)
|
2008-10-21 16:00:00 +02:00
|
|
|
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()
|
|
|
|
{
|
2017-03-23 19:08:58 +01:00
|
|
|
local T=$(gettop)
|
2008-12-18 03:03:49 +01:00
|
|
|
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
|
2017-03-23 19:08:58 +01:00
|
|
|
local T=$(gettop)
|
|
|
|
local FILELIST
|
2015-10-01 05:28:54 +02:00
|
|
|
if [ ! "$OUT_DIR" = "" ]; then
|
|
|
|
mkdir -p $OUT_DIR
|
|
|
|
FILELIST=$OUT_DIR/filelist
|
|
|
|
else
|
|
|
|
FILELIST=$T/filelist
|
|
|
|
fi
|
|
|
|
if [[ ! -f $FILELIST ]]; then
|
2009-03-04 04:28:42 +01:00
|
|
|
echo -n "Creating index..."
|
2015-10-01 05:28:54 +02: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
|
2015-10-01 05:28:54 +02:00
|
|
|
lines=($(\grep "$1" $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
|
2019-10-03 12:02:46 +02:00
|
|
|
pathname=${lines[@]:$(($choice-1)):1}
|
2009-03-04 04:28:42 +01:00
|
|
|
done
|
|
|
|
else
|
2019-10-03 12:02:46 +02:00
|
|
|
pathname=${lines[@]:0:1}
|
2009-03-04 04:28:42 +01:00
|
|
|
fi
|
2012-12-13 19:52:07 +01:00
|
|
|
\cd $T/$pathname
|
2009-03-04 04:28:42 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 19:11:40 +01:00
|
|
|
# Update module-info.json in out.
|
|
|
|
function refreshmod() {
|
|
|
|
if [ ! "$ANDROID_PRODUCT_OUT" ]; then
|
|
|
|
echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2
|
|
|
|
|
|
|
|
# for the output of the next command
|
|
|
|
mkdir -p $ANDROID_PRODUCT_OUT || return 1
|
|
|
|
|
|
|
|
# Note, can't use absolute path because of the way make works.
|
|
|
|
m out/target/product/$(get_build_var TARGET_DEVICE)/module-info.json \
|
|
|
|
> $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
# List all modules for the current device, as cached in module-info.json. If any build change is
|
|
|
|
# made and it should be reflected in the output, you should run 'refreshmod' first.
|
|
|
|
function allmod() {
|
|
|
|
if [ ! "$ANDROID_PRODUCT_OUT" ]; then
|
|
|
|
echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
|
|
|
|
echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
|
|
|
|
refreshmod || return 1
|
|
|
|
fi
|
|
|
|
|
2020-01-12 03:12:17 +01:00
|
|
|
python -c "import json; print('\n'.join(sorted(json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')).keys())))"
|
2018-12-06 19:11:40 +01:00
|
|
|
}
|
|
|
|
|
2019-01-24 23:34:23 +01:00
|
|
|
# Get the path of a specific module in the android tree, as cached in module-info.json. If any build change
|
2018-12-06 19:11:40 +01:00
|
|
|
# is made, and it should be reflected in the output, you should run 'refreshmod' first.
|
2019-01-24 23:34:23 +01:00
|
|
|
function pathmod() {
|
2018-12-06 19:11:40 +01:00
|
|
|
if [ ! "$ANDROID_PRODUCT_OUT" ]; then
|
|
|
|
echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $# -ne 1 ]]; then
|
2019-01-24 23:34:23 +01:00
|
|
|
echo "usage: pathmod <module>" >&2
|
2018-12-06 19:11:40 +01:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then
|
|
|
|
echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2
|
|
|
|
refreshmod || return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
local relpath=$(python -c "import json, os
|
|
|
|
module = '$1'
|
|
|
|
module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json'))
|
|
|
|
if module not in module_info:
|
|
|
|
exit(1)
|
2020-01-12 03:12:17 +01:00
|
|
|
print(module_info[module]['path'][0])" 2>/dev/null)
|
2018-12-06 19:11:40 +01:00
|
|
|
|
|
|
|
if [ -z "$relpath" ]; then
|
|
|
|
echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2
|
|
|
|
return 1
|
|
|
|
else
|
2019-01-24 23:34:23 +01:00
|
|
|
echo "$ANDROID_BUILD_TOP/$relpath"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Go to a specific module in the android tree, as cached in module-info.json. If any build change
|
|
|
|
# is made, and it should be reflected in the output, you should run 'refreshmod' first.
|
|
|
|
function gomod() {
|
|
|
|
if [[ $# -ne 1 ]]; then
|
|
|
|
echo "usage: gomod <module>" >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
local path="$(pathmod $@)"
|
|
|
|
if [ -z "$path" ]; then
|
|
|
|
return 1
|
2018-12-06 19:11:40 +01:00
|
|
|
fi
|
2019-01-24 23:34:23 +01:00
|
|
|
cd $path
|
2018-12-06 19:11:40 +01:00
|
|
|
}
|
|
|
|
|
2018-12-11 18:06:00 +01:00
|
|
|
function _complete_android_module_names() {
|
2018-12-06 19:11:40 +01:00
|
|
|
local word=${COMP_WORDS[COMP_CWORD]}
|
|
|
|
COMPREPLY=( $(allmod | grep -E "^$word") )
|
|
|
|
}
|
|
|
|
|
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
|
2015-05-15 16:12:53 +02:00
|
|
|
echo $'\E'"[0;31mFAILURE\e[00m"
|
2013-03-09 02:34:02 +01:00
|
|
|
else
|
2015-05-15 16:12:53 +02:00
|
|
|
echo $'\E'"[0;32mSUCCESS\e[00m"
|
2013-03-09 02:34:02 +01:00
|
|
|
fi
|
|
|
|
return $retval
|
2013-03-09 00:15:06 +01:00
|
|
|
}
|
|
|
|
|
2014-08-25 07:14:19 +02:00
|
|
|
function get_make_command()
|
|
|
|
{
|
2017-07-13 01:14:50 +02:00
|
|
|
# If we're in the top of an Android tree, use soong_ui.bash instead of make
|
|
|
|
if [ -f build/soong/soong_ui.bash ]; then
|
2017-07-28 22:00:13 +02:00
|
|
|
# Always use the real make if -C is passed in
|
|
|
|
for arg in "$@"; do
|
|
|
|
if [[ $arg == -C* ]]; then
|
|
|
|
echo command make
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
2017-07-13 01:14:50 +02:00
|
|
|
echo build/soong/soong_ui.bash --make-mode
|
|
|
|
else
|
|
|
|
echo command make
|
|
|
|
fi
|
2014-08-25 07:14:19 +02:00
|
|
|
}
|
|
|
|
|
2017-07-13 01:14:50 +02:00
|
|
|
function _wrap_build()
|
2014-06-18 23:55:58 +02:00
|
|
|
{
|
2019-01-31 22:25:31 +01:00
|
|
|
if [[ "${ANDROID_QUIET_BUILD:-}" == true ]]; then
|
|
|
|
"$@"
|
|
|
|
return $?
|
|
|
|
fi
|
2014-06-18 23:55:58 +02:00
|
|
|
local start_time=$(date +"%s")
|
2017-07-13 01:14:50 +02:00
|
|
|
"$@"
|
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))
|
2014-06-23 23:05:06 +02:00
|
|
|
local ncolors=$(tput colors 2>/dev/null)
|
|
|
|
if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
|
2015-05-15 16:12:53 +02:00
|
|
|
color_failed=$'\E'"[0;31m"
|
|
|
|
color_success=$'\E'"[0;32m"
|
|
|
|
color_reset=$'\E'"[00m"
|
2014-06-23 23:05:06 +02:00
|
|
|
else
|
|
|
|
color_failed=""
|
|
|
|
color_success=""
|
|
|
|
color_reset=""
|
|
|
|
fi
|
2014-06-18 23:55:58 +02:00
|
|
|
echo
|
|
|
|
if [ $ret -eq 0 ] ; then
|
2017-07-13 01:14:50 +02:00
|
|
|
echo -n "${color_success}#### build completed successfully "
|
2014-06-18 23:55:58 +02:00
|
|
|
else
|
2017-07-13 01:14:50 +02:00
|
|
|
echo -n "${color_failed}#### failed to build some targets "
|
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
|
2015-05-15 16:12:53 +02:00
|
|
|
echo " ####${color_reset}"
|
2014-06-18 23:55:58 +02:00
|
|
|
echo
|
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|
2019-06-21 01:40:33 +02:00
|
|
|
function _trigger_build()
|
|
|
|
(
|
|
|
|
local -r bc="$1"; shift
|
|
|
|
if T="$(gettop)"; then
|
|
|
|
_wrap_build "$T/build/soong/soong_ui.bash" --build-mode --${bc} --dir="$(pwd)" "$@"
|
|
|
|
else
|
|
|
|
echo "Couldn't locate the top of the tree. Try setting TOP."
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
|
|
|
|
function m()
|
|
|
|
(
|
|
|
|
_trigger_build "all-modules" "$@"
|
|
|
|
)
|
|
|
|
|
|
|
|
function mm()
|
|
|
|
(
|
|
|
|
_trigger_build "modules-in-a-dir-no-deps" "$@"
|
|
|
|
)
|
|
|
|
|
|
|
|
function mmm()
|
|
|
|
(
|
|
|
|
_trigger_build "modules-in-dirs-no-deps" "$@"
|
|
|
|
)
|
|
|
|
|
|
|
|
function mma()
|
|
|
|
(
|
|
|
|
_trigger_build "modules-in-a-dir" "$@"
|
|
|
|
)
|
|
|
|
|
|
|
|
function mmma()
|
|
|
|
(
|
|
|
|
_trigger_build "modules-in-dirs" "$@"
|
|
|
|
)
|
|
|
|
|
2017-07-13 01:14:50 +02:00
|
|
|
function make()
|
|
|
|
{
|
2017-07-28 22:00:13 +02:00
|
|
|
_wrap_build $(get_make_command "$@") "$@"
|
2017-07-13 01:14:50 +02:00
|
|
|
}
|
|
|
|
|
2015-09-30 23:10:48 +02:00
|
|
|
function provision()
|
|
|
|
{
|
|
|
|
if [ ! "$ANDROID_PRODUCT_OUT" ]; then
|
|
|
|
echo "Couldn't locate output files. Try running 'lunch' first." >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then
|
|
|
|
echo "There is no provisioning script for the device." >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if user really wants to do this.
|
|
|
|
if [ "$1" = "--no-confirmation" ]; then
|
|
|
|
shift 1
|
|
|
|
else
|
|
|
|
echo "This action will reflash your device."
|
|
|
|
echo ""
|
|
|
|
echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED."
|
|
|
|
echo ""
|
2015-11-10 19:41:15 +01:00
|
|
|
echo -n "Are you sure you want to do this (yes/no)? "
|
|
|
|
read
|
2015-09-30 23:10:48 +02:00
|
|
|
if [[ "${REPLY}" != "yes" ]] ; then
|
|
|
|
echo "Not taking any action. Exiting." >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
"$ANDROID_PRODUCT_OUT/provision-device" "$@"
|
|
|
|
}
|
|
|
|
|
2018-06-19 10:34:41 +02:00
|
|
|
# Zsh needs bashcompinit called to support bash-style completion.
|
2018-10-15 18:15:12 +02:00
|
|
|
function enable_zsh_completion() {
|
|
|
|
# Don't override user's options if bash-style completion is already enabled.
|
|
|
|
if ! declare -f complete >/dev/null; then
|
|
|
|
autoload -U compinit && compinit
|
|
|
|
autoload -U bashcompinit && bashcompinit
|
|
|
|
fi
|
2018-06-19 10:34:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function validate_current_shell() {
|
|
|
|
local current_sh="$(ps -o command -p $$)"
|
|
|
|
case "$current_sh" in
|
2011-06-21 01:03:14 +02:00
|
|
|
*bash*)
|
2018-06-19 10:34:41 +02:00
|
|
|
function check_type() { type -t "$1"; }
|
2011-06-21 01:03:14 +02:00
|
|
|
;;
|
2018-06-19 10:34:41 +02:00
|
|
|
*zsh*)
|
|
|
|
function check_type() { type "$1"; }
|
2018-10-15 18:15:12 +02:00
|
|
|
enable_zsh_completion ;;
|
2011-06-21 01:03:14 +02:00
|
|
|
*)
|
2018-06-19 10:34:41 +02:00
|
|
|
echo -e "WARNING: Only bash and zsh are supported.\nUse of other shell would lead to erroneous results."
|
2011-06-21 01:03:14 +02:00
|
|
|
;;
|
|
|
|
esac
|
2018-06-19 10:34:41 +02:00
|
|
|
}
|
2008-12-18 03:03:49 +01:00
|
|
|
|
|
|
|
# Execute the contents of any vendorsetup.sh files we can find.
|
2019-02-13 00:52:36 +01:00
|
|
|
# Unless we find an allowed-vendorsetup_sh-files file, in which case we'll only
|
|
|
|
# load those.
|
|
|
|
#
|
|
|
|
# This allows loading only approved vendorsetup.sh files
|
2018-06-19 10:34:41 +02:00
|
|
|
function source_vendorsetup() {
|
2019-07-25 10:54:27 +02:00
|
|
|
unset VENDOR_PYTHONPATH
|
2019-02-13 00:52:36 +01:00
|
|
|
allowed=
|
|
|
|
for f in $(find -L device vendor product -maxdepth 4 -name 'allowed-vendorsetup_sh-files' 2>/dev/null | sort); do
|
|
|
|
if [ -n "$allowed" ]; then
|
|
|
|
echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:"
|
|
|
|
echo " $allowed"
|
|
|
|
echo " $f"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
allowed="$f"
|
|
|
|
done
|
|
|
|
|
|
|
|
allowed_files=
|
|
|
|
[ -n "$allowed" ] && allowed_files=$(cat "$allowed")
|
2018-06-19 10:34:41 +02:00
|
|
|
for dir in device vendor product; do
|
|
|
|
for f in $(test -d $dir && \
|
|
|
|
find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do
|
2019-02-13 00:52:36 +01:00
|
|
|
|
|
|
|
if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then
|
|
|
|
echo "including $f"; . "$f"
|
|
|
|
else
|
|
|
|
echo "ignoring $f, not in $allowed"
|
|
|
|
fi
|
2018-06-19 10:34:41 +02:00
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
2011-07-15 20:07:06 +02:00
|
|
|
|
2018-06-19 10:34:41 +02:00
|
|
|
validate_current_shell
|
|
|
|
source_vendorsetup
|
2011-07-15 20:07:06 +02:00
|
|
|
addcompletions
|