Commit 73ff1a8d authored by Kirill Smelkov's avatar Kirill Smelkov

golang: Go modules support; Prepare to deprecate GOPATH

Add support for using Go modules to golang/gowork infrastructure:

- Users can now request to install a module via gowork:install as. e.g.
  in the following example:

	[gowork]
	install =
	    lab.nexedi.com/kirr/neo/go/...@v0.0.0-20210103165133-f3effa6c535f
	    golang.org/x/tools/gopls@v0.4.3
	    ${helloweb:location}/go:./...

  The first two request to install programs from an external module at particular
  revision/version. The latter requests to install programs from locally
  cloned/checked-out module source.

  The documentation now talks only about programs, because "package
  installation" became unnecessary long time ago as Go toolchain uses
  right packages and recompiles things as needed automatically since
  introduction of the Go build cache in go 1.10.

- The change comes accompanied by corresponding helloweb change that
  reworks it to a) become a module itself, and b) to use other modules -
  that are not explicitly cloned by buildout - so that we can be sure
  that module way of fetching/building things actually works.

  kirr/helloweb@a7c788ae

- Non-module way - e.g. build via GOPATH - is still supported (because
  e.g. software/gitlab still uses it), but not explicitly documented and
  scheduled to be deprecated and removed. The reason for this is that
  upstream Go is going to remove support for GOPATH and leave only
  module-based approach in Go1.17

  https://github.com/golang/go/issues/37755#issuecomment-771879911
parent 0f72fe8c
......@@ -103,14 +103,14 @@ environment-extra =
# buildflags = -race
#
#
# Users can also add `install` field to [gowork] to describe packages they want to
# be installed (+ automatically their dependencies are installed too). e.g.
# Users can also add `install` field to [gowork] to request Go programs to be
# automatically installed, for example:
#
# [gowork]
# install =
# lab.nexedi.com/kirr/neo/go/...
# github.com/pkg/profile
# golang.org/x/perf/cmd/benchstat
# lab.nexedi.com/kirr/neo/go/...@v0.0.0-20210103165133-f3effa6c535f
# golang.org/x/tools/gopls@v0.4.3
# ${helloweb:location}/go:./...
#
#
# ${go:exe} is standalone executable that runs go in activated gowork environment.
......@@ -168,11 +168,36 @@ command = mkdir -p ${:directory}
update-command = ${:command}
stop-on-error = true
# install go packages
# clients can put package list to install to gowork:install ("..." requests installing everything)
# install go programs
# clients can put program list to install to gowork:install
[gowork.goinstall]
recipe = plone.recipe.command
command = bash -c ". ${gowork:env.sh} && test -z '${gowork:install}' || go install ${gowork:buildflags} -v $(echo -n '${gowork:install}' |tr '\n' ' ')"
command = bash -c ". ${gowork:env.sh} &&
for x in $(echo -n '${gowork:install}' |tr '\n' ' '); do
case "\$x" in
# external module, e.g. golang.org/x/tools/gopls@v0.4.3
*@*)
echo GOMOD \$x
GO111MODULE=on go install ${gowork:buildflags} -v \$x
;;
# locally-cloned module source, e.g. <module-src-location>:./...
*:*)
echo GOMODSRC \$x
dir=\"\$${x%%:*}\"
arg=\"\$${x#*:}\"
(cd \$dir && GO111MODULE=on go install ${gowork:buildflags} -v \$arg)
;;
# non-module
*)
echo GOPKG \$x
GO111MODULE=off go install ${gowork:buildflags} -v \$x
;;
esac
done
"
update-command = ${:command}
stop-on-error = true
......
......@@ -24,11 +24,11 @@ parts =
<= go-git-package
go.importpath = lab.nexedi.com/nexedi/helloweb
repository = https://lab.nexedi.com/nexedi/helloweb.git
revision = 8bfedac656
revision = a7c788ae71
[gowork]
install =
lab.nexedi.com/nexedi/helloweb/go/...
${helloweb:location}/go:./...
golang = ${golang1.16:location}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment