Skip to content

Commit 4a2a3bc

Browse files
ianlancetaylorgopherbot
authored andcommitted
cmd/go, go/build: clarify build constraint docs
Clarify that the //go:build line is an expression of constraints, not a constraint itself. Fixes #53308 Change-Id: Ib67243c6ee5cfe3b688c12b943b5e7496f686035 Reviewed-on: https://go-review.googlesource.com/c/go/+/411697 Reviewed-by: Rob Pike <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 9a4d535 commit 4a2a3bc

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

src/cmd/go/alldocs.go

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/help/helpdoc.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -812,11 +812,12 @@ var HelpBuildConstraint = &base.Command{
812812
UsageLine: "buildconstraint",
813813
Short: "build constraints",
814814
Long: `
815-
A build constraint, also known as a build tag, is a line comment that begins
815+
A build constraint, also known as a build tag, is a condition under which a
816+
file should be included in the package. Build constraints are given by a
817+
line comment that begins
816818
817819
//go:build
818820
819-
that lists the conditions under which a file should be included in the package.
820821
Constraints may appear in any kind of source file (not just Go), but
821822
they must appear near the top of the file, preceded
822823
only by blank lines and other line comments. These rules mean that in Go
@@ -825,9 +826,9 @@ files a build constraint must appear before the package clause.
825826
To distinguish build constraints from package documentation,
826827
a build constraint should be followed by a blank line.
827828
828-
A build constraint is evaluated as an expression containing options
829-
combined by ||, &&, and ! operators and parentheses. Operators have
830-
the same meaning as in Go.
829+
A build constraint comment is evaluated as an expression containing
830+
build tags combined by ||, &&, and ! operators and parentheses.
831+
Operators have the same meaning as in Go.
831832
832833
For example, the following build constraint constrains a file to
833834
build when the "linux" and "386" constraints are satisfied, or when
@@ -837,7 +838,7 @@ build when the "linux" and "386" constraints are satisfied, or when
837838
838839
It is an error for a file to have more than one //go:build line.
839840
840-
During a particular build, the following words are satisfied:
841+
During a particular build, the following build tags are satisfied:
841842
842843
- the target operating system, as spelled by runtime.GOOS, set with the
843844
GOOS environment variable.

src/cmd/go/internal/work/build.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,10 @@ and test commands:
151151
For example, when building with a non-standard configuration,
152152
use -pkgdir to keep generated packages in a separate location.
153153
-tags tag,list
154-
a comma-separated list of build tags to consider satisfied during the
155-
build. For more information about build tags, see the description of
156-
build constraints in the documentation for the go/build package.
157-
(Earlier versions of Go used a space-separated list, and that form
158-
is deprecated but still recognized.)
154+
a comma-separated list of additional build tags to consider satisfied
155+
during the build. For more information about build tags, see
156+
'go help buildconstraint'. (Earlier versions of Go used a
157+
space-separated list, and that form is deprecated but still recognized.)
159158
-trimpath
160159
remove all file system paths from the resulting executable.
161160
Instead of absolute file system paths, the recorded file names

src/go/build/doc.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@
5757
//
5858
// # Build Constraints
5959
//
60-
// A build constraint, also known as a build tag, is a line comment that begins
60+
// A build constraint, also known as a build tag, is a condition under which a
61+
// file should be included in the package. Build constraints are given by a
62+
// line comment that begins
6163
//
6264
// //go:build
6365
//
64-
// that lists the conditions under which a file should be included in the
65-
// package. Build constraints may also be part of a file's name
66+
// Build constraints may also be part of a file's name
6667
// (for example, source_windows.go will only be included if the target
6768
// operating system is windows).
6869
//

0 commit comments

Comments
 (0)