lib: Move to go modules and shed a few tears
The old system with vendor/ and git submodules worked great, unfortunately FUD around git submodules seemed to scare people away and golang moved to a go.mod system that adds a new lock file format instead of using the built-in git version. It's now almost impossible to use modern golang without this, so we've switched. So much for the golang compatibility promise-- turns out it doesn't apply to the useful parts that I actually care about like this. Thanks to frebib for his incredibly valuable contributions to this patch. This snide commit message is mine alone. This patch also mixes in some changes due to legacy golang as we've also bumped the minimum version to 1.16 in the docs and tests. Lastly, we had to disable some tests and fix up a few other misc things to get this passing. We've definitely hot bugs in the go.mod system, and our Makefile tries to workaround those.
This commit is contained in:
15
misc/go
15
misc/go
@@ -1,15 +0,0 @@
|
||||
#!/bin/bash
|
||||
# hack around stupid $GOPATH semantics, with ~/bin/go helper
|
||||
# thanks to Nilium in #go-nuts for 1/3 of the idea
|
||||
[ -z "$GOPATH" ] && echo '$GOPATH is not set!' && exit 1
|
||||
GO="$(which -a go | sed -e '2q;d')" # TODO: pick /usr/bin/go in a better way
|
||||
if [ "$1" = "generate" ]; then
|
||||
exec $GO "$@" # go generate is stupid and gets confused by $GOPATH
|
||||
fi
|
||||
# the idea is to have $project/gopath/src/ be a symlink to ../vendor but you put
|
||||
# all of your vendored things in vendor/ but with this gopath can be per project
|
||||
if [ -d "$PWD/vendor/" ] && [ -d "$PWD/gopath/" ] && [ "`readlink $PWD/gopath/src`" = "../vendor" ] ; then
|
||||
GOPATH="$PWD/gopath/:$GOPATH" $GO "$@"
|
||||
else
|
||||
$GO "$@"
|
||||
fi
|
||||
@@ -17,11 +17,11 @@ BREW=`command -v brew 2>/dev/null`
|
||||
PACMAN=`command -v pacman 2>/dev/null`
|
||||
|
||||
# set minimum golang version and installed golang version
|
||||
mingoversion=13
|
||||
goversion=0
|
||||
mingolangversion=16
|
||||
golangversion=0
|
||||
if [ -x "$GO" ]; then
|
||||
# capture the minor version number
|
||||
goversion=$(go version | grep -o -P '(?<=go1\.)[0-9]*')
|
||||
golangversion=$(go version | grep -o -P '(?<=go1\.)[0-9]*')
|
||||
fi
|
||||
|
||||
# if DNF is available use it
|
||||
@@ -126,7 +126,7 @@ if in_ci; then
|
||||
fi
|
||||
|
||||
# attempt to workaround old ubuntu
|
||||
if [ -n "$APT" -a "$goversion" -lt "$mingoversion" ]; then
|
||||
if [ -n "$APT" -a "$golangversion" -lt "$mingolangversion" ]; then
|
||||
echo "install golang from a ppa."
|
||||
$sudo_command $APT remove -y golang
|
||||
$sudo_command $APT install -y software-properties-common # for add-apt-repository
|
||||
@@ -136,20 +136,15 @@ if [ -n "$APT" -a "$goversion" -lt "$mingoversion" ]; then
|
||||
fi
|
||||
|
||||
# if golang is too old, we don't want to fail with an obscure error later
|
||||
if [ "$goversion" -lt "$mingoversion" ]; then
|
||||
echo "mgmt recommends go1.$mingoversion or higher."
|
||||
if [ "$golangversion" -lt "$mingolangversion" ]; then
|
||||
echo "mgmt recommends go1.$mingolangversion or higher."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
fold_start "Install golang dependencies"
|
||||
echo "running 'go get -v -d ./...' from `pwd`"
|
||||
go get -v -t -d ./... # get all the golang dependencies
|
||||
echo "done running 'go get -v -t -d ./...'"
|
||||
fold_end "Install golang dependencies"
|
||||
|
||||
[ -e "$GOBIN/mgmt" ] && rm -f "$GOBIN/mgmt" # the `go get` version has no -X
|
||||
|
||||
fold_start "Install golang tools"
|
||||
# TODO: change this for golang 1.17
|
||||
go get github.com/blynn/nex # for lexing
|
||||
go get golang.org/x/tools/cmd/goyacc # formerly `go tool yacc`
|
||||
go get golang.org/x/tools/cmd/stringer # for automatic stringer-ing
|
||||
|
||||
@@ -13,24 +13,12 @@
|
||||
# The default that will get used automatically.
|
||||
export GOPATH=~/go/
|
||||
|
||||
# The golang bins are stored here.
|
||||
# The golang binaries are stored here.
|
||||
export GOBIN="${GOPATH}bin/"
|
||||
|
||||
# Needed so that golang build tools will get found.
|
||||
export PATH="${GOBIN}:${PATH}"
|
||||
|
||||
# Define the golang dir for mgmt.
|
||||
MGMTDIR="${GOPATH}src/github.com/purpleidea/mgmt/"
|
||||
|
||||
# Make the parent dir.
|
||||
mkdir -p $(dirname $MGMTDIR)
|
||||
|
||||
# Move our code into it so that golang works.
|
||||
mv "$SRCDIR" "$MGMTDIR"
|
||||
|
||||
# Work from that directory.
|
||||
cd "$MGMTDIR"
|
||||
|
||||
# Pull from the MKOSI_DEFAULT var: https://github.com/systemd/mkosi/pull/367
|
||||
mkosi_default="mkosi.default." # remove this prefix
|
||||
MGMT_MKOSI_DISTRO="${MKOSI_DEFAULT##$mkosi_default}"
|
||||
@@ -51,7 +39,7 @@ if [ -e "/etc/arch-release" ]; then
|
||||
echo 'Server = http://mirror.rackspace.com/archlinux/$repo/os/$arch' > /etc/pacman.d/mirrorlist
|
||||
cat /etc/pacman.d/mirrorlist.backup >> /etc/pacman.d/mirrorlist
|
||||
pacman -Syu --noconfirm pacman-mirrorlist
|
||||
pacman -Syyu
|
||||
pacman -Syu
|
||||
fi
|
||||
|
||||
# Get all the dependencies for mgmt.
|
||||
|
||||
Reference in New Issue
Block a user