]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add 'go help buildconstraint'
authorMichał Łowicki <mlowicki@gmail.com>
Sat, 11 Apr 2020 21:24:37 +0000 (22:24 +0100)
committerJay Conrod <jayconrod@google.com>
Fri, 1 May 2020 15:02:30 +0000 (15:02 +0000)
Fixes #37018

Change-Id: I1d32c1cb432bc2d7a4d8d6b5c3a54fee558141ec
Reviewed-on: https://go-review.googlesource.com/c/go/+/228017
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/alldocs.go
src/cmd/go/internal/help/help.go
src/cmd/go/internal/help/helpdoc.go
src/cmd/go/main.go

index d6725a63ba54318f9997bfc9de97db0486ebe7d6..8fe48810e4e36af19464be7a416e6e3de1df34de 100644 (file)
 //
 // Additional help topics:
 //
-//     buildmode   build modes
-//     c           calling between Go and C
-//     cache       build and test caching
-//     environment environment variables
-//     filetype    file types
-//     go.mod      the go.mod file
-//     gopath      GOPATH environment variable
-//     gopath-get  legacy GOPATH go get
-//     goproxy     module proxy protocol
-//     importpath  import path syntax
-//     modules     modules, module versions, and more
-//     module-get  module-aware go get
-//     module-auth module authentication using go.sum
-//     module-private module configuration for non-public modules
-//     packages    package lists and patterns
-//     testflag    testing flags
-//     testfunc    testing functions
+//     buildconstraint build constraints
+//     buildmode       build modes
+//     c               calling between Go and C
+//     cache           build and test caching
+//     environment     environment variables
+//     filetype        file types
+//     go.mod          the go.mod file
+//     gopath          GOPATH environment variable
+//     gopath-get      legacy GOPATH go get
+//     goproxy         module proxy protocol
+//     importpath      import path syntax
+//     modules         modules, module versions, and more
+//     module-get      module-aware go get
+//     module-auth     module authentication using go.sum
+//     module-private  module configuration for non-public modules
+//     packages        package lists and patterns
+//     testflag        testing flags
+//     testfunc        testing functions
 //
 // Use "go help <topic>" for more information about that topic.
 //
 // See also: go fmt, go fix.
 //
 //
+// Build constraints
+//
+// Build constraints describe the conditions under which each source file
+// should be included in the corresponding package. Build constraints
+// for a given source file may be added by build constraint comments
+// within the file, or by specific patterns in the file's name.
+//
+// A build constraint comment appears before the file's package clause and
+// must be separated from the package clause by at least one blank line.
+// The comment begins with:
+//
+//     // +build
+//
+// and follows with a space-separated list of options on the same line.
+// The constraint is evaluated as the OR of the options.
+// Each option evaluates as the AND of its comma-separated terms.
+// Each term consists of letters, digits, underscores, and dots.
+// Each term may be negated with a leading exclamation point.
+//
+// For example, the build constraint:
+//
+//     // +build linux,386 darwin,!cgo arm
+//
+// corresponds to boolean formula:
+//
+//     (linux AND 386) OR (darwin AND NOT cgo) OR arm
+//
+// During a particular build, the following terms are satisfied:
+// - the target operating system and architecture, as spelled by
+//   runtime.GOOS and runtime.GOARCH respectively
+// - the compiler being used, either "gc" or "gccgo"
+// - "cgo", if the cgo command is supported
+//   (see CGO_ENABLED in 'go help environment')
+// - a term for each Go major release, through the current version:
+//   "go1.1" from Go version 1.1 onward,
+//   "go1.2" from Go version 1.2 onward, and so on
+// - and any additional tags given by the '-tags' flag (see 'go help build').
+//
+// An additional build constraint may be derived from the source file name.
+// If a file's name, after stripping the extension and a possible _test suffix,
+// matches the patterns *_GOOS, *_GOARCH, or *_GOOS_GOARCH for any known
+// GOOS or GOARCH value, then the file is implicitly constrained to that
+// specific GOOS and/or GOARCH, in addition to any other build constraints
+// declared as comments within the file.
+//
+// For example, the file:
+//
+//     source_windows_amd64.go
+//
+// is implicitly constrained to windows / amd64.
+//
+// See 'go doc go/build' for more details.
+//
+//
 // Build modes
 //
 // The 'go build' and 'go install' commands take a -buildmode argument which
index edb4a2a23caa838d4320dbc2ddf541776ca2cc5b..7a730fc8eb8c5e5255c6121b8b26d81ba9b6ba99 100644 (file)
@@ -93,7 +93,7 @@ Use "go help{{with .LongName}} {{.}}{{end}} <command>" for more information abou
 {{if eq (.UsageLine) "go"}}
 Additional help topics:
 {{range .Commands}}{{if and (not .Runnable) (not .Commands)}}
-       {{.Name | printf "%-11s"}} {{.Short}}{{end}}{{end}}
+       {{.Name | printf "%-15s"}} {{.Short}}{{end}}{{end}}
 
 Use "go help{{with .LongName}} {{.}}{{end}} <topic>" for more information about that topic.
 {{end}}
index 4093e40f26a8f0bd2904980d10b14b7dc53ba1e2..693de8ff49de5e954863bd0d13123fc12f077bb2 100644 (file)
@@ -765,3 +765,60 @@ GODEBUG=gocachetest=1 causes the go command to print details of its
 decisions about whether to reuse a cached test result.
 `,
 }
+
+var HelpBuildConstraint = &base.Command{
+       UsageLine: "buildconstraint",
+       Short:     "build constraints",
+       Long: `
+Build constraints describe the conditions under which each source file
+should be included in the corresponding package. Build constraints
+for a given source file may be added by build constraint comments
+within the file, or by specific patterns in the file's name.
+
+A build constraint comment appears before the file's package clause and
+must be separated from the package clause by at least one blank line.
+The comment begins with:
+
+       // +build
+
+and follows with a space-separated list of options on the same line.
+The constraint is evaluated as the OR of the options.
+Each option evaluates as the AND of its comma-separated terms.
+Each term consists of letters, digits, underscores, and dots.
+Each term may be negated with a leading exclamation point.
+
+For example, the build constraint:
+
+       // +build linux,386 darwin,!cgo arm
+
+corresponds to boolean formula:
+
+       (linux AND 386) OR (darwin AND NOT cgo) OR arm
+
+During a particular build, the following terms are satisfied:
+- the target operating system and architecture, as spelled by
+  runtime.GOOS and runtime.GOARCH respectively
+- the compiler being used, either "gc" or "gccgo"
+- "cgo", if the cgo command is supported
+  (see CGO_ENABLED in 'go help environment')
+- a term for each Go major release, through the current version:
+  "go1.1" from Go version 1.1 onward,
+  "go1.2" from Go version 1.2 onward, and so on
+- and any additional tags given by the '-tags' flag (see 'go help build').
+
+An additional build constraint may be derived from the source file name.
+If a file's name, after stripping the extension and a possible _test suffix,
+matches the patterns *_GOOS, *_GOARCH, or *_GOOS_GOARCH for any known
+GOOS or GOARCH value, then the file is implicitly constrained to that
+specific GOOS and/or GOARCH, in addition to any other build constraints
+declared as comments within the file.
+
+For example, the file:
+
+       source_windows_amd64.go
+
+is implicitly constrained to windows / amd64.
+
+See 'go doc go/build' for more details.
+`,
+}
index 2112defa6a5b6097b4b3b99b0b79c09d401ede12..fdf49b7380e1076107ec91f7cea08e045e5238f5 100644 (file)
@@ -59,6 +59,7 @@ func init() {
                version.CmdVersion,
                vet.CmdVet,
 
+               help.HelpBuildConstraint,
                help.HelpBuildmode,
                help.HelpC,
                help.HelpCache,