Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: build errors with relative GOMODCACHE #43715

Closed
amazing-gao opened this issue Jan 15, 2021 · 4 comments
Closed

cmd/go: build errors with relative GOMODCACHE #43715

amazing-gao opened this issue Jan 15, 2021 · 4 comments
Milestone

Comments

@amazing-gao
Copy link

@amazing-gao amazing-gao commented Jan 15, 2021

What version of Go are you using (go version)?

$ go version

go version go1.15.6 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/gao/Library/Caches/go-build"
GOENV="/Users/gao/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE="*.amazingao.com"
GOMODCACHE="/Users/gao/.gvm/pkgsets/go1.15.6/global/pkg/mod"
GONOPROXY="*.amazingao.com"
GONOSUMDB="*.amazingao.com"
GOOS="darwin"
GOPATH="/Users/gao/.gvm/pkgsets/go1.15.6/global"
GOPRIVATE="*.amazingao.com"
GOPROXY="https://goproxy.cn,direct"
GOROOT="/Users/gao/.gvm/gos/go1.15.6"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/gao/.gvm/gos/go1.15.6/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/gao/workspaces/gocache/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/gq/62v31qtj0hj8zn8xxzmgzk740000gn/T/go-build789633623=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Use GOMODCACHE to speed up gitlab CICD.

I write a demo project:

.
├── go.mod
├── go.sum
└── main.go

0 directories, 3 files

go.mod

module gocache

go 1.15

require github.com/gin-gonic/gin v1.6.3

main.go

package main

import (
	"github.com/gin-gonic/gin"
)

func main() {
	gin.Default().Run(":8080")
}

go mod tidy

GOMODCACHE=.cache go mod tidy

go build

GOMODCACHE=.cache go build .

What did you expect to see?

build success with GOMODCACHE.

What did you see instead?

build error:

# github.com/go-playground/locales/currency
open .cache/github.com/go-playground/locales@v0.13.0/currency/currency.go: no such file or directory
# github.com/gin-gonic/gin/internal/bytesconv
open .cache/github.com/gin-gonic/gin@v1.6.3/internal/bytesconv/bytesconv.go: no such file or directory
# github.com/gin-gonic/gin/internal/json
open .cache/github.com/gin-gonic/gin@v1.6.3/internal/json/json.go: no such file or directory
# github.com/leodido/go-urn
open .cache/github.com/leodido/go-urn@v1.2.0/machine.go: no such file or directory
# golang.org/x/sys/unix
asm: open .cache/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/asm_darwin_amd64.s: no such file or directory
# github.com/golang/protobuf/proto
open .cache/github.com/golang/protobuf@v1.3.3/proto/clone.go: no such file or directory
# gopkg.in/yaml.v2
open .cache/gopkg.in/yaml.v2@v2.2.8/apic.go: no such file or directory
# github.com/gin-contrib/sse
open .cache/github.com/gin-contrib/sse@v0.1.0/sse-decoder.go: no such file or directory
# github.com/ugorji/go/codec
asm: open .cache/github.com/ugorji/go/codec@v1.1.7/helper.s: no such file or directory
@seankhliao seankhliao changed the title build with GOMODCACHE error cmd/go: build errors with relative GOMODCACHE Jan 15, 2021
@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented Jan 15, 2021

on tip:
GOMODCACHE=$(mktemp -d) works
GOMODCACHE=$(pwd)/.cache works
GOMDOCACHE=.cache doesn't work
GOMODCACHE=../cache (relative to outside current module) doesn;t work

@amazing-gao
Copy link
Author

@amazing-gao amazing-gao commented Jan 15, 2021

on tip:
GOMODCACHE=$(mktemp -d) works
GOMODCACHE=$(pwd)/.cache works
GOMDOCACHE=.cache doesn't work
GOMODCACHE=../cache (relative to outside current module) doesn;t work

Thanks a lot, your tips work fine for me.

@jayconrod jayconrod added this to the Go1.17 milestone Jan 15, 2021
@jayconrod
Copy link
Contributor

@jayconrod jayconrod commented Jan 15, 2021

The go command should reject relative paths in GOMODCACHE. It already rejects relative paths in a couple environment variables (GOBIN and GOCACHE I think). It should probably reject relative paths with a clear message in any environment variable that accepts paths.

cc @bcmills @matloob

@gopherbot
Copy link

@gopherbot gopherbot commented Jan 18, 2021

Change https://golang.org/cl/284432 mentions this issue: cmd/go: reject relative paths in GOMODCACHE environment

@gopherbot gopherbot closed this in 4c1a7ab Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants