Skip to content

cmd/go: work use failing with symlinks in the path #68383

Closed
@dgeorgievski

Description

@dgeorgievski

Go version

go version go1.22.0 linux/amd64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/ubuntu/workspace/.cache/go-build'
GOENV='/home/ubuntu/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/ubuntu/workspace/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ubuntu/workspace/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/ubuntu/workspace/Projects/eval/go/patching/go.mod'
GOWORK='/home/ubuntu/workspace/Projects/eval/go/patching/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1646219358=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I was reviewing the suggestions for local patching in this article
https://eli.thegreenplace.net/2024/locally-patching-dependencies-in-go/

Go workspaces was one of the suggestions. I tried the code in path on the local file system accessed through a symlink named Projects and tried to invoke go work use command.

# symlink: Projects -> workspace/Projects/
 $ cd Projects/eval/go/patching/
/home/ubuntu/Projects/eval/go/patching
$ ls -l
total 12
-rw-rw-r-- 1 ubuntu ubuntu  69 Jul 11 14:45 go.mod
-rw-rw-r-- 1 ubuntu ubuntu 167 Jul 11 14:38 go.sum
-rw-rw-r-- 1 ubuntu ubuntu 316 Jul 11 14:38 main.go

$ echo $DEP
/home/ubuntu/temp/go-cmp

$ go work init
$ go work use . $DEP
go: directory ../../../../temp/go-cmp does not exist 

It looks like go work skips one level if a symlink is used

If I don't use the symlink to access the working directory everything works fine

$ cd ~/workspace/Projects/eval/go/patching/
$ go mod init 
$ go work use . $DEP
$ cat go.work
go 1.22.0

use (
        .
        /home/ubuntu/temp/go-cmp
)

What did you see happen?

go mod use fails if I use the symlink to access the working directory.

What did you expect to see?

go mod use to create go.work file and correctly refer the directories with go.mod files

Metadata

Metadata

Assignees

Labels

GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions