From 0257ebe4ac7907d0293371cc6a50a0ec0a55f61c Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Wed, 9 Apr 2014 18:57:42 +0000 Subject: enable developers to provide their own android toolchain R=halcanary@google.com, scroggo@google.com Author: djsollen@google.com Review URL: https://codereview.chromium.org/227673003 git-svn-id: http://skia.googlecode.com/svn/trunk@14113 2bbb7eff-a529-9590-31e7-b0007b416f81 --- platform_tools/android/bin/android_setup.sh | 69 +--------------- .../android/bin/utils/setup_toolchain.sh | 96 ++++++++++++++++++++++ 2 files changed, 98 insertions(+), 67 deletions(-) create mode 100755 platform_tools/android/bin/utils/setup_toolchain.sh (limited to 'platform_tools') diff --git a/platform_tools/android/bin/android_setup.sh b/platform_tools/android/bin/android_setup.sh index 3063a1136a..9018de1acf 100755 --- a/platform_tools/android/bin/android_setup.sh +++ b/platform_tools/android/bin/android_setup.sh @@ -64,72 +64,6 @@ if [ ! -d "$THIRD_PARTY_EXTERNAL_DIR" ]; then exit 1; fi -# Helper function to determine and download the toolchain that we will be using. -setup_toolchain() { - API_LEVEL=14 - NDK_REV=${NDK_REV-8e} - ANDROID_ARCH=${ANDROID_ARCH-arm} - - TOOLCHAIN_DIR=${SCRIPT_DIR}/../toolchains - if [ $(uname) == "Darwin" ]; then - verbose "Using Mac toolchain." - TOOLCHAIN_TYPE=ndk-r$NDK_REV-$ANDROID_ARCH-mac_v$API_LEVEL - else - verbose "Using Linux toolchain." - TOOLCHAIN_TYPE=ndk-r$NDK_REV-$ANDROID_ARCH-linux_v$API_LEVEL - fi - exportVar ANDROID_TOOLCHAIN "${TOOLCHAIN_DIR}/${TOOLCHAIN_TYPE}/bin" - - # if the toolchain doesn't exist on your machine then we need to fetch it - if [ ! -d "$ANDROID_TOOLCHAIN" ]; then - mkdir -p $TOOLCHAIN_DIR - # enter the toolchain directory then download, unpack, and remove the tarball - pushd $TOOLCHAIN_DIR - TARBALL=ndk-r$NDK_REV-v$API_LEVEL.tgz - - ${SCRIPT_DIR}/download_toolchains.py \ - http://chromium-skia-gm.commondatastorage.googleapis.com/android-toolchains/$TARBALL \ - $TOOLCHAIN_DIR/$TARBALL - tar -xzf $TARBALL $TOOLCHAIN_TYPE - rm $TARBALL - popd - fi - - if [ ! -d "$ANDROID_TOOLCHAIN" ]; then - echo "ERROR: unable to download/setup the required toolchain (${TOOLCHAIN_TYPE})" - return 1; - fi - - verbose "Targeting NDK API $API_LEVEL for use on Android 4.0 (NDK Revision $NDK_REV) and above" - - GCC=$(command ls $ANDROID_TOOLCHAIN/*-gcc | head -n1) - if [ -z "$GCC" ]; then - echo "ERROR: Could not find Android cross-compiler in: $ANDROID_TOOLCHAIN" - return 1 - fi - - # Remove the '-gcc' at the end to get the full toolchain prefix - ANDROID_TOOLCHAIN_PREFIX=${GCC%%-gcc} - - CCACHE=${ANDROID_MAKE_CCACHE-$(which ccache || true)} - - exportVar CC "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-gcc" - exportVar CXX "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-g++" - exportVar LINK "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-gcc" - - exportVar AR "$ANDROID_TOOLCHAIN_PREFIX-ar" - exportVar RANLIB "$ANDROID_TOOLCHAIN_PREFIX-ranlib" - exportVar OBJCOPY "$ANDROID_TOOLCHAIN_PREFIX-objcopy" - exportVar STRIP "$ANDROID_TOOLCHAIN_PREFIX-strip" - - # 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. - # This is required to build using ninja on a Mac. - ln -sf $ANDROID_TOOLCHAIN_PREFIX-nm $ANDROID_TOOLCHAIN/nm - ln -sf $ANDROID_TOOLCHAIN_PREFIX-readelf $ANDROID_TOOLCHAIN/readelf - exportVar PATH $ANDROID_TOOLCHAIN:$PATH -} - # Helper function to configure the GYP defines to the appropriate values # based on the target device. setup_device() { @@ -208,7 +142,8 @@ setup_device() { verbose "The build is targeting the device: $TARGET_DEVICE" exportVar DEVICE_ID $TARGET_DEVICE - setup_toolchain + # setup the appropriate cross compiling toolchains + source $SCRIPT_DIR/utils/setup_toolchain.sh DEFINES="${DEFINES} android_toolchain=${TOOLCHAIN_TYPE}" diff --git a/platform_tools/android/bin/utils/setup_toolchain.sh b/platform_tools/android/bin/utils/setup_toolchain.sh new file mode 100755 index 0000000000..1e9061698a --- /dev/null +++ b/platform_tools/android/bin/utils/setup_toolchain.sh @@ -0,0 +1,96 @@ +#!/bin/bash +# +# setup_toolchain.sh: Sets toolchain environment variables used by other scripts. + +# Fail-fast if anything in the script fails. +set -e + +# check that the preconditions for this script are met +if [ $(type -t verbose) != 'function' ]; then + echo "ERROR: The verbose function is expected to be defined" + return 1 +fi + +if [ $(type -t exportVar) != 'function' ]; then + echo "ERROR: The exportVar function is expected to be defined" + return 1 +fi + +if [ $(type -t absPath) != 'function' ]; then + echo "ERROR: The absPath function is expected to be defined" + return 1 +fi + +if [ -z "$SCRIPT_DIR" ]; then + echo "ERROR: The SCRIPT_DIR variable is expected to be defined" + return 1 +fi + +function default_toolchain() { + API_LEVEL=14 + NDK_REV=${NDK_REV-8e} + ANDROID_ARCH=${ANDROID_ARCH-arm} + + TOOLCHAIN_DIR=${SCRIPT_DIR}/../toolchains + if [ $(uname) == "Darwin" ]; then + verbose "Using Mac toolchain." + TOOLCHAIN_TYPE=ndk-r$NDK_REV-$ANDROID_ARCH-mac_v$API_LEVEL + else + verbose "Using Linux toolchain." + TOOLCHAIN_TYPE=ndk-r$NDK_REV-$ANDROID_ARCH-linux_v$API_LEVEL + fi + exportVar ANDROID_TOOLCHAIN "${TOOLCHAIN_DIR}/${TOOLCHAIN_TYPE}/bin" + + # if the toolchain doesn't exist on your machine then we need to fetch it + if [ ! -d "$ANDROID_TOOLCHAIN" ]; then + mkdir -p $TOOLCHAIN_DIR + # enter the toolchain directory then download, unpack, and remove the tarball + pushd $TOOLCHAIN_DIR + TARBALL=ndk-r$NDK_REV-v$API_LEVEL.tgz + + ${SCRIPT_DIR}/download_toolchains.py \ + http://chromium-skia-gm.commondatastorage.googleapis.com/android-toolchains/$TARBALL \ + $TOOLCHAIN_DIR/$TARBALL + tar -xzf $TARBALL $TOOLCHAIN_TYPE + rm $TARBALL + popd + fi + + verbose "Targeting NDK API $API_LEVEL for use on Android 4.0 (NDK Revision $NDK_REV) and above" +} + +#check to see if the toolchain has been defined and if not setup the default toolchain +if [ -z "$ANDROID_TOOLCHAIN" ]; then + default_toolchain + if [ ! -d "$ANDROID_TOOLCHAIN" ]; then + echo "ERROR: unable to download/setup the required toolchain (${ANDROID_TOOLCHAIN})" + return 1; + fi +fi + +GCC=$(command ls $ANDROID_TOOLCHAIN/*-gcc | head -n1) +if [ -z "$GCC" ]; then + echo "ERROR: Could not find Android cross-compiler in: $ANDROID_TOOLCHAIN" + return 1 +fi + +# Remove the '-gcc' at the end to get the full toolchain prefix +ANDROID_TOOLCHAIN_PREFIX=${GCC%%-gcc} + +CCACHE=${ANDROID_MAKE_CCACHE-$(which ccache || true)} + +exportVar CC "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-gcc" +exportVar CXX "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-g++" +exportVar LINK "$CCACHE $ANDROID_TOOLCHAIN_PREFIX-gcc" + +exportVar AR "$ANDROID_TOOLCHAIN_PREFIX-ar" +exportVar RANLIB "$ANDROID_TOOLCHAIN_PREFIX-ranlib" +exportVar OBJCOPY "$ANDROID_TOOLCHAIN_PREFIX-objcopy" +exportVar STRIP "$ANDROID_TOOLCHAIN_PREFIX-strip" + +# 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. +# This is required to build using ninja on a Mac. +ln -sf $ANDROID_TOOLCHAIN_PREFIX-nm $ANDROID_TOOLCHAIN/nm +ln -sf $ANDROID_TOOLCHAIN_PREFIX-readelf $ANDROID_TOOLCHAIN/readelf +exportVar PATH $ANDROID_TOOLCHAIN:$PATH -- cgit v1.2.3