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

runtime/debug: BuildInfo does not honour replace directives #37392

Closed
myitcv opened this issue Feb 23, 2020 · 5 comments
Closed

runtime/debug: BuildInfo does not honour replace directives #37392

myitcv opened this issue Feb 23, 2020 · 5 comments

Comments

@myitcv
Copy link
Member

@myitcv myitcv commented Feb 23, 2020

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

$ go version
go version devel +1cd724acb6 Tue Feb 18 20:21:35 2020 +0000 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="/tmp/tmp.iN3J3OviqO/bin"
GOCACHE="/home/myitcv/.cache/go-build"
GOENV="/home/myitcv/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/tmp/tmp.YATmfepfQp"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/myitcv/gos"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/tmp.iN3J3OviqO/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-build497027281=/tmp/go-build -gno-record-gcc-switches"

What did you do?

export GOPATH=$(mktemp -d) 
cd $(mktemp -d) 
export GOBIN=$PWD/bin
go mod init example.com/hello
go get -d github.com/myitcvscratch/main1@v0.0.0-20200223195030-0e559444dd31
go install github.com/myitcvscratch/main1
./bin/main1

gives:

Hello

and:

go version -m ./bin/main1

gives:

./bin/main1: devel +1cd724acb6 Tue Feb 18 20:21:35 2020 +0000
        path    github.com/myitcvscratch/main1
        mod     github.com/myitcvscratch/main1  v0.0.0-20200223195030-0e559444dd31      h1:ksuMuyNXJTVEqPoCW7OFo0yey/ijEj3Rxt56WwUPbD4=

Then:

go mod edit -replace=github.com/myitcvscratch/main1=github.com/myitcvscratch/main2@v0.0.0-20200223200030-a2adf1d5f0a7
go install github.com/myitcvscratch/main1
./bin/main1

gives:

Goodbye

But:

go version -m ./bin/main1

gives:

./bin/main1: devel +1cd724acb6 Tue Feb 18 20:21:35 2020 +0000
        path    github.com/myitcvscratch/main1
        mod     github.com/myitcvscratch/main1  v0.0.0-20200223195030-0e559444dd31      h1:ksuMuyNXJTVEqPoCW7OFo0yey/ijEj3Rxt56WwUPbD4=

i.e. the newly built binary does not include any information about the fact that github.com/myitcvscratch/main1 has been replaced, nor is any information about github.com/myitcvscratch/main2 included in the runtime/debug.BuildInfo

What did you expect to see?

Some reflection of the fact that github.com/myitcvscratch/main1 has been replaced with github.com/myitcvscratch/main2 in the runtime/debug.BuildInfo

What did you see instead?

As above

cc @bcmills @jayconrod @hyangah

@bcmills
Copy link
Member

@bcmills bcmills commented Feb 24, 2020

This is closely related to #33975, in that modload.PackageBuildInfo is confusing “the main module” with “the module containing package main”. (There is no point in checking for a replacement for “the main module” because it cannot be replaced. However, we should check for a replacement for the module containing package main, because it is not necessarily the main module proper.)

CC @matloob

@bcmills bcmills added this to the Backlog milestone Feb 24, 2020
@bcmills
Copy link
Member

@bcmills bcmills commented Feb 24, 2020

This turned out to be easy enough to just go ahead and fix.

@bcmills bcmills self-assigned this Feb 24, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Feb 24, 2020

Change https://golang.org/cl/220645 mentions this issue: cmd/go/internal/modload: record the replacement for the module containing package main in BuildInfo

@gopherbot gopherbot closed this in e092fc3 Feb 24, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Feb 24, 2020

Change https://golang.org/cl/220717 mentions this issue: cmd/go: add GOEXE suffix in TestScript/version_replace

@bcmills bcmills reopened this Feb 25, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Feb 25, 2020

Change https://golang.org/cl/220898 mentions this issue: Revert "Revert "cmd/go/internal/modload: record the replacement for the module containing package main in BuildInfo""

@gopherbot gopherbot closed this in 987e4e8 Feb 25, 2020
@bcmills bcmills modified the milestones: Backlog, Go1.15 Feb 25, 2020
@golang golang locked and limited conversation to collaborators Feb 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants