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: go work causes go build to error when symlinks are involved #53343

Open
yalon opened this issue Jun 12, 2022 · 6 comments
Open

cmd/go: go work causes go build to error when symlinks are involved #53343

yalon opened this issue Jun 12, 2022 · 6 comments
Labels
GoCommand cmd/go help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@yalon
Copy link

yalon commented Jun 12, 2022

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

$ go version

go version go1.18 darwin/arm64

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=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/testy/Library/Caches/go-build"
GOENV="/Users/testy/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/testy/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/testy/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.18/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.18/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/testy/tmp/x/lib1/lib2/go.mod"
GOWORK="/Users/testy/tmp/x/go.work"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/qr/4s_dq83s1lddgv10vn9591y80000gn/T/go-build3045518203=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

`
mkdir bug
cd bug

mkdir lib1 lib2
cd lib1
go mod init bugsquash.com/lib1
ln -s ../lib2
cd ../lib2
go mod init bugsquash.com/lib2
mkdir -p internal/a
printf "package a\nfunc Foo() {}\n" > internal/a/foo.go
mkdir -p cmd/foo
printf 'package main\nimport "bugsquash.com/lib2/internal/a"\nfunc main() { a.Foo() }\n' > cmd/foo/foo.go
go build cmd/foo/foo.go # succeeds
cd ../lib1/lib2
go build cmd/foo/foo.go # succeeds
cd ../../
go work init
go work use ./lib2
cd lib1/lib2
go build cmd/foo/foo.go

fails with this message:

package command-line-arguments

cmd/foo/foo.go:2:8: use of internal package bugsquash.com/lib2/internal/a not allowed

cd ../../lib2
go build cmd/foo/foo.go # succeeds
cd ../
rm go.work
cd lib1/lib2
go build cmd/foo/foo.go # succeeds
`

What did you expect to see?

I expect go build to succeed in lib1/lib2 (lib2 is a symlink) even when using go.work. If I remove go.work it works.

What did you see instead?

package command-line-arguments cmd/foo/foo.go:2:8: use of internal package bugsquash.com/lib2/internal/a not allowed

@shuLhan

This comment was marked as off-topic.

@shuLhan

This comment was marked as off-topic.

@seankhliao seankhliao added NeedsFix The path to resolution is known, but the work has not been done. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go and removed NeedsFix The path to resolution is known, but the work has not been done. labels Jun 15, 2022
@seankhliao
Copy link
Member

cc @matloob

@seankhliao seankhliao changed the title go work causes go build to error when symlinks are involved cmd/go: go work causes go build to error when symlinks are involved Jun 15, 2022
@bcmills

This comment was marked as off-topic.

@shuLhan

This comment was marked as off-topic.

@bcmills bcmills added this to the Backlog milestone Jun 23, 2022
@quantonganh
Copy link
Contributor

quantonganh commented Nov 3, 2023

├── go.work
├── lib1
│   ├── go.mod
│   └── lib2 -> ../lib2
└── lib2
    ├── cmd
    ├── go.mod
    └── internal

On my system (macOS 12.3), the error is different:

$ go build cmd/foo/foo.go
go: cannot load module ../../lib2 listed in go.work file: open ../../lib2/go.mod: no such file or directory

and IMO, this is... expected:

$ pwd
/path/to/bug/lib1/lib2

$ ls ../../lib2/go.mod
"../../lib2/go.mod": No such file or directory (os error 2)

When you run ls ../ in bug/lib1/lib2, since ls follows symlink by default, this will list files in the bug folder:

$ ls ../
go.work  lib1  lib2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants