aboutsummaryrefslogtreecommitdiff
path: root/go
diff options
context:
space:
mode:
authorRahul Chaudhry <rahulchaudhry@chromium.org>2016-03-29 10:20:18 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-03-30 16:58:42 +0000
commitf637a050cc27b206824d7b1262d2aa9de0668bef (patch)
treec983227876e0ff41750681aaa89e90146550063b /go
parent25b0005755697f571b816d286497c3fddfa06fd2 (diff)
downloadtoolchain-utils-f637a050cc27b206824d7b1262d2aa9de0668bef.tar.gz
toolchain-utils: scripts for building and testing the Go toolchain.
BUG=None TEST=None Change-Id: I07bd5ca5c2e005e3b476654ee3ff5fefc205e95a Reviewed-on: https://chrome-internal-review.googlesource.com/252756 Commit-Ready: Rahul Chaudhry <rahulchaudhry@google.com> Tested-by: Rahul Chaudhry <rahulchaudhry@google.com> Reviewed-by: Luis Lozano <llozano@chromium.org>
Diffstat (limited to 'go')
-rwxr-xr-xgo/android/adb_shamu8
-rwxr-xr-xgo/android/adb_volantis8
-rwxr-xr-xgo/android/build_go26
-rwxr-xr-xgo/android/go_shamu11
-rwxr-xr-xgo/android/go_shamu_exec8
-rwxr-xr-xgo/android/go_volantis11
-rwxr-xr-xgo/android/go_volantis_exec8
-rwxr-xr-xgo/android/target_cp28
-rwxr-xr-xgo/android/target_sh13
-rwxr-xr-xgo/android/target_tmpdir5
-rwxr-xr-xgo/chromeos/build_go45
-rwxr-xr-xgo/chromeos/go_daisy11
-rwxr-xr-xgo/chromeos/go_daisy_exec10
-rwxr-xr-xgo/chromeos/go_panther11
-rwxr-xr-xgo/chromeos/go_panther_exec10
-rwxr-xr-xgo/chromeos/go_x86-zgb11
-rwxr-xr-xgo/chromeos/go_x86-zgb_exec10
-rwxr-xr-xgo/chromeos/target_cp28
-rwxr-xr-xgo/chromeos/target_sh11
-rwxr-xr-xgo/chromeos/target_tmpdir5
-rwxr-xr-xgo/go_target83
-rwxr-xr-xgo/go_target_exec41
-rwxr-xr-xgo/push_goroot34
23 files changed, 436 insertions, 0 deletions
diff --git a/go/android/adb_shamu b/go/android/adb_shamu
new file mode 100755
index 00000000..1c53ecc1
--- /dev/null
+++ b/go/android/adb_shamu
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+# This wrapper runs adb with the serial number of the shamu device.
+# Replace XXXXXXXX with the actual serial number of the device.
+# This is just an example. Create one such wrapper for each Android
+# device used for running Go tests.
+
+exec adb -s XXXXXXXX "$@"
diff --git a/go/android/adb_volantis b/go/android/adb_volantis
new file mode 100755
index 00000000..4712eec2
--- /dev/null
+++ b/go/android/adb_volantis
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+# This wrapper runs adb with the serial number of the volantis device.
+# Replace YYYYYYYY with the actual serial number of the device.
+# This is just an example. Create one such wrapper for each Android
+# device used for running Go tests.
+
+exec adb -s YYYYYYYY "$@"
diff --git a/go/android/build_go b/go/android/build_go
new file mode 100755
index 00000000..65b7ec2b
--- /dev/null
+++ b/go/android/build_go
@@ -0,0 +1,26 @@
+#!/bin/bash
+set -e -o pipefail
+
+# This script builds the go cross compilers for Android targets.
+#
+# Usage: build_go
+#
+# It assumes that the "arm-linux-androideabi" toolchain is already installed.
+# It assumes that the "aarch64-linux-android" toolchain is already installed.
+
+if [[ ! -e "make.bash" && -e "src/make.bash" ]]
+then
+ cd src
+fi
+
+# Build the Go toolchain for arm devices.
+GOOS="android" GOARCH="arm" CGO_ENABLED="1" \
+ CC_FOR_TARGET="arm-linux-androideabi-gcc" \
+ CXX_FOR_TARGET="arm-linux-androideabi-g++" \
+ ./make.bash --no-clean
+
+# Build the Go toolchain for arm64 devices.
+GOOS="android" GOARCH="arm64" CGO_ENABLED="1" \
+ CC_FOR_TARGET="aarch64-linux-android-gcc" \
+ CXX_FOR_TARGET="aarch64-linux-android-g++" \
+ ./make.bash --no-clean
diff --git a/go/android/go_shamu b/go/android/go_shamu
new file mode 100755
index 00000000..7e1ffbea
--- /dev/null
+++ b/go/android/go_shamu
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# Invoke the Go cross compiler for shamu.
+# Uses ../go_target to add PIE flags.
+#
+# This is just an example for an arm device.
+
+GOOS="android" GOARCH="arm" CGO_ENABLED="1" \
+ CC="arm-linux-androideabi-gcc" \
+ CXX="arm-linux-androideabi-g++" \
+ exec go_target "$@"
diff --git a/go/android/go_shamu_exec b/go/android/go_shamu_exec
new file mode 100755
index 00000000..2c169026
--- /dev/null
+++ b/go/android/go_shamu_exec
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+# Copy and remotely execute a binary on the shamu device.
+#
+# For this to work, the corresponding adb_shamu wrapper
+# must exist to tell adb the serial number of the device.
+
+GOOS="android" GOARCH="arm" exec go_target_exec shamu "$@"
diff --git a/go/android/go_volantis b/go/android/go_volantis
new file mode 100755
index 00000000..bfeab196
--- /dev/null
+++ b/go/android/go_volantis
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# Invoke the Go cross compiler for volantis.
+# Uses ../go_target to add PIE flags.
+#
+# This is just an example for an arm64 device.
+
+GOOS="android" GOARCH="arm64" CGO_ENABLED="1" \
+ CC="aarch64-linux-android-gcc" \
+ CXX="aarch64-linux-android-g++" \
+ exec go_target "$@"
diff --git a/go/android/go_volantis_exec b/go/android/go_volantis_exec
new file mode 100755
index 00000000..86cb2cfb
--- /dev/null
+++ b/go/android/go_volantis_exec
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+# Copy and remotely execute a binary on the volantis device.
+#
+# For this to work, the corresponding adb_volantis wrapper
+# must exist to tell adb the serial number of the device.
+
+GOOS="android" GOARCH="arm64" exec go_target_exec volantis "$@"
diff --git a/go/android/target_cp b/go/android/target_cp
new file mode 100755
index 00000000..8a311534
--- /dev/null
+++ b/go/android/target_cp
@@ -0,0 +1,28 @@
+#!/bin/bash
+set -e -o pipefail
+
+# Copy a file or directory to the target Android device.
+#
+# Usage: target_cp <src> <target>:<dest>
+
+src="$1"
+shift
+
+targetdest="$1"
+shift
+
+target="${targetdest%:*}"
+dest="${targetdest#*:}"
+
+if [[ -z "${src}" || -z "${target}" || -z "${dest}" || "${targetdest}" != "${target}:${dest}" || -n "$*" ]]
+then
+ echo "Usage: target_cp <src> <target>:<dest>"
+ exit 1
+fi
+
+if [[ -d ${src} ]]
+then
+ adb_${target} push ${src} ${dest}/${src##*/} 2>/dev/null
+else
+ adb_${target} push ${src} ${dest} 2>/dev/null
+fi
diff --git a/go/android/target_sh b/go/android/target_sh
new file mode 100755
index 00000000..241843e8
--- /dev/null
+++ b/go/android/target_sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+set -e -o pipefail
+
+# Run a command on the target Android device.
+#
+# Usage: target_sh <cmd> <args>...
+
+target="$1"
+shift
+
+exitcode="$(target_tmpdir)/exitcode"
+adb_${target} shell "$*; echo -n \$? > ${exitcode}" | sed -e 's:\r$::' -u
+exit $(adb_${target} shell "cat ${exitcode}")
diff --git a/go/android/target_tmpdir b/go/android/target_tmpdir
new file mode 100755
index 00000000..b5953696
--- /dev/null
+++ b/go/android/target_tmpdir
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+# Temporary directory to be used on Android devices.
+
+echo "/data/local/tmp"
diff --git a/go/chromeos/build_go b/go/chromeos/build_go
new file mode 100755
index 00000000..cb882eaf
--- /dev/null
+++ b/go/chromeos/build_go
@@ -0,0 +1,45 @@
+#!/bin/bash
+set -e -o pipefail
+
+# This script builds the go cross compilers for ChromeOS targets.
+#
+# Usage: build_go
+#
+# It assumes that the "x86_64-cros-linux-gnu" toolchain is already installed.
+# It assumes that the "i686-pc-linux-gnu" toolchain is already installed.
+# It assumes that the "armv7a-cros-linux-gnueabi" toolchain is already installed.
+
+if [[ ! -e "make.bash" && -e "src/make.bash" ]]
+then
+ cd src
+fi
+
+# Build the Go toolchain for amd64 targets.
+GOOS="linux" GOARCH="amd64" CGO_ENABLED="1" \
+ CC_FOR_TARGET="x86_64-cros-linux-gnu-gcc" \
+ CXX_FOR_TARGET="x86_64-cros-linux-gnu-g++" \
+ ./make.bash --no-clean
+GOOS="linux" GOARCH="amd64" CGO_ENABLED="1" \
+ CC="x86_64-cros-linux-gnu-gcc" \
+ CXX="x86_64-cros-linux-gnu-g++" \
+ ../bin/go install -v -buildmode=pie std
+
+# Build the Go toolchain for 386 targets.
+GOOS="linux" GOARCH="386" CGO_ENABLED="1" \
+ CC_FOR_TARGET="i686-pc-linux-gnu-gcc" \
+ CXX_FOR_TARGET="i686-pc-linux-gnu-g++" \
+ ./make.bash --no-clean
+GOOS="linux" GOARCH="386" CGO_ENABLED="1" \
+ CC="i686-pc-linux-gnu-gcc" \
+ CXX="i686-pc-linux-gnu-g++" \
+ ../bin/go install -v -buildmode=pie std
+
+# Build the Go toolchain for arm targets.
+GOOS="linux" GOARCH="arm" CGO_ENABLED="1" \
+ CC_FOR_TARGET="armv7a-cros-linux-gnueabi-gcc" \
+ CXX_FOR_TARGET="armv7a-cros-linux-gnueabi-g++" \
+ ./make.bash --no-clean
+GOOS="linux" GOARCH="arm" CGO_ENABLED="1" \
+ CC="armv7a-cros-linux-gnueabi-gcc" \
+ CXX="armv7a-cros-linux-gnueabi-g++" \
+ ../bin/go install -v -buildmode=pie std
diff --git a/go/chromeos/go_daisy b/go/chromeos/go_daisy
new file mode 100755
index 00000000..db4a95ac
--- /dev/null
+++ b/go/chromeos/go_daisy
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# Invoke the Go cross compiler for daisy.
+# Uses ../go_target to add PIE flags.
+#
+# This is just an example for an arm board.
+
+GOOS="linux" GOARCH="arm" CGO_ENABLED="1" \
+ CC="armv7a-cros-linux-gnueabi-gcc" \
+ CXX="armv7a-cros-linux-gnueabi-g++" \
+ exec go_target "$@"
diff --git a/go/chromeos/go_daisy_exec b/go/chromeos/go_daisy_exec
new file mode 100755
index 00000000..3b9a63dd
--- /dev/null
+++ b/go/chromeos/go_daisy_exec
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# Copy and remotely execute a binary on the daisy device.
+#
+# For this to work, the corresponding entry must exist in
+# ~/.ssh/config and the device must already be setup for
+# password-less authentication. See setup instructions at
+# http://go/chromeos-toolchain-team/go-toolchain
+
+GOOS="linux" GOARCH="arm" exec go_target_exec daisy "$@"
diff --git a/go/chromeos/go_panther b/go/chromeos/go_panther
new file mode 100755
index 00000000..5c06f432
--- /dev/null
+++ b/go/chromeos/go_panther
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# Invoke the Go cross compiler for panther.
+# Uses ../go_target to add PIE flags.
+#
+# This is just an example for an amd64 board.
+
+GOOS="linux" GOARCH="amd64" CGO_ENABLED="1" \
+ CC="x86_64-cros-linux-gnu-gcc" \
+ CXX="x86_64-cros-linux-gnu-g++" \
+ exec go_target "$@"
diff --git a/go/chromeos/go_panther_exec b/go/chromeos/go_panther_exec
new file mode 100755
index 00000000..64f77b1f
--- /dev/null
+++ b/go/chromeos/go_panther_exec
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# Copy and remotely execute a binary on the panther device.
+#
+# For this to work, the corresponding entry must exist in
+# ~/.ssh/config and the device must already be setup for
+# password-less authentication. See setup instructions at
+# http://go/chromeos-toolchain-team/go-toolchain
+
+GOOS="linux" GOARCH="amd64" exec go_target_exec panther "$@"
diff --git a/go/chromeos/go_x86-zgb b/go/chromeos/go_x86-zgb
new file mode 100755
index 00000000..272efb58
--- /dev/null
+++ b/go/chromeos/go_x86-zgb
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# Invoke the Go cross compiler for x86-zgb.
+# Uses ../go_target to add PIE flags.
+#
+# This is just an example for an 386 board.
+
+GOOS="linux" GOARCH="386" CGO_ENABLED="1" \
+ CC="i686-pc-linux-gnu-gcc" \
+ CXX="i686-pc-linux-gnu-g++" \
+ exec go_target "$@"
diff --git a/go/chromeos/go_x86-zgb_exec b/go/chromeos/go_x86-zgb_exec
new file mode 100755
index 00000000..b0341f21
--- /dev/null
+++ b/go/chromeos/go_x86-zgb_exec
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# Copy and remotely execute a binary on the x86-zgb device.
+#
+# For this to work, the corresponding entry must exist in
+# ~/.ssh/config and the device must already be setup for
+# password-less authentication. See setup instructions at
+# http://go/chromeos-toolchain-team/go-toolchain
+
+GOOS="linux" GOARCH="386" exec go_target_exec x86-zgb "$@"
diff --git a/go/chromeos/target_cp b/go/chromeos/target_cp
new file mode 100755
index 00000000..6df476e6
--- /dev/null
+++ b/go/chromeos/target_cp
@@ -0,0 +1,28 @@
+#!/bin/bash
+set -e -o pipefail
+
+# Copy a file or directory to the target ChromeOS device.
+#
+# Usage: target_cp <src> <target>:<dest>
+
+src="$1"
+shift
+
+targetdest="$1"
+shift
+
+target="${targetdest%:*}"
+dest="${targetdest#*:}"
+
+if [[ -z "${src}" || -z "${target}" || -z "${dest}" || "${targetdest}" != "${target}:${dest}" || -n "$*" ]]
+then
+ echo "Usage: target_cp <src> <target>:<dest>"
+ exit 1
+fi
+
+if [[ -d ${src} ]]
+then
+ scp -rq ${src} ${target}:${dest}
+else
+ scp -q ${src} ${target}:${dest}
+fi
diff --git a/go/chromeos/target_sh b/go/chromeos/target_sh
new file mode 100755
index 00000000..43c5fac6
--- /dev/null
+++ b/go/chromeos/target_sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+set -e -o pipefail
+
+# Run a command on the target ChromeOS device.
+#
+# Usage: target_sh <cmd> <args>...
+
+target="$1"
+shift
+
+ssh ${target} "$*"
diff --git a/go/chromeos/target_tmpdir b/go/chromeos/target_tmpdir
new file mode 100755
index 00000000..382a0334
--- /dev/null
+++ b/go/chromeos/target_tmpdir
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+# Temporary directory to be used on ChromeOS devices.
+
+echo "/tmp"
diff --git a/go/go_target b/go/go_target
new file mode 100755
index 00000000..05786377
--- /dev/null
+++ b/go/go_target
@@ -0,0 +1,83 @@
+#!/bin/bash
+set -e -o pipefail
+
+# This script wraps the go cross compilers.
+#
+# It ensures that Go binaries are linked with an external linker
+# by default (cross gcc). Appropriate flags are added to build a
+# position independent executable (PIE) for ASLR.
+# "export GOPIE=0" to temporarily disable this behavior.
+
+function pie_enabled()
+ {
+ [[ "${GOPIE}" != "0" ]]
+ }
+
+function has_ldflags()
+ {
+ # Check if any linker flags are present in argv.
+ for arg in "$@"
+ do
+ case "${arg}" in
+ -ldflags | -ldflags=*) return 0 ;;
+ -linkmode | -linkmode=*) return 0 ;;
+ -buildmode | -buildmode=*) return 0 ;;
+ -installsuffix | -installsuffix=*) return 0 ;;
+ -extld | -extld=*) return 0 ;;
+ -extldflags | -extldflags=*) return 0 ;;
+ esac
+ done
+ return 1
+ }
+
+pie_flags=()
+if pie_enabled && ! has_ldflags "$@"
+then
+ case "$1" in
+ build | install | run | test)
+ # Add "-buildmode=pie" to "go build|install|run|test" commands.
+ pie_flags=(
+ "$1"
+ "-buildmode=pie"
+ )
+ shift
+ ;;
+ tool)
+ case "$2" in
+ asm)
+ # Handle direct assembler invocations ("go tool asm <args>").
+ pie_flags=(
+ "$1"
+ "$2"
+ "-shared"
+ )
+ shift 2
+ ;;
+ compile)
+ # Handle direct compiler invocations ("go tool compile <args>").
+ pie_flags=(
+ "$1"
+ "$2"
+ "-shared"
+ "-installsuffix=shared"
+ )
+ shift 2
+ ;;
+ link)
+ # Handle direct linker invocations ("go tool link <args>").
+ pie_flags=(
+ "$1"
+ "$2"
+ "-installsuffix=shared"
+ "-buildmode=pie"
+ "-extld"
+ "${CC}"
+ )
+ shift 2
+ ;;
+ esac
+ ;;
+ esac
+fi
+
+exec go "${pie_flags[@]}" "$@"
diff --git a/go/go_target_exec b/go/go_target_exec
new file mode 100755
index 00000000..34d9e799
--- /dev/null
+++ b/go/go_target_exec
@@ -0,0 +1,41 @@
+#!/bin/bash
+set -e -o pipefail
+
+# This wrapper copies an executable to a target device and executes it there.
+#
+# Usage: go_target_exec <target> <binary> <args>...
+#
+# This script can work with both ChromeOS/Android devices.
+#
+# It uses "target_tmpdir" to get the path to the temporary directory on the device.
+# It uses "target_cp" to copy the binary to the temporary directory on the device.
+# It uses "target_sh" to execute the binary remotely and get the output/exitcode.
+
+target="$1"
+shift
+
+binary="$1"
+shift
+
+# Get path to temporary directory on device and copy the binary over.
+tmpdir="$(target_tmpdir)"
+target_cp ${binary} ${target}:${tmpdir}/a.out
+
+# If current directory is inside GOROOT, then execute the binary in the
+# corresponding directory inside GOROOT on the device.
+targetdir="${tmpdir}"
+goroot="$(go_${target} env GOROOT)"
+if [[ "${PWD}" == ${goroot}/src/* ]]
+then
+ targetdir="${tmpdir}/go/src/${PWD#${goroot}/src/}"
+fi
+
+# Set GOROOT, and forward some environment variables to the remote shell.
+vars="GOROOT=${tmpdir}/go"
+vars+="${GOOS:+ GOOS=${GOOS}}"
+vars+="${GOARCH:+ GOARCH=${GOARCH}}"
+vars+="${GOMAXPROCS:+ GOMAXPROCS=${GOMAXPROCS}}"
+vars+="${GOTRACEBACK:+ GOTRACEBACK=${GOTRACEBACK}}"
+
+# Remotely execute the binary using ssh (for ChromeOS) or adb (for Android).
+target_sh ${target} "cd ${targetdir} && ${vars} ${tmpdir}/a.out $*"
diff --git a/go/push_goroot b/go/push_goroot
new file mode 100755
index 00000000..41612f72
--- /dev/null
+++ b/go/push_goroot
@@ -0,0 +1,34 @@
+#!/bin/bash
+set -e -o pipefail
+
+# This script copies a locally built GOROOT to a remote device.
+#
+# Usage: push_goroot <target>...
+#
+# This script can work with both ChromeOS/Android devices.
+#
+# It uses "target_tmpdir" to figure out where to copy GOROOT on the device.
+# It uses "target_sh" to remotely execute commands on the device.
+# It uses "target_cp" to transfer files to the device.
+
+goroot="$(target_tmpdir)/go"
+for target in "$@"
+do
+ echo -n "pushing to ${target} ... "
+ target_sh ${target} "rm -rf ${goroot}"
+ target_sh ${target} "mkdir -p ${goroot}/pkg"
+
+ pkgdir="$(go_${target} env GOOS)_$(go_${target} env GOARCH)"
+ if [[ -d "pkg/${pkgdir}_shared" ]]
+ then
+ target_cp "pkg/${pkgdir}_shared" ${target}:${goroot}/pkg
+ target_sh ${target} "ln -s ${pkgdir}_shared ${goroot}/pkg/${pkgdir}"
+ else
+ target_cp "pkg/${pkgdir}" ${target}:${goroot}/pkg
+ fi
+
+ target_cp "src" ${target}:${goroot}
+ target_cp "lib" ${target}:${goroot}
+ target_cp "test" ${target}:${goroot}
+ echo "done"
+done