diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index 051b3daef9..0ea0bad9a9 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -525,7 +525,9 @@ // 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. diff --git a/src/cmd/go/internal/generate/generate.go b/src/cmd/go/internal/generate/generate.go index 19597c7a33..f2ae80e5dc 100644 --- a/src/cmd/go/internal/generate/generate.go +++ b/src/cmd/go/internal/generate/generate.go @@ -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) { diff --git a/src/internal/syscall/windows/mksyscall.go b/src/internal/syscall/windows/mksyscall.go index a8edafb3c3..0bf87dc95c 100644 --- a/src/internal/syscall/windows/mksyscall.go +++ b/src/internal/syscall/windows/mksyscall.go @@ -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 diff --git a/src/internal/syscall/windows/registry/mksyscall.go b/src/internal/syscall/windows/registry/mksyscall.go index 077215351e..fa8e27e8ff 100644 --- a/src/internal/syscall/windows/registry/mksyscall.go +++ b/src/internal/syscall/windows/registry/mksyscall.go @@ -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