github.com/rsc/go@v0.0.0-20150416155037-e040fd465409/src/androidtest.bash (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2014 The Go Authors.  All rights reserved.
     3  # Use of this source code is governed by a BSD-style
     4  # license that can be found in the LICENSE file.
     5  
     6  # For testing Android.
     7  # The compiler runs locally, then a copy of the GOROOT is pushed to a
     8  # target device using adb, and the tests are run there.
     9  
    10  set -e
    11  ulimit -c 0 # no core files
    12  
    13  if [ ! -f make.bash ]; then
    14  	echo 'androidtest.bash must be run from $GOROOT/src' 1>&2
    15  	exit 1
    16  fi
    17  
    18  if [ -z $GOOS ]; then
    19  	export GOOS=android
    20  fi
    21  if [ "$GOOS" != "android" ]; then
    22  	echo "androidtest.bash requires GOOS=android, got GOOS=$GOOS" 1>&2
    23  	exit 1
    24  fi
    25  
    26  export CGO_ENABLED=1
    27  
    28  # Run the build for the host bootstrap, so we can build go_android_exec.
    29  # Also lets us fail early before the (slow) adb push if the build is broken.
    30  ./make.bash
    31  export GOROOT=$(dirname $(pwd))
    32  export PATH=$GOROOT/bin:$PATH
    33  GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go build \
    34  	-o ../bin/go_android_${GOARCH}_exec \
    35  	../misc/android/go_android_exec.go
    36  
    37  # Push GOROOT to target device.
    38  #
    39  # The adb sync command will sync either the /system or /data
    40  # directories of an android device from a similar directory
    41  # on the host. We copy the files required for running tests under
    42  # /data/local/tmp/goroot. The adb sync command does not follow
    43  # symlinks so we have to copy.
    44  export ANDROID_PRODUCT_OUT=/tmp/androidtest-$$
    45  FAKE_GOROOT=$ANDROID_PRODUCT_OUT/data/local/tmp/goroot
    46  mkdir -p $FAKE_GOROOT
    47  mkdir -p $FAKE_GOROOT/pkg
    48  cp -a "${GOROOT}/src" "${FAKE_GOROOT}/"
    49  cp -a "${GOROOT}/test" "${FAKE_GOROOT}/"
    50  cp -a "${GOROOT}/lib" "${FAKE_GOROOT}/"
    51  cp -a "${GOROOT}/pkg/android_$GOARCH" "${FAKE_GOROOT}/pkg/"
    52  echo '# Syncing test files to android device'
    53  time adb sync data &> /dev/null
    54  echo ''
    55  rm -rf "$ANDROID_PRODUCT_OUT"
    56  
    57  # Run standard build and tests.
    58  ./all.bash --no-clean