Skip to content

Commit

Permalink
golang: Go modules support; Prepare to deprecate GOPATH
Browse files Browse the repository at this point in the history
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/[email protected]
	    golang.org/x/tools/[email protected]
	    ${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.

  https://lab.nexedi.com/kirr/helloweb/commit/a7c788ae71

- 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

  golang/go#37755 (comment)
  • Loading branch information
navytux committed Mar 2, 2021
1 parent 0f72fe8 commit 73ff1a8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
41 changes: 33 additions & 8 deletions component/golang/buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
# ${helloweb:location}/go:./...
#
#
# ${go:exe} is standalone executable that runs go in activated gowork environment.
Expand Down Expand Up @@ -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/[email protected]
*@*)
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
Expand Down
4 changes: 2 additions & 2 deletions component/helloweb/buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down

0 comments on commit 73ff1a8

Please sign in to comment.