hack hack hack

Edit down the android scripts a bit.
  - set -e
  - detect ccache by default
  - -t for BUILDTYPE

I figure the -t changes are going to break some bots.

BUG=skia:
R=djsollen@google.com, mtklein@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/223613004

git-svn-id: http://skia.googlecode.com/svn/trunk@14061 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-04-04 16:26:42 +00:00
parent a8d95f899b
commit a13767579d
3 changed files with 80 additions and 155 deletions

View File

@ -1,23 +1,18 @@
#!/bin/bash #!/bin/bash
# Fail-fast if anything in the script fails.
set -e
# Remove any existing .android_config file before running android_setup. If we # Remove any existing .android_config file before running android_setup. If we
# did not remove this now then we would build for whatever device type was # did not remove this now then we would build for whatever device type was
# listed in the .android_config instead of the default device type. # listed in the .android_config instead of the default device type.
rm -f .android_config rm -f .android_config
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
source $SCRIPT_DIR/android_setup.sh source $SCRIPT_DIR/android_setup.sh
# Fail-fast if anything in the script fails.
# Don't do this until "source android_setup.sh" is done; see
# https://codereview.chromium.org/223943002 for discussion.
set -e
GYP_GENERATORS=ninja-android ./gyp_skia GYP_GENERATORS=ninja-android ./gyp_skia
OUT=$SKIA_OUT/${BUILDTYPE-Debug} # Defaults to Debug if BUILDTYPE isn't set. ninja -C $SKIA_OUT/$BUILDTYPE ${APP_ARGS[@]}
ninja -C $OUT ${APP_ARGS[@]}
ln -sf lib $OUT/lib.target # android_run_skia looks in lib.target; ninja writes to lib.
# TODO(mtklein): change android_run_skia
# Write the device id into the .android_config file. This tells # Write the device id into the .android_config file. This tells
# android_run_skia the last build we completed. # android_run_skia the last build we completed.

View File

@ -7,41 +7,28 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $SCRIPT_DIR/android_setup.sh source $SCRIPT_DIR/android_setup.sh
source $SCRIPT_DIR/utils/setup_adb.sh source $SCRIPT_DIR/utils/setup_adb.sh
configuration="Debug" if [ ! -f "${SKIA_OUT}/$BUILDTYPE/lib/lib${APP_ARGS[0]}.so" ];
for arg in ${APP_ARGS[@]}
do
if [[ "${arg}" == "--release" ]];
then
configuration="Release"
else
runVars=("${runVars[@]}" "${arg}")
fi
shift
done
if [ ! -f "${SKIA_OUT}/${configuration}/lib.target/lib${runVars[0]}.so" ];
then then
echo "Unable to find the ${runVars[0]} library" echo "Unable to find $BUILDTYPE ${APP_ARGS[0]} library"
exit 1 exit 1
fi fi
adb_push_if_needed "${SKIA_OUT}/${configuration}/skia_launcher" /data/local/tmp adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/skia_launcher" /data/local/tmp
if [ -f "${SKIA_OUT}/${configuration}/lib.target/libskia_android.so" ]; then if [ -f "${SKIA_OUT}/$BUILDTYPE/lib/libskia_android.so" ]; then
# Does not exist for builds with static skia. # Does not exist for builds with static skia.
adb_push_if_needed "${SKIA_OUT}/${configuration}/lib.target/libskia_android.so" /data/local/tmp adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/lib/libskia_android.so" /data/local/tmp
fi fi
adb_push_if_needed "${SKIA_OUT}/${configuration}/lib.target/lib${runVars[0]}.so" /data/local/tmp adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/lib/lib${APP_ARGS[0]}.so" /data/local/tmp
STATUS_FILENAME="/data/local/tmp/.skia_tmp_$(date +%s%N)" STATUS_FILENAME="/data/local/tmp/.skia_tmp_$(date +%s%N)"
$ADB ${DEVICE_SERIAL} shell "/data/local/tmp/skia_launcher ${runVars[@]}; echo \$? > ${STATUS_FILENAME}" $ADB ${DEVICE_SERIAL} shell \
"/data/local/tmp/skia_launcher ${APP_ARGS[@]}; echo \$? > ${STATUS_FILENAME}"
if [ -z "$($ADB $DEVICE_SERIAL shell 'if [ -f $STATUS_FILENAME ]; then echo exists; fi')" ]; then if [ -z "$($ADB $DEVICE_SERIAL shell 'if [ -f $STATUS_FILENAME ]; then echo exists; fi')" ]; then
exit 1 exit 1
fi fi
EXIT_CODE=`$ADB ${DEVICE_SERIAL} shell cat ${STATUS_FILENAME}` EXIT_CODE=`$ADB ${DEVICE_SERIAL} shell cat ${STATUS_FILENAME}`
$ADB ${DEVICE_SERIAL} shell rm ${STATUS_FILENAME} $ADB ${DEVICE_SERIAL} shell rm ${STATUS_FILENAME}
echo "EXIT_CODE is [${EXIT_CODE}]" echo "EXIT_CODE is ${EXIT_CODE}"
if [ $'0\r' != "${EXIT_CODE}" ]; then if [ $'0\r' != "${EXIT_CODE}" ]; then
exit 1 exit 1
fi fi

View File

@ -2,37 +2,33 @@
# #
# android_setup.sh: Sets environment variables used by other Android scripts. # android_setup.sh: Sets environment variables used by other Android scripts.
# Parse the arguments for a DEVICE_ID. # Fail-fast if anything in the script fails.
DEVICE_ID="" set -e
DEVICE_SERIAL=""
BUILDTYPE=${BUILDTYPE-Debug}
while (( "$#" )); do while (( "$#" )); do
if [[ $(echo "$1" | grep "^-d$") != "" ]]; if [[ "$1" == "-d" ]]; then
then
DEVICE_ID=$2 DEVICE_ID=$2
shift shift
elif [[ "$1" == "-s" ]]; elif [[ "$1" == "-s" ]]; then
then
if [[ $# -lt 2 ]];
then
echo "ERROR: missing serial number"
exit 1;
fi
DEVICE_SERIAL="-s $2" DEVICE_SERIAL="-s $2"
shift shift
elif [[ $(echo "$1" | grep "^BUILDTYPE=") != "" ]]; elif [[ "$1" == "-t" ]]; then
then BUILDTYPE=$2
BUILDTYPE=${1##BUILDTYPE=} shift
elif [[ "$1" == "--release" ]]; then
BUILDTYPE=Release
else else
APP_ARGS=("${APP_ARGS[@]}" "${1}") APP_ARGS=("${APP_ARGS[@]}" "${1}")
fi fi
shift shift
done done
function verbose { function verbose {
if [[ -n $SKIA_ANDROID_VERBOSE_SETUP ]]; then if [[ -n $VERBOSE ]]; then
echo $@ echo $@
fi fi
} }
function exportVar { function exportVar {
@ -42,25 +38,19 @@ function exportVar {
export $NAME="$VALUE" export $NAME="$VALUE"
} }
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" function absPath {
(cd $1; pwd)
}
SCRIPT_DIR=$(absPath "$(dirname "$BASH_SOURCE[0]}")")
# A valid Android SDK installation is required to build the sample app.
if [ -z "$ANDROID_SDK_ROOT" ]; then if [ -z "$ANDROID_SDK_ROOT" ]; then
ANDROID_TOOL=$(which android 2>/dev/null) if ANDROID_SDK_ROOT="$(dirname $(which android))/.."; then
if [ -z "$ANDROID_TOOL" ]; then exportVar ANDROID_SDK_ROOT $ANDROID_SDK_ROOT
echo "ERROR: Please define ANDROID_SDK_ROOT in your environment to point" else
echo " to a valid Android SDK installation." echo "No ANDROID_SDK_ROOT set and can't auto detect it from location of android binary."
exit 1 exit 1
fi fi
ANDROID_SDK_ROOT=$(cd $(dirname "$ANDROID_TOOL")/.. && pwd)
exportVar ANDROID_SDK_ROOT "$ANDROID_SDK_ROOT"
fi
# ant is required to be installed on your system and in your PATH
which ant &> /dev/null
if [[ "$?" != "0" ]]; then
echo "ERROR: Unable to find ant. Please install it before proceeding."
exit 1
fi fi
# check to see that gclient sync ran successfully # check to see that gclient sync ran successfully
@ -77,50 +67,30 @@ fi
# Helper function to determine and download the toolchain that we will be using. # Helper function to determine and download the toolchain that we will be using.
setup_toolchain() { setup_toolchain() {
API_LEVEL=14 API_LEVEL=14
NDK_REV=${NDK_REV-8e}
if [[ -z "$NDK_REV" ]]; ANDROID_ARCH=${ANDROID_ARCH-arm}
then
NDK_REV="8e"
fi
if [[ -z "$ANDROID_ARCH" ]];
then
ANDROID_ARCH="arm"
fi
TOOLCHAIN_DIR=${SCRIPT_DIR}/../toolchains TOOLCHAIN_DIR=${SCRIPT_DIR}/../toolchains
if [ $(uname) == "Linux" ]; then if [ $(uname) == "Darwin" ]; then
verbose "Using Linux toolchain."
TOOLCHAIN_TYPE=ndk-r$NDK_REV-$ANDROID_ARCH-linux_v$API_LEVEL
elif [ $(uname) == "Darwin" ]; then
verbose "Using Mac toolchain." verbose "Using Mac toolchain."
TOOLCHAIN_TYPE=ndk-r$NDK_REV-$ANDROID_ARCH-mac_v$API_LEVEL TOOLCHAIN_TYPE=ndk-r$NDK_REV-$ANDROID_ARCH-mac_v$API_LEVEL
else else
verbose "Could not automatically determine toolchain! Defaulting to Linux." verbose "Using Linux toolchain."
TOOLCHAIN_TYPE=ndk-r$NDK_REV-$ANDROID_ARCH-linux_v$API_LEVEL TOOLCHAIN_TYPE=ndk-r$NDK_REV-$ANDROID_ARCH-linux_v$API_LEVEL
fi fi
exportVar ANDROID_TOOLCHAIN ${TOOLCHAIN_DIR}/${TOOLCHAIN_TYPE}/bin exportVar ANDROID_TOOLCHAIN "${TOOLCHAIN_DIR}/${TOOLCHAIN_TYPE}/bin"
# if the toolchain doesn't exist on your machine then we need to fetch it # if the toolchain doesn't exist on your machine then we need to fetch it
if [ ! -d "$ANDROID_TOOLCHAIN" ]; then if [ ! -d "$ANDROID_TOOLCHAIN" ]; then
# create the toolchain directory if needed mkdir -p $TOOLCHAIN_DIR
if [ ! -d "$TOOLCHAIN_DIR" ]; then
mkdir $TOOLCHAIN_DIR
fi
# enter the toolchain directory then download, unpack, and remove the tarball # enter the toolchain directory then download, unpack, and remove the tarball
pushd $TOOLCHAIN_DIR pushd $TOOLCHAIN_DIR
TARBALL=ndk-r$NDK_REV-v$API_LEVEL.tgz TARBALL=ndk-r$NDK_REV-v$API_LEVEL.tgz
echo "Downloading $TARBALL ..." ${SCRIPT_DIR}/download_toolchains.py \
${SCRIPT_DIR}/download_toolchains.py http://chromium-skia-gm.commondatastorage.googleapis.com/android-toolchains/$TARBALL $TOOLCHAIN_DIR/$TARBALL http://chromium-skia-gm.commondatastorage.googleapis.com/android-toolchains/$TARBALL \
if [[ "$?" != "0" ]]; then $TOOLCHAIN_DIR/$TARBALL
echo "ERROR: Unable to download toolchain $TARBALL."
exit 1
fi
echo "Untarring $TOOLCHAIN_TYPE from $TARBALL."
tar -xzf $TARBALL $TOOLCHAIN_TYPE tar -xzf $TARBALL $TOOLCHAIN_TYPE
echo "Removing $TARBALL"
rm $TARBALL rm $TARBALL
popd popd
fi fi
@ -130,10 +100,9 @@ setup_toolchain() {
return 1; return 1;
fi fi
verbose "The build is targeting NDK API level $API_LEVEL for use on Android 4.0 (NDK Revision $NDK_REV) and above" verbose "Targeting NDK API $API_LEVEL for use on Android 4.0 (NDK Revision $NDK_REV) and above"
LS="/bin/ls" # Use directly to avoid any 'ls' alias that might be defined. GCC=$(command ls $ANDROID_TOOLCHAIN/*-gcc | head -n1)
GCC=$($LS $ANDROID_TOOLCHAIN/*-gcc | head -n1)
if [ -z "$GCC" ]; then if [ -z "$GCC" ]; then
echo "ERROR: Could not find Android cross-compiler in: $ANDROID_TOOLCHAIN" echo "ERROR: Could not find Android cross-compiler in: $ANDROID_TOOLCHAIN"
return 1 return 1
@ -142,26 +111,23 @@ setup_toolchain() {
# Remove the '-gcc' at the end to get the full toolchain prefix # Remove the '-gcc' at the end to get the full toolchain prefix
ANDROID_TOOLCHAIN_PREFIX=${GCC%%-gcc} ANDROID_TOOLCHAIN_PREFIX=${GCC%%-gcc}
if [[ -z "$ANDROID_MAKE_CCACHE" ]]; then CCACHE=${ANDROID_MAKE_CCACHE-$(which ccache || true)}
export CC="$ANDROID_TOOLCHAIN_PREFIX-gcc"
export CXX="$ANDROID_TOOLCHAIN_PREFIX-g++" exportVar CC "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-gcc"
export LINK="$ANDROID_TOOLCHAIN_PREFIX-gcc" exportVar CXX "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-g++"
else exportVar LINK "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-gcc"
export CC="$ANDROID_MAKE_CCACHE $ANDROID_TOOLCHAIN_PREFIX-gcc"
export CXX="$ANDROID_MAKE_CCACHE $ANDROID_TOOLCHAIN_PREFIX-g++" exportVar AR "$ANDROID_TOOLCHAIN_PREFIX-ar"
export LINK="$ANDROID_MAKE_CCACHE $ANDROID_TOOLCHAIN_PREFIX-gcc" exportVar RANLIB "$ANDROID_TOOLCHAIN_PREFIX-ranlib"
fi exportVar OBJCOPY "$ANDROID_TOOLCHAIN_PREFIX-objcopy"
export AR="$ANDROID_TOOLCHAIN_PREFIX-ar" exportVar STRIP "$ANDROID_TOOLCHAIN_PREFIX-strip"
export RANLIB="$ANDROID_TOOLCHAIN_PREFIX-ranlib"
export OBJCOPY="$ANDROID_TOOLCHAIN_PREFIX-objcopy" # Create symlinks for nm & readelf and add them to the path so that the ninja
export STRIP="$ANDROID_TOOLCHAIN_PREFIX-strip" # build uses them instead of attempting to use the one on the system.
# This is required to build using ninja on a Mac.
# create symlinks for nm & readelf and add them to the path so that the ninja
# build uses them instead of attempting to use the one on the system
ln -sf $ANDROID_TOOLCHAIN_PREFIX-nm $ANDROID_TOOLCHAIN/nm ln -sf $ANDROID_TOOLCHAIN_PREFIX-nm $ANDROID_TOOLCHAIN/nm
ln -sf $ANDROID_TOOLCHAIN_PREFIX-readelf $ANDROID_TOOLCHAIN/readelf ln -sf $ANDROID_TOOLCHAIN_PREFIX-readelf $ANDROID_TOOLCHAIN/readelf
export PATH=$ANDROID_TOOLCHAIN:$PATH exportVar PATH $ANDROID_TOOLCHAIN:$PATH
} }
# Helper function to configure the GYP defines to the appropriate values # Helper function to configure the GYP defines to the appropriate values
@ -170,7 +136,7 @@ setup_device() {
DEFINES="OS=android" DEFINES="OS=android"
DEFINES="${DEFINES} host_os=$(uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/')" DEFINES="${DEFINES} host_os=$(uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/')"
DEFINES="${DEFINES} skia_os=android" DEFINES="${DEFINES} skia_os=android"
DEFINES="${DEFINES} android_base=${SCRIPT_DIR}/.." DEFINES="${DEFINES} android_base=$(absPath ${SCRIPT_DIR}/..)"
if [[ "$GYP_DEFINES" != *skia_shared_lib=* ]]; then if [[ "$GYP_DEFINES" != *skia_shared_lib=* ]]; then
DEFINES="${DEFINES} skia_shared_lib=1" DEFINES="${DEFINES} skia_shared_lib=1"
fi fi
@ -181,10 +147,10 @@ setup_device() {
if [ -z "$TARGET_DEVICE" ]; then if [ -z "$TARGET_DEVICE" ]; then
if [ -f .android_config ]; then if [ -f .android_config ]; then
TARGET_DEVICE=$(cat .android_config) TARGET_DEVICE=$(cat .android_config)
verbose "INFO: no target device was specified so using the device (${TARGET_DEVICE}) from the most recent build" verbose "no target device (-d), using ${TARGET_DEVICE} from most recent build"
else else
TARGET_DEVICE="arm_v7_thumb" TARGET_DEVICE="arm_v7_thumb"
verbose "INFO: no target device type was specified so using the default '${TARGET_DEVICE}'" verbose "no target device (-d), using ${TARGET_DEVICE}"
fi fi
fi fi
@ -207,12 +173,7 @@ setup_device() {
DEFINES="${DEFINES} skia_resource_cache_mb_limit=32" DEFINES="${DEFINES} skia_resource_cache_mb_limit=32"
ANDROID_ARCH="arm" ANDROID_ARCH="arm"
;; ;;
intel_rhb) intel_rhb | razr_i | x86)
DEFINES="${DEFINES} skia_arch_type=x86 skia_arch_width=32"
DEFINES="${DEFINES} skia_resource_cache_mb_limit=32"
ANDROID_ARCH="x86"
;;
razr_i)
DEFINES="${DEFINES} skia_arch_type=x86 skia_arch_width=32" DEFINES="${DEFINES} skia_arch_type=x86 skia_arch_width=32"
DEFINES="${DEFINES} skia_resource_cache_mb_limit=32" DEFINES="${DEFINES} skia_resource_cache_mb_limit=32"
ANDROID_ARCH="x86" ANDROID_ARCH="x86"
@ -238,26 +199,17 @@ setup_device() {
DEFINES="${DEFINES} skia_resource_cache_mb_limit=32" DEFINES="${DEFINES} skia_resource_cache_mb_limit=32"
ANDROID_ARCH="mips" ANDROID_ARCH="mips"
;; ;;
x86)
DEFINES="${DEFINES} skia_arch_type=x86 skia_arch_width=32"
DEFINES="${DEFINES} skia_resource_cache_mb_limit=32"
ANDROID_ARCH="x86"
;;
*) *)
echo -n "ERROR: unknown device specified ($TARGET_DEVICE), valid values: " echo "ERROR: unknown device $TARGET_DEVICE"
echo "nexus_[s,4,7,10] xoom galaxy_nexus razr_i arm arm_thumb arm_v7 arm_v7_thumb x86" exit 1
return 1;
;; ;;
esac esac
verbose "The build is targeting the device: $TARGET_DEVICE" verbose "The build is targeting the device: $TARGET_DEVICE"
export DEVICE_ID="$TARGET_DEVICE" exportVar DEVICE_ID $TARGET_DEVICE
# Set up the toolchain.
setup_toolchain setup_toolchain
if [[ "$?" != "0" ]]; then
return 1
fi
DEFINES="${DEFINES} android_toolchain=${TOOLCHAIN_TYPE}" DEFINES="${DEFINES} android_toolchain=${TOOLCHAIN_TYPE}"
exportVar GYP_DEFINES "$DEFINES $GYP_DEFINES" exportVar GYP_DEFINES "$DEFINES $GYP_DEFINES"
@ -279,7 +231,6 @@ adb_pull_if_needed() {
HOST_DST="${HOST_DST}/$(basename ${ANDROID_SRC})" HOST_DST="${HOST_DST}/$(basename ${ANDROID_SRC})"
fi fi
echo "HOST: $HOST_DST"
if [ -f $HOST_DST ]; if [ -f $HOST_DST ];
then then
@ -291,13 +242,12 @@ adb_pull_if_needed() {
HOST_MD5=`md5sum $HOST_DST` HOST_MD5=`md5sum $HOST_DST`
fi fi
if [ "${ANDROID_MD5:0:32}" != "${HOST_MD5:0:32}" ]; if [ "${ANDROID_MD5:0:32}" != "${HOST_MD5:0:32}" ]; then
then echo -n "$HOST_DST "
$ADB $DEVICE_SERIAL pull $ANDROID_SRC $HOST_DST $ADB $DEVICE_SERIAL pull $ANDROID_SRC $HOST_DST
# else
# echo "md5 match of android [$ANDROID_SRC] and host [$HOST_DST]"
fi fi
else else
echo -n "$HOST_DST "
$ADB $DEVICE_SERIAL pull $ANDROID_SRC $HOST_DST $ADB $DEVICE_SERIAL pull $ANDROID_SRC $HOST_DST
fi fi
} }
@ -318,11 +268,9 @@ adb_push_if_needed() {
ANDROID_DST="${ANDROID_DST}/$(basename ${HOST_SRC})" ANDROID_DST="${ANDROID_DST}/$(basename ${HOST_SRC})"
fi fi
echo "ANDROID: $ANDROID_DST"
ANDROID_LS=`$ADB $DEVICE_SERIAL shell ls -ld $ANDROID_DST` ANDROID_LS=`$ADB $DEVICE_SERIAL shell ls -ld $ANDROID_DST`
if [ "${ANDROID_LS:0:1}" == "-" ]; if [ "${ANDROID_LS:0:1}" == "-" ]; then
then
#get the MD5 for dst and src #get the MD5 for dst and src
ANDROID_MD5=`$ADB $DEVICE_SERIAL shell md5 $ANDROID_DST` ANDROID_MD5=`$ADB $DEVICE_SERIAL shell md5 $ANDROID_DST`
if [ $(uname) == "Darwin" ]; then if [ $(uname) == "Darwin" ]; then
@ -331,19 +279,14 @@ adb_push_if_needed() {
HOST_MD5=`md5sum $HOST_SRC` HOST_MD5=`md5sum $HOST_SRC`
fi fi
if [ "${ANDROID_MD5:0:32}" != "${HOST_MD5:0:32}" ]; if [ "${ANDROID_MD5:0:32}" != "${HOST_MD5:0:32}" ]; then
then echo -n "$ANDROID_DST "
$ADB $DEVICE_SERIAL push $HOST_SRC $ANDROID_DST $ADB $DEVICE_SERIAL push $HOST_SRC $ANDROID_DST
# else
# echo "md5 match of android [${ANDROID_DST}] and host [${HOST_SRC}]"
fi fi
else else
echo -n "$ANDROID_DST "
$ADB $DEVICE_SERIAL push $HOST_SRC $ANDROID_DST $ADB $DEVICE_SERIAL push $HOST_SRC $ANDROID_DST
fi fi
} }
# Set up the device.
setup_device "${DEVICE_ID}" setup_device "${DEVICE_ID}"
if [[ "$?" != "0" ]]; then
exit 1
fi