]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: set the "generate" build tag in go generate, per design doc
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 8 May 2019 21:28:14 +0000 (21:28 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 8 May 2019 23:13:44 +0000 (23:13 +0000)
And use it in two internal windows packages, so they don't show up in
"go list std" or binary releases on non-Windows platforms.

Fixes #31920

Change-Id: Iaa292b6015c9d7310dd677c9e296006440ba5e27
Reviewed-on: https://go-review.googlesource.com/c/go/+/175983
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/alldocs.go
src/cmd/go/internal/generate/generate.go
src/internal/syscall/windows/mksyscall.go
src/internal/syscall/windows/registry/mksyscall.go

index 051b3daef9eaaeec42ba455e8adec1ed431eb1ca..0ea0bad9a91676e3c4e1027417427bc7a15a1ac9 100644 (file)
 // they are treated as a single package. Within a package, generate processes the
 // source files in a package in file name order, one at a time. Within
 // a source file, generate runs generators in the order they appear
-// in the file, one at a time.
+// in the file, one at a time. The go generate tool also sets the build
+// tag "generate" so that files may be examined by go generate but ignored
+// during build.
 //
 // If any generator returns an error exit status, "go generate" skips
 // all further processing for that package.
index 19597c7a3386b6754c24c8bb8b236f3c95bd5abf..f2ae80e5dc68f5e2764c07e6f2226fba743108ee 100644 (file)
@@ -114,7 +114,9 @@ one at a time. If the command line lists .go files from a single directory,
 they are treated as a single package. Within a package, generate processes the
 source files in a package in file name order, one at a time. Within
 a source file, generate runs generators in the order they appear
-in the file, one at a time.
+in the file, one at a time. The go generate tool also sets the build
+tag "generate" so that files may be examined by go generate but ignored
+during build.
 
 If any generator returns an error exit status, "go generate" skips
 all further processing for that package.
@@ -161,6 +163,9 @@ func runGenerate(cmd *base.Command, args []string) {
                        log.Fatalf("generate: %s", err)
                }
        }
+
+       cfg.BuildContext.BuildTags = append(cfg.BuildContext.BuildTags, "generate")
+
        // Even if the arguments are .go files, this loop suffices.
        printed := false
        for _, pkg := range load.Packages(args) {
index a8edafb3c3b5aec036e4f34ede3532ad8e57f373..0bf87dc95c272b0d70a8bad3c733744a2eac964d 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build generate
+
 package windows
 
 //go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zsyscall_windows.go syscall_windows.go security_windows.go psapi_windows.go symlink_windows.go
index 077215351ef5bcaf0f1b24475ffcbebd6ea33b8b..fa8e27e8ff69bb8dfb3323a09e1acbf8ecb4dbea 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build generate
+
 package registry
 
 //go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zsyscall_windows.go syscall.go