aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/load/pkg.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2022-11-29 15:43:08 -0500
committerRuss Cox <rsc@golang.org>2023-02-23 10:55:13 +0000
commitd54aeeeea3327a760856fdc280c742b853684f47 (patch)
tree87a5ba23082cc38e7d592e8b6b24b630fb8c2bab /src/cmd/go/internal/load/pkg.go
parentbd8ec78b08ead1fb34ec8dc7bc4bf2ff7a9e8b82 (diff)
downloadgo-d54aeeeea3327a760856fdc280c742b853684f47.tar.gz
go-d54aeeeea3327a760856fdc280c742b853684f47.zip
cmd/go: set default GODEBUG for main packages
For #56986, change the go command to compute and set the default GODEBUG settings for each main package, based on the work module's go version and the //go:debug lines in the main package. Change-Id: I2118cf0ae6d981138138661e02120c05af648872 Reviewed-on: https://go-review.googlesource.com/c/go/+/453605 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/go/internal/load/pkg.go')
-rw-r--r--src/cmd/go/internal/load/pkg.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index 11b69cb6f4..2d479561ac 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -58,7 +58,7 @@ type Package struct {
type PackagePublic struct {
// Note: These fields are part of the go command's public API.
// See list.go. It is okay to add fields, but not to change or
- // remove existing ones. Keep in sync with list.go
+ // remove existing ones. Keep in sync with ../list/list.go
Dir string `json:",omitempty"` // directory containing package sources
ImportPath string `json:",omitempty"` // import path of package in dir
ImportComment string `json:",omitempty"` // path in import comment on package statement
@@ -79,6 +79,8 @@ type PackagePublic struct {
BinaryOnly bool `json:",omitempty"` // package cannot be recompiled
Incomplete bool `json:",omitempty"` // was there an error loading this package or dependencies?
+ DefaultGODEBUG string `json:",omitempty"` // default GODEBUG setting (only for Name=="main")
+
// Stale and StaleReason remain here *only* for the list command.
// They are only initialized in preparation for list execution.
// The regular build determines staleness on the fly during action execution.
@@ -230,9 +232,6 @@ type PackageInternal struct {
TestmainGo *[]byte // content for _testmain.go
Embed map[string][]string // //go:embed comment mapping
OrigImportPath string // original import path before adding '_test' suffix
- Directives []build.Directive
- TestDirectives []build.Directive
- XTestDirectives []build.Directive
Asmflags []string // -asmflags for this package
Gcflags []string // -gcflags for this package
@@ -438,9 +437,6 @@ func (p *Package) copyBuild(opts PackageOpts, pp *build.Package) {
p.TestEmbedPatterns = pp.TestEmbedPatterns
p.XTestEmbedPatterns = pp.XTestEmbedPatterns
p.Internal.OrigImportPath = pp.ImportPath
- p.Internal.Directives = pp.Directives
- p.Internal.TestDirectives = pp.TestDirectives
- p.Internal.XTestDirectives = pp.XTestDirectives
}
// A PackageError describes an error loading information about a package.
@@ -1924,6 +1920,7 @@ func (p *Package) load(ctx context.Context, opts PackageOpts, path string, stk *
if cfg.ModulesEnabled {
p.Module = modload.PackageModuleInfo(ctx, pkgPath)
}
+ p.DefaultGODEBUG = defaultGODEBUG(p, nil, nil, nil)
p.EmbedFiles, p.Internal.Embed, err = resolveEmbed(p.Dir, p.EmbedPatterns)
if err != nil {
@@ -2405,6 +2402,9 @@ func (p *Package) setBuildInfo(autoVCS bool) {
if cfg.BuildTrimpath {
appendSetting("-trimpath", "true")
}
+ if p.DefaultGODEBUG != "" {
+ appendSetting("DefaultGODEBUG", p.DefaultGODEBUG)
+ }
cgo := "0"
if cfg.BuildContext.CgoEnabled {
cgo = "1"