xref: /aosp_15_r20/external/toolchain-utils/go/push_goroot (revision 760c253c1ed00ce9abd48f8546f08516e57485fe)
1*760c253cSXin Li#!/bin/bash
2*760c253cSXin Liset -e -o pipefail
3*760c253cSXin Li
4*760c253cSXin Li# This script copies a locally built GOROOT to a remote device.
5*760c253cSXin Li#
6*760c253cSXin Li# Usage: push_goroot <target>...
7*760c253cSXin Li#
8*760c253cSXin Li# This script can work with both ChromeOS/Android devices.
9*760c253cSXin Li#
10*760c253cSXin Li# It uses "target_tmpdir" to figure out where to copy GOROOT on the device.
11*760c253cSXin Li# It uses "target_sh" to remotely execute commands on the device.
12*760c253cSXin Li# It uses "target_cp" to transfer files to the device.
13*760c253cSXin Li
14*760c253cSXin Ligoroot="$(target_tmpdir)/goroot"
15*760c253cSXin Lifor target in "$@"
16*760c253cSXin Lido
17*760c253cSXin Li	echo -n "pushing goroot to ${target} ... "
18*760c253cSXin Li	target_sh ${target} "rm -rf ${goroot}"
19*760c253cSXin Li	target_sh ${target} "mkdir -p ${goroot}/pkg"
20*760c253cSXin Li
21*760c253cSXin Li	cd "$(go_${target} env GOROOT)"
22*760c253cSXin Li	pkgdir="pkg/$(go_${target} env GOOS)_$(go_${target} env GOARCH)"
23*760c253cSXin Li	target_cp "${pkgdir}" ${target}:${goroot}/pkg
24*760c253cSXin Li
25*760c253cSXin Li	target_cp "src" ${target}:${goroot}
26*760c253cSXin Li	target_cp "lib" ${target}:${goroot}
27*760c253cSXin Li	[[ -d test ]] && target_cp "test" ${target}:${goroot}
28*760c253cSXin Li	echo "done"
29*760c253cSXin Lidone
30