From e11efc27c9d02dc697aa16b0c8bf9a25beb45c04 Mon Sep 17 00:00:00 2001
From: Kirill Smelkov <kirr@nexedi.com>
Date: Mon, 1 Mar 2021 12:39:13 +0300
Subject: [PATCH] =?UTF-8?q?golang:=20Break=20future=20gowork=20=E2=87=84?=
 =?UTF-8?q?=20go-git-package=20cycle?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Consider a Go package that is defined via go-git-package, for example

    [helloweb]
    <= go-git-package
    go.importpath = lab.nexedi.com/nexedi/helloweb
    repository    = https://lab.nexedi.com/nexedi/helloweb.git

Currently, since go-git-package references ${gowork:src}, it creates
helloweb -> gowork dependency. gowork, in turn, depends on
gowork.goinstall, which gets list of things to install from ${gowork:install}.

Currently we put only plain strings into ${gowork.install}, e.g.

    [gowork]
    install =
       lab.nexedi.com/nexedi/helloweb/go/...

but for Go modules support and for properly expressing what depends on what,
we'll want in the next patch to be able to specify something like

    [gowork]
    install =
       ${helloweb:location}/go:./...

which will create helloweb ⇄ gowork cycle.

Unfortunately buildout does not detect nor report an error for such cycles, and
simply processes parts in an order, which leads to situation where e.g.
helloweb was not yet cloned, but gowork.goinstall tries to `go install` it and
complains "no such helloweb directory".

-> Fix it by leaving gowork to use by component/golang/ users, and putting
settings about where gowork directories is into underlying gowork.dir section.
---
 component/golang/buildout.cfg   | 19 +++++++++++--------
 component/helloweb/buildout.cfg |  4 ++--
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/component/golang/buildout.cfg b/component/golang/buildout.cfg
index d6d983adf..45ee110c4 100644
--- a/component/golang/buildout.cfg
+++ b/component/golang/buildout.cfg
@@ -116,9 +116,9 @@ template= inline:
   exec go "$@"
 
 [gowork]
-directory = ${buildout:directory}/go.work
-src	= ${:directory}/src
-bin	= ${:directory}/bin
+directory = ${gowork.dir:directory}
+src	= ${gowork.dir:src}
+bin	= ${gowork.dir:bin}
 depends = ${gowork.goinstall:recipe}
 
 # go version used for the workspace (possible to override in applications)
@@ -140,16 +140,19 @@ env.sh  = ${gowork-env.sh:output}
 [gowork-env.sh]
 recipe	= slapos.recipe.template
 url     = ${:_profile_base_location_}/goenv.sh.in
-output	= ${gowork:directory}/env.sh
-depends = ${gowork.mkdir:recipe}
+output	= ${gowork.dir:directory}/env.sh
+depends = ${gowork.dir:recipe}
 md5sum	= 6efdf5d63381c240c7d206d7939a63f7
 
-[gowork.mkdir]
+[gowork.dir]
+directory = ${buildout:directory}/go.work
+src	= ${:directory}/src
+bin	= ${:directory}/bin
 # NOTE do not use slapos.cookbook:mkdirectory here - if anything in software (not instance)
 # uses slapos.cookbook:* in recipe - slapos.cookbook will get compiled against system
 # libxml/libxslt or fail to bootstrap at all if those are not present.
 recipe  = plone.recipe.command
-command = mkdir -p ${gowork:directory}
+command = mkdir -p ${:directory}
 update-command = ${:command}
 stop-on-error = true
 
@@ -175,4 +178,4 @@ git-executable = ${git:location}/bin/git
 # generated with the help of gowork-snapshot tool.
 [go-git-package]
 <= git-repository
-location = ${gowork:src}/${:go.importpath}
+location = ${gowork.dir:src}/${:go.importpath}
diff --git a/component/helloweb/buildout.cfg b/component/helloweb/buildout.cfg
index 0ae511f52..f769c53eb 100644
--- a/component/helloweb/buildout.cfg
+++ b/component/helloweb/buildout.cfg
@@ -44,7 +44,7 @@ input   = inline:
 [helloweb-egg]
 recipe  = zc.recipe.egg:develop
 egg     = helloweb
-setup   = ${gowork:src}/lab.nexedi.com/nexedi/helloweb/python/
+setup   = ${go_lab.nexedi.com_nexedi_helloweb:location}/python/
 
 [helloweb-python]
 recipe  = zc.recipe.egg:scripts
@@ -86,7 +86,7 @@ environment =
 
 [helloweb-ruby-bundle]
 recipe  = slapos.recipe.cmmi
-path    = ${gowork:src}/lab.nexedi.com/nexedi/helloweb/ruby/
+path    = ${go_lab.nexedi.com_nexedi_helloweb:location}/ruby/
 
 configure-command = :
 make-binary =
-- 
2.30.9