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

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

Fixes #53856

Change-Id: Ib533e9fbe063b74c81f6512464a4dac5e2af0ccc
GitHub-Last-Rev: 5df0f63545d40d0f1c4713fa34e8ec3f1c598038
GitHub-Pull-Request: golang/go#54218
This commit is contained in:
cuiweixie 2022-08-13 05:55:05 +00:00
parent 2f6783c098
commit c2ae8d6f75
3 changed files with 16 additions and 3 deletions

View File

@ -2346,6 +2346,15 @@ func (p *Package) setBuildInfo(includeVCS 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(){}