Home | History | Annotate | Download | only in src
      1 #!/usr/bin/env bash
      2 # Copyright 2015 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 darwin/arm{,64} on iOS.
      7 
      8 set -e
      9 ulimit -c 0 # no core files
     10 
     11 if [ ! -f make.bash ]; then
     12 	echo 'iostest.bash must be run from $GOROOT/src' 1>&2
     13 	exit 1
     14 fi
     15 
     16 if [ -z $GOOS ]; then
     17 	export GOOS=darwin
     18 fi
     19 if [ "$GOOS" != "darwin" ]; then
     20 	echo "iostest.bash requires GOOS=darwin, got GOOS=$GOOS" 1>&2
     21 	exit 1
     22 fi
     23 if [ "$GOARCH" != "arm" ] && [ "$GOARCH" != "arm64" ]; then
     24 	echo "iostest.bash requires GOARCH=arm or GOARCH=arm64, got GOARCH=$GOARCH" 1>&2
     25 	exit 1
     26 fi
     27 if [ "$GOARCH" = "arm" ]; then
     28 	export GOARM=7
     29 fi
     30 
     31 if [ "$1" = "-restart" ]; then
     32 	# Reboot to make sure previous runs do not interfere with the current run.
     33 	# It is reasonably easy for a bad program leave an iOS device in an
     34 	# almost unusable state.
     35 	IDEVARGS=
     36 	if [ -n "$GOIOS_DEVICE_ID" ]; then
     37 		IDEVARGS="-u $GOIOS_DEVICE_ID"
     38 	fi
     39 	idevicediagnostics $IDEVARGS restart
     40 	# Initial sleep to make sure we are restarting before we start polling.
     41 	sleep 30
     42 	# Poll until the device has restarted.
     43 	until idevicediagnostics $IDEVARGS diagnostics; do
     44 		# TODO(crawshaw): replace with a test app using go_darwin_arm_exec.
     45 		echo "waiting for idevice to come online"
     46 		sleep 10
     47 	done
     48 	# Diagnostics are reported during boot before the device can start an
     49 	# app. Wait a little longer before trying to use the device.
     50 	sleep 30
     51 fi
     52 
     53 unset GOBIN
     54 export GOROOT=$(dirname $(pwd))
     55 export PATH=$GOROOT/bin:$PATH
     56 export CGO_ENABLED=1
     57 export CC_FOR_TARGET=$GOROOT/misc/ios/clangwrap.sh
     58 
     59 # Run the build for the host bootstrap, so we can build go_darwin_arm_exec.
     60 # Also lets us fail early before the (slow) ios-deploy if the build is broken.
     61 ./make.bash
     62 
     63 GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go build \
     64 	-o ../bin/go_darwin_${GOARCH}_exec \
     65 	../misc/ios/go_darwin_arm_exec.go
     66 
     67 if [ "$GOIOS_DEV_ID" = "" ]; then
     68 	echo "detecting iOS development identity"
     69 	eval $(GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go run ../misc/ios/detect.go)
     70 fi
     71 
     72 # Run standard build and tests.
     73 ./all.bash --no-clean
     74