github.com/golang-haiku/go-1.4.3@v0.0.0-20190609233734-1f5ae41cc308/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 'nacl.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. So we fake one with symlinks to push the GOROOT
    42  # into a subdirectory of /data.
    43  export ANDROID_PRODUCT_OUT=/tmp/androidtest-$$
    44  FAKE_GOROOT=$ANDROID_PRODUCT_OUT/data/local/tmp/goroot
    45  mkdir -p $FAKE_GOROOT
    46  ln -s $GOROOT/src $FAKE_GOROOT/src
    47  ln -s $GOROOT/test $FAKE_GOROOT/test
    48  ln -s $GOROOT/lib $FAKE_GOROOT/lib
    49  echo '# Syncing test files to android device'
    50  time adb sync data &> /dev/null
    51  echo ''
    52  rm -rf "$ANDROID_PRODUCT_OUT"
    53  
    54  # Run standard build and tests.
    55  ./all.bash --no-clean