Skip to contentSkip to conversation

go-mod.bbclass: Add class for `go mod` support

PATCH In review Khem Raj 2 participants 6 messages Jun 22, 2020

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/4 go-mod.bbclass: Add class for `go mod` support

From: Otavio Salvador <[email protected]>

When using Go Modules, the the current working directory MUST be at or below the location of the 'go.mod' file when the go tool is used, and there is no way to tell it to look elsewhere. It will automatically look upwards for the file, but not downwards.

To support this use case, we provide the GO_WORKDIR variable, which defaults to GO_IMPORT but allows for easy override.

[YOCTO #13883]

---
 meta/classes/go-mod.bbclass | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 meta/classes/go-mod.bbclass
meta/classes/go-mod.bbclass new file +20 -0
new file mode 100644
index 0000000000..5871d02506
@@ -0,0 +1,20 @@
+# Handle Go Modules support
+#
+# When using Go Modules, the the current working directory MUST be at or below
+# the location of the 'go.mod' file when the go tool is used, and there is no
+# way to tell it to look elsewhere.  It will automatically look upwards for the
+# file, but not downwards.
+#
+# To support this use case, we provide the `GO_WORKDIR` variable, which defaults
+# to `GO_IMPORT` but allows for easy override.
+#
+# Copyright 2020 (C) O.S. Systems Software LTDA.
+
+# The '-modcacherw' option ensures we have write access to the cached objects so
+# we avoid errors during clean task as well as when removing the TMPDIR.
+export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS} -modcacherw"
+
+inherit go
+
+GO_WORKDIR ?= "${GO_IMPORT}"
+do_compile[dirs] += "${B}/src/${GO_WORKDIR}"
Signature · 1 line
2.27.0
author
#1 lore raw

PATCH 2/4 go.bbclass: Add `-trimpath` to default build flags

From: Otavio Salvador <[email protected]>

The -trimpath option is important for reproducible builds so full build paths and module paths are not embedded.

---
 meta/classes/go.bbclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/classes/go.bbclass +1 -1
index c99689ac59..a9e31b50ea 100644
@@ -41,7 +41,7 @@ GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${GO_RPATH_LINK} ${LDFLAGS
 GO_LINKMODE ?= ""
 GO_LINKMODE_class-nativesdk = "--linkmode=external"
 GO_LDFLAGS ?= '-ldflags="${GO_RPATH} ${GO_LINKMODE} -extldflags '${GO_EXTLDFLAGS}'"'
-export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS}"
+export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS} -trimpath"
 export GOPATH_OMIT_IN_ACTIONID ?= "1"
 export GOPTESTBUILDFLAGS ?= "${GOBUILDFLAGS} -c"
 export GOPTESTFLAGS ?= ""
Signature · 1 line
2.27.0
author
#2 lore raw

PATCH 3/4 go-dep: Avoid use of 'go mod' support

In reply to Khem Raj

From: Otavio Salvador <[email protected]>

dep utility must not use 'go mod' support, so we explicitly disable it.

---
 meta/recipes-devtools/go/go-dep_0.5.4.bb | 4 ++++
 1 file changed, 4 insertions(+)
meta/recipes-devtools/go/go-dep_0.5.4.bb +4 -0
index 615cb289e5..496224a5cf 100644
@@ -13,6 +13,10 @@ SRCREV = "1f7c19e5f52f49ffb9f956f64c010be14683468b"
 
 inherit go
 
+# New Go versions has Go modules support enabled by default and cause the Glide
+# tool build to fail.
+export GO111MODULE = "off"
+
 GO_INSTALL = "${GO_IMPORT}/cmd/dep"
 
 RDEPENDS_${PN}-dev += "bash"
Signature · 1 line
2.27.0
author
#3 lore raw

PATCH 4/4 glide: Avoid use of 'go mod' support

In reply to Khem Raj

From: Otavio Salvador <[email protected]>

Glide utility must not use 'go mod' support, so we explicitly disable it.

---
 meta/recipes-devtools/glide/glide_0.13.3.bb | 4 ++++
 1 file changed, 4 insertions(+)
meta/recipes-devtools/glide/glide_0.13.3.bb +4 -0
index ebad0ec60a..31295edf90 100644
@@ -9,6 +9,10 @@ SRCREV = "8ed5b9292379d86c39592a7e6a58eb9c903877cf"
 
 inherit go
 
+# New Go versions has Go modules support enabled by default and cause the Glide
+# tool build to fail.
+export GO111MODULE = "off"
+
 RDEPENDS_${PN}-dev += "bash"
 RDEPENDS_${PN}-ptest += "bash"
 
Signature · 1 line
2.27.0
#4 lore raw
In reply to Khem Raj

This set of patches is contained in the series I sent out for review this morning :-)

Steve

Quoted 50 lines · Khem Raj

From: Otavio Salvador <[email protected]>

When using Go Modules, the the current working directory MUST be at or below the location of the 'go.mod' file when the go tool is used, and there is no way to tell it to look elsewhere. It will automatically look upwards for the file, but not downwards.

To support this use case, we provide the GO_WORKDIR variable, which defaults to GO_IMPORT but allows for easy override.

[YOCTO #13883]

---
 meta/classes/go-mod.bbclass | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 meta/classes/go-mod.bbclass
meta/classes/go-mod.bbclass new file +20 -1
new file mode 100644
index 0000000000..5871d02506
@@ -0,0 +1,20 @@
+# Handle Go Modules support
+#
+# When using Go Modules, the the current working directory MUST be at or below
+# the location of the 'go.mod' file when the go tool is used, and there is no
+# way to tell it to look elsewhere.  It will automatically look upwards for the
+# file, but not downwards.
+#
+# To support this use case, we provide the `GO_WORKDIR` variable, which defaults
+# to `GO_IMPORT` but allows for easy override.
+#
+# Copyright 2020 (C) O.S. Systems Software LTDA.
+
+# The '-modcacherw' option ensures we have write access to the cached objects so
+# we avoid errors during clean task as well as when removing the TMPDIR.
+export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS} -modcacherw"
+
+inherit go
+
+GO_WORKDIR ?= "${GO_IMPORT}"
+do_compile[dirs] += "${B}/src/${GO_WORKDIR}"
--

2.27.0

author
#5 lore raw
Quoted 3 lines · Steve Sakoman

This set of patches is contained in the series I sent out for review this morning :-)

ah even better, Feel free to ignore this series then

Quoted 54 lines

Steve

Quoted 50 lines · Khem Raj

From: Otavio Salvador <[email protected]>

When using Go Modules, the the current working directory MUST be at or below the location of the 'go.mod' file when the go tool is used, and there is no way to tell it to look elsewhere. It will automatically look upwards for the file, but not downwards.

To support this use case, we provide the GO_WORKDIR variable, which defaults to GO_IMPORT but allows for easy override.

[YOCTO #13883]

---
 meta/classes/go-mod.bbclass | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 meta/classes/go-mod.bbclass
meta/classes/go-mod.bbclass new file +20 -1
new file mode 100644
index 0000000000..5871d02506
@@ -0,0 +1,20 @@
+# Handle Go Modules support
+#
+# When using Go Modules, the the current working directory MUST be at or below
+# the location of the 'go.mod' file when the go tool is used, and there is no
+# way to tell it to look elsewhere.  It will automatically look upwards for the
+# file, but not downwards.
+#
+# To support this use case, we provide the `GO_WORKDIR` variable, which defaults
+# to `GO_IMPORT` but allows for easy override.
+#
+# Copyright 2020 (C) O.S. Systems Software LTDA.
+
+# The '-modcacherw' option ensures we have write access to the cached objects so
+# we avoid errors during clean task as well as when removing the TMPDIR.
+export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS} -modcacherw"
+
+inherit go
+
+GO_WORKDIR ?= "${GO_IMPORT}"
+do_compile[dirs] += "${B}/src/${GO_WORKDIR}"
--

2.27.0