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: go build requires versioned replace directive when replacing a used module with a local path #54264

Open
mlaventure opened this issue Aug 4, 2022 · 1 comment
Labels
GoCommand NeedsInvestigation
Milestone

Comments

@mlaventure
Copy link

@mlaventure mlaventure commented Aug 4, 2022

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

$ go version
go version go1.18.5 linux/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=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mlaventure/.cache/go-build"
GOENV="/home/mlaventure/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/mlaventure/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mlaventure/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.5"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/mlaventure/tmp/go/workspace/realdeal/go.mod"
GOWORK="/home/mlaventure/tmp/go/workspace/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 -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2178506260=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Given the following workspace structure:

~/tmp/go/workspace $ tree
.
├── fubar
│   ├── fubar.go
│   └── go.mod
├── go.work
└── realdeal
    ├── go.mod
    ├── realdeal
    └── realdeal.go

2 directories, 6 files

With the following go.work:

~/tmp/go/workspace $ cat go.work 
go 1.18

use ./fubar
use ./realdeal

replace github.com/foo/fubar   => ./fubar

Build realdeal which depends on fubar:

~/tmp/go/workspace/realdeal $ go build .

What did you expect to see?

Nothing, the build should succeed

What did you see instead?

go: workspace module github.com/foo/fubar is replaced at all versions in the go.work file. To fix, remove the replacement from the go.work file or specify the version at which to replace the module.

Found workaround

The only way I've found to fix this is to update the go.work to be as follow:

~/tmp/go/workspace $ cat go.work 
go 1.18

use ./fubar
use ./realdeal

replace github.com/foo/fubar v0.0.0-00010101000000-000000000000 => ./fubar

This is not needed if a workspace is not used. It also seems to contradict the example from the documentation (https://go.dev/ref/mod#workspaces):

replace (
    golang.org/x/net v1.2.3 => example.com/fork/net v1.4.5
    golang.org/x/net => example.com/fork/net v1.4.5
    golang.org/x/net v1.2.3 => ./fork/net
    golang.org/x/net => ./fork/net
)
@dmitshur dmitshur added NeedsInvestigation GoCommand labels Aug 4, 2022
@dmitshur dmitshur added this to the Backlog milestone Aug 4, 2022
@dmitshur
Copy link
Contributor

@dmitshur dmitshur commented Aug 4, 2022

CC @bcmills, @matloob.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

2 participants