2015-02-21 13:38:37 +01:00
|
|
|
#
|
|
|
|
# This helper is for templates for Go packages.
|
|
|
|
#
|
|
|
|
|
2017-11-24 23:05:29 +01:00
|
|
|
do_configure() {
|
2018-09-19 02:29:24 +02:00
|
|
|
# $go_import_path must be set, or we can't link $PWD into $GOSRCPATH
|
2018-12-20 02:01:04 +01:00
|
|
|
# nor build from modules
|
2018-09-19 02:29:24 +02:00
|
|
|
if [ -z "$go_import_path" ]; then
|
|
|
|
msg_error "\"\$go_import_path\" not set on $pkgname template.\n"
|
|
|
|
fi
|
|
|
|
|
2018-09-19 02:41:08 +02:00
|
|
|
# This isn't really configuration, but its needed by packages
|
|
|
|
# that do unusual things with the build where the expect to be
|
|
|
|
# able to cd into the $GOSRCPATH
|
2018-12-20 02:01:04 +01:00
|
|
|
if [[ "${go_mod_mode}" != "off" ]] && [[ -f go.mod ]]; then
|
|
|
|
# Skip GOPATH symlink for Go modules
|
|
|
|
msg_normal "Building $pkgname using Go modules.\n"
|
|
|
|
elif [[ "${go_get}" != "yes" ]]; then
|
2017-11-24 23:05:29 +01:00
|
|
|
mkdir -p "$(dirname ${GOSRCPATH})"
|
|
|
|
ln -fs $PWD "${GOSRCPATH}"
|
2017-09-15 19:18:31 +02:00
|
|
|
fi
|
2017-11-24 23:05:29 +01:00
|
|
|
}
|
2017-09-15 19:18:31 +02:00
|
|
|
|
2017-11-24 23:05:29 +01:00
|
|
|
do_build() {
|
2015-04-17 18:18:35 +02:00
|
|
|
go_package=${go_package:-$go_import_path}
|
2018-12-20 02:01:04 +01:00
|
|
|
# Build using Go modules if there's a go.mod file
|
|
|
|
if [[ "${go_mod_mode}" != "off" ]] && [[ -f go.mod ]]; then
|
|
|
|
if [[ -z "${go_mod_mode}" ]] && [[ -d vendor ]]; then
|
|
|
|
msg_normal "Using vendor dir for $pkgname Go dependencies.\n"
|
|
|
|
go_mod_mode=vendor
|
|
|
|
elif [[ "${go_mod_mode}" = "default" ]]; then
|
|
|
|
# Allow templates to explicitly opt into the go tool's
|
|
|
|
# default behavior.
|
|
|
|
go_mod_mode=
|
|
|
|
fi
|
|
|
|
go build -o "${GOPATH}/bin/$(basename ${go_package})" -mod="${go_mod_mode}" -x -tags "${go_build_tags}" -ldflags "${go_ldflags}" ${go_package}
|
|
|
|
else
|
|
|
|
# Otherwise, build using GOPATH
|
|
|
|
go get -x -tags "${go_build_tags}" -ldflags "${go_ldflags}" ${go_package}
|
|
|
|
fi
|
2015-02-21 13:38:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
do_install() {
|
2015-08-22 20:42:02 +02:00
|
|
|
find "${GOPATH}/bin" -type f -executable | while read line
|
2015-06-12 13:21:10 +02:00
|
|
|
do
|
|
|
|
vbin "${line}"
|
2015-05-04 13:39:15 +02:00
|
|
|
done
|
2015-02-21 13:38:37 +01:00
|
|
|
}
|