termux-packages/scripts/build/setup/termux_setup_golang.sh
2021-07-05 12:22:15 +05:30

62 lines
1.8 KiB
Bash

# Utility function for golang-using packages to setup a go toolchain.
termux_setup_golang() {
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
local TERMUX_GO_VERSION=go1.16.5
local TERMUX_GO_PLATFORM=linux-amd64
local TERMUX_BUILDGO_FOLDER
if [ "${TERMUX_PACKAGES_OFFLINE-false}" = "true" ]; then
TERMUX_BUILDGO_FOLDER=${TERMUX_SCRIPTDIR}/build-tools/${TERMUX_GO_VERSION}
else
TERMUX_BUILDGO_FOLDER=${TERMUX_COMMON_CACHEDIR}/${TERMUX_GO_VERSION}
fi
export GOROOT=$TERMUX_BUILDGO_FOLDER
export PATH=${GOROOT}/bin:${PATH}
if [ -d "$TERMUX_BUILDGO_FOLDER" ]; then return; fi
local TERMUX_BUILDGO_TAR=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM}.tar.gz
rm -Rf "$TERMUX_COMMON_CACHEDIR/go" "$TERMUX_BUILDGO_FOLDER"
termux_download https://golang.org/dl/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM}.tar.gz \
"$TERMUX_BUILDGO_TAR" \
b12c23023b68de22f74c0524f10b753e7b08b1504cb7e417eccebdd3fae49061
( cd "$TERMUX_COMMON_CACHEDIR"; tar xf "$TERMUX_BUILDGO_TAR"; mv go "$TERMUX_BUILDGO_FOLDER"; rm "$TERMUX_BUILDGO_TAR" )
else
if [ "$(dpkg-query -W -f '${db:Status-Status}\n' golang 2>/dev/null)" != "installed" ]; then
echo "Package 'golang' is not installed."
echo "You can install it with"
echo
echo " pkg install golang"
echo
echo "or build it from source with"
echo
echo " ./build-package.sh golang"
echo
exit 1
fi
export GOROOT="$TERMUX_PREFIX/lib/go"
fi
}
termux_go_get() {
if $TERMUX_ON_DEVICE_BUILD; then
if [ -z ${GOPATH+x} ]; then
if $TERMUX_PKG_BUILD_IN_SRC; then
export GOPATH=$TERMUX_PKG_SRCDIR/go
else
export GOPATH=$TERMUX_PKG_BUILDDIR/go
fi
fi
if [ -d $TERMUX_PKG_CACHEDIR/go ]; then
cp $TERMUX_PKG_CACHEDIR/go $GOPATH -r
fi
go get "$@"
cp $GOPATH $TERMUX_PKG_CACHEDIR/go -r
else
go get "$@"
fi
}