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 version -m shows that replace directive was ignored #39393

Closed
miquella opened this issue Jun 4, 2020 · 3 comments
Closed

cmd/go: go version -m shows that replace directive was ignored #39393

miquella opened this issue Jun 4, 2020 · 3 comments
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@miquella
Copy link

miquella commented Jun 4, 2020

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

$ go version
go version go1.14.4 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/mark/.cache/chgo/cache/go1.14.4"
GOENV="/home/mark/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mark/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/goroots/go1.14.4"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/goroots/go1.14.4/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/mark/src/testing1/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build605705998=/tmp/go-build -gno-record-gcc-switches"

What did you do?

While attempting to follow the recommended way of tracking tool dependencies for a module, I discovered that the version of the tool installed didn't respect the replace directive in the go.mod file.

go.mod:

module testing

go 1.14

require (
	// …
	k8s.io/code-generator v0.18.0
	// …
)

replace (
	// …
	k8s.io/code-generator => k8s.io/code-generator v0.0.0-20190311093542-50b561225d70
	// …
)

tools.go:

// +build tools

package tools

import (
	_ "k8s.io/code-generator/cmd/deepcopy-gen"
)

With these files in place, I installed the tool via:

$ GOBIN=$PWD/bin go install k8s.io/code-generator/cmd/deepcopy-gen
go: finding module for package k8s.io/klog
go: finding module for package k8s.io/gengo/args
go: finding module for package k8s.io/gengo/examples/deepcopy-gen/generators
go: finding module for package github.com/spf13/pflag
go: downloading k8s.io/gengo v0.0.0-20200518160137-fb547a11e5e0
go: found github.com/spf13/pflag in github.com/spf13/pflag v1.0.5
go: found k8s.io/gengo/args in k8s.io/gengo v0.0.0-20200518160137-fb547a11e5e0
go: found k8s.io/klog in k8s.io/klog v1.0.0
go: downloading golang.org/x/tools v0.0.0-20200505023115-26f46d2f7ef8

Unfortunately, go version -m … indicates that the non-replaced version was installed rather than the replaced version.

What did you expect to see?

$ go version -m bin/deepcopy-gen
bin/deepcopy-gen: go1.14.4
	path	k8s.io/code-generator/cmd/deepcopy-gen
	mod	k8s.io/code-generator	v0.0.0-20190311093542-50b561225d70	h1:lgPp615xLHxN84RBd+viA/oHzJfI0miFYFH4T9wpPQ4=

What did you see instead?

$ go version -m bin/deepcopy-gen
bin/deepcopy-gen: go1.14.4
	path	k8s.io/code-generator/cmd/deepcopy-gen
	mod	k8s.io/code-generator	v0.18.0	h1:0xIRWzym+qMgVpGmLESDeMfz/orwgxwxFFAo1xfGNtQ=
@miquella
Copy link
Author

miquella commented Jun 4, 2020

To confirm that it was actually respecting the base require rather than something else, I tried changing the version to v0.17.0:

module testing

go 1.14

require (
	// …
	k8s.io/code-generator v0.17.0
	// …
)

replace (
	// …
	k8s.io/code-generator => k8s.io/code-generator v0.0.0-20190311093542-50b561225d70
	// …
)

Which produced:

$ go version -m bin/deepcopy-gen
bin/deepcopy-gen: go1.14.4
	path	k8s.io/code-generator/cmd/deepcopy-gen
	mod	k8s.io/code-generator	v0.17.0	

So it is following the require, but appears to be ignoring the replace.

@jayconrod jayconrod changed the title Replace directive ignored during go install cmd/go: go version -m shows that replace directive was ignored Jun 4, 2020
@jayconrod jayconrod added modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 4, 2020
@jayconrod
Copy link
Contributor

Reproduced with Go 1.14.4 but not master. go list -json shows the replacement is applied. Might be an issue with go version -m.

@jayconrod
Copy link
Contributor

Ah, this was fixed in CL 220898, which was a fix for a closely related issue, #37392. The text produced by modload.PackageBuildInfo is reported by both go version -m and runtime/debug.ReadBuildInfo, so these two issues have a common root cause. I'll close this one. Thanks for reporting though!

@golang golang locked and limited conversation to collaborators Jun 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules 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

3 participants