aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/load/pkg.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2022-11-29 13:30:50 -0500
committerRuss Cox <rsc@golang.org>2023-02-23 10:10:21 +0000
commitbd8ec78b08ead1fb34ec8dc7bc4bf2ff7a9e8b82 (patch)
treea9a2e48a8fd8551cbc3fc39dc91a6ae8e0682f50 /src/cmd/go/internal/load/pkg.go
parentf07fafacef04e8a8eaf2c8d2e1a14dc88e8683ee (diff)
downloadgo-bd8ec78b08ead1fb34ec8dc7bc4bf2ff7a9e8b82.tar.gz
go-bd8ec78b08ead1fb34ec8dc7bc4bf2ff7a9e8b82.zip
cmd/go, go/build: parse directives in file headers
For #56986, go/build needs to report up to cmd/go about //go:debug lines found in the source code. Rather than make a special case for //go:debug, this change gathers all top-level directives above the package line and includes them in the result. The go command's module index must match go/build, so this CL contains the code to update the index as well. A future CL will use the //go:debug lines to prepare the default GODEBUG settings, as well as rejecting such lines in non-main packages. Change-Id: I66ab8dc72f9cd65c503b10b744367caca233f8a6 Reviewed-on: https://go-review.googlesource.com/c/go/+/453603 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Russ Cox <rsc@golang.org> 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.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index 7c0c104883..11b69cb6f4 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -230,6 +230,9 @@ 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
@@ -435,6 +438,9 @@ 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.