diff mbox series

[1/2] package/go: set GOCACHE for download post-process

Message ID 20230116105032.1890904-1-peter@korsgaard.com
State Accepted
Headers show
Series [1/2] package/go: set GOCACHE for download post-process | expand

Commit Message

Peter Korsgaard Jan. 16, 2023, 10:50 a.m. UTC
The go mod vendor call in support/download/go-post-process accesses the go
cache, so pass GOCACHE= in the environment to ensure our cache directory is
used.

The go cache defaults to ~/.cache/go-build if not set, so this fixes builds
where that location (or GOCACHE if set in the environment) is not writable:

rm -rf ~/.cache/go-build
chmod -w ~/.cache
make docker-compose-source
..
failed to initialize build cache at /home/peko/.cache/go-build: mkdir /home/peko/.cache/go-build: permission denied
make[1]: *** [package/pkg-generic.mk:189: /home/peko/source/buildroot/output/build/docker-compose-2.14.0/.stamp_downloaded] Error 1

We use two different cache directories for target and host builds, but the
download/vendoring should be independent of the architecture, so use the
target variant even for host-only packages for simplicity.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
---
 package/go/go.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Yann E. MORIN Jan. 16, 2023, 8:26 p.m. UTC | #1
Peter, All,

On 2023-01-16 11:50 +0100, Peter Korsgaard spake thusly:
> The go mod vendor call in support/download/go-post-process accesses the go
> cache, so pass GOCACHE= in the environment to ensure our cache directory is
> used.
> 
> The go cache defaults to ~/.cache/go-build if not set, so this fixes builds
> where that location (or GOCACHE if set in the environment) is not writable:
> 
> rm -rf ~/.cache/go-build
> chmod -w ~/.cache
> make docker-compose-source
> ..
> failed to initialize build cache at /home/peko/.cache/go-build: mkdir /home/peko/.cache/go-build: permission denied
> make[1]: *** [package/pkg-generic.mk:189: /home/peko/source/buildroot/output/build/docker-compose-2.14.0/.stamp_downloaded] Error 1
> 
> We use two different cache directories for target and host builds, but the
> download/vendoring should be independent of the architecture, so use the
> target variant even for host-only packages for simplicity.
> 
> Signed-off-by: Peter Korsgaard <peter@korsgaard.com>

Applied to master, thanks.

Regards,
Yann E. MORIN.

> ---
>  package/go/go.mk | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/package/go/go.mk b/package/go/go.mk
> index d3ed07f03b..c4f72d403c 100644
> --- a/package/go/go.mk
> +++ b/package/go/go.mk
> @@ -25,6 +25,7 @@ HOST_GO_COMMON_ENV = \
>  	GOFLAGS=-mod=vendor \
>  	GOROOT="$(HOST_GO_ROOT)" \
>  	GOPATH="$(HOST_GO_GOPATH)" \
> +	GOCACHE="$(HOST_GO_TARGET_CACHE)" \
>  	GOPROXY=off \
>  	PATH=$(BR_PATH) \
>  	GOBIN= \
> @@ -75,7 +76,6 @@ HOST_GO_TARGET_ENV = \
>  	$(HOST_GO_COMMON_ENV) \
>  	GOOS="linux" \
>  	GOARCH=$(GO_GOARCH) \
> -	GOCACHE="$(HOST_GO_TARGET_CACHE)" \
>  	CC="$(TARGET_CC)" \
>  	CXX="$(TARGET_CXX)" \
>  	CGO_CFLAGS="$(TARGET_CFLAGS)" \
> -- 
> 2.30.2
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
Christian Stewart Jan. 16, 2023, 8:36 p.m. UTC | #2
Hi Peter,

Thought this was set already!


On Mon, Jan 16, 2023, 2:52 AM Peter Korsgaard <peter@korsgaard.com> wrote:

> The go mod vendor call in support/download/go-post-process accesses the go
> cache, so pass GOCACHE= in the environment to ensure our cache directory is
> used.
>
> The go cache defaults to ~/.cache/go-build if not set, so this fixes builds
> where that location (or GOCACHE if set in the environment) is not writable:
>
> rm -rf ~/.cache/go-build
> chmod -w ~/.cache
> make docker-compose-source
> ..
> failed to initialize build cache at /home/peko/.cache/go-build: mkdir
> /home/peko/.cache/go-build: permission denied
> make[1]: *** [package/pkg-generic.mk:189:
> /home/peko/source/buildroot/output/build/docker-compose-2.14.0/.stamp_downloaded]
> Error 1
>
> We use two different cache directories for target and host builds, but the
> download/vendoring should be independent of the architecture, so use the
> target variant even for host-only packages for simplicity.
>
> Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
> ---
>  package/go/go.mk | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/package/go/go.mk b/package/go/go.mk
> index d3ed07f03b..c4f72d403c 100644
> --- a/package/go/go.mk
> +++ b/package/go/go.mk
> @@ -25,6 +25,7 @@ HOST_GO_COMMON_ENV = \
>         GOFLAGS=-mod=vendor \
>         GOROOT="$(HOST_GO_ROOT)" \
>         GOPATH="$(HOST_GO_GOPATH)" \
> +       GOCACHE="$(HOST_GO_TARGET_CACHE)" \
>         GOPROXY=off \
>         PATH=$(BR_PATH) \
>         GOBIN= \
> @@ -75,7 +76,6 @@ HOST_GO_TARGET_ENV = \
>         $(HOST_GO_COMMON_ENV) \
>         GOOS="linux" \
>         GOARCH=$(GO_GOARCH) \
> -       GOCACHE="$(HOST_GO_TARGET_CACHE)" \
>         CC="$(TARGET_CC)" \
>         CXX="$(TARGET_CXX)" \
>         CGO_CFLAGS="$(TARGET_CFLAGS)" \
> --
> 2.30.2
>


Reviewed-by: Christian Stewart <christian@paral.in>

>
>
Peter Korsgaard Jan. 16, 2023, 8:56 p.m. UTC | #3
>>>>> "Christian" == Christian Stewart <christian@paral.in> writes:

 > Hi Peter,
 > Thought this was set already!

It is for the build step - but not for the download step, so we can end
up in problems with the go mod vendor call in the download post-process.
Peter Korsgaard Jan. 17, 2023, 9:27 a.m. UTC | #4
>>>>> "Peter" == Peter Korsgaard <peter@korsgaard.com> writes:

 > The go mod vendor call in support/download/go-post-process accesses the go
 > cache, so pass GOCACHE= in the environment to ensure our cache directory is
 > used.

 > The go cache defaults to ~/.cache/go-build if not set, so this fixes builds
 > where that location (or GOCACHE if set in the environment) is not writable:

 > rm -rf ~/.cache/go-build
 > chmod -w ~/.cache
 > make docker-compose-source
 > ..
 > failed to initialize build cache at /home/peko/.cache/go-build: mkdir /home/peko/.cache/go-build: permission denied
 > make[1]: *** [package/pkg-generic.mk:189:
 > /home/peko/source/buildroot/output/build/docker-compose-2.14.0/.stamp_downloaded]
 > Error 1

 > We use two different cache directories for target and host builds, but the
 > download/vendoring should be independent of the architecture, so use the
 > target variant even for host-only packages for simplicity.

 > Signed-off-by: Peter Korsgaard <peter@korsgaard.com>

Committed to 2022.11.x and 2022.02.x, thanks.
diff mbox series

Patch

diff --git a/package/go/go.mk b/package/go/go.mk
index d3ed07f03b..c4f72d403c 100644
--- a/package/go/go.mk
+++ b/package/go/go.mk
@@ -25,6 +25,7 @@  HOST_GO_COMMON_ENV = \
 	GOFLAGS=-mod=vendor \
 	GOROOT="$(HOST_GO_ROOT)" \
 	GOPATH="$(HOST_GO_GOPATH)" \
+	GOCACHE="$(HOST_GO_TARGET_CACHE)" \
 	GOPROXY=off \
 	PATH=$(BR_PATH) \
 	GOBIN= \
@@ -75,7 +76,6 @@  HOST_GO_TARGET_ENV = \
 	$(HOST_GO_COMMON_ENV) \
 	GOOS="linux" \
 	GOARCH=$(GO_GOARCH) \
-	GOCACHE="$(HOST_GO_TARGET_CACHE)" \
 	CC="$(TARGET_CC)" \
 	CXX="$(TARGET_CXX)" \
 	CGO_CFLAGS="$(TARGET_CFLAGS)" \