1
0
mirror of https://github.com/golang/go synced 2024-11-18 09:14:43 -07:00

cmd/go: record the -buildmode flag in debug.BuildInfo

Fixes #53856

Change-Id: Ib533e9fbe063b74c81f6512464a4dac5e2af0ccc
GitHub-Last-Rev: c2ae8d6f75
GitHub-Pull-Request: golang/go#54218
Reviewed-on: https://go-review.googlesource.com/c/go/+/420937
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: xie cui <523516579@qq.com>
This commit is contained in:
cuiweixie 2022-09-08 02:18:50 +00:00 committed by Gopher Robot
parent b244b89d56
commit 59ba97bf3b
3 changed files with 16 additions and 3 deletions

View File

@ -2342,6 +2342,15 @@ func (p *Package) setBuildInfo(autoVCS bool) {
if BuildAsmflags.present {
appendSetting("-asmflags", BuildAsmflags.String())
}
buildmode := cfg.BuildBuildmode
if buildmode == "default" {
if p.Name == "main" {
buildmode = "exe"
} else {
buildmode = "archive"
}
}
appendSetting("-buildmode", buildmode)
appendSetting("-compiler", cfg.BuildContext.Compiler)
if gccgoflags := BuildGccgoflags.String(); gccgoflags != "" && cfg.BuildContext.Compiler == "gccgo" {
appendSetting("-gccgoflags", gccgoflags)

View File

@ -14,7 +14,7 @@ go build -o a.exe a.go
go version -m a.exe
stdout '^\tpath\tcommand-line-arguments$'
stdout '^\tdep\ta\t\(devel\)\t$'
! stdout mod
! stdout mod[^e]
-- a/go.mod --
module a

View File

@ -32,15 +32,17 @@ go build -o fortune.exe rsc.io/fortune
go version fortune.exe
stdout '^fortune.exe: .+'
go version -m fortune.exe
stdout -buildmode=exe
stdout '^\tpath\trsc.io/fortune'
stdout '^\tmod\trsc.io/fortune\tv1.0.0'
# Check the build info of a binary built from $GOROOT/src/cmd
go build -o test2json.exe cmd/test2json
go version -m test2json.exe
stdout -buildmode=exe
stdout '^test2json.exe: .+'
stdout '^\tpath\tcmd/test2json$'
! stdout 'mod'
! stdout 'mod[^e]'
# Repeat the test with -buildmode=pie.
[!buildmode:pie] stop
@ -48,6 +50,7 @@ go build -buildmode=pie -o external.exe rsc.io/fortune
go version external.exe
stdout '^external.exe: .+'
go version -m external.exe
stdout -buildmode=pie
stdout '^\tpath\trsc.io/fortune'
stdout '^\tmod\trsc.io/fortune\tv1.0.0'
@ -59,6 +62,7 @@ go build -buildmode=pie -ldflags=-linkmode=internal -o internal.exe rsc.io/fortu
go version internal.exe
stdout '^internal.exe: .+'
go version -m internal.exe
stdout -buildmode=pie
stdout '^\tpath\trsc.io/fortune'
stdout '^\tmod\trsc.io/fortune\tv1.0.0'
@ -67,4 +71,4 @@ module m
-- empty.go --
package main
func main(){}
func main(){}