package constraint
Import Path
go/build/constraint (on go.dev)
Dependency Relation
imports 5 packages, and imported by 3 packages
Involved Source Files
Package constraint implements parsing and evaluation of build constraint lines.
See https://golang.org/cmd/go/#hdr-Build_constraints for documentation about build constraints themselves.
This package parses both the original “// +build” syntax and the “//go:build” syntax that was added in Go 1.17.
See https://golang.org/design/draft-gobuild for details about the “//go:build” syntax.
vers.go
Package-Level Type Names (total 6)
An AndExpr represents the expression X && Y.
X Expr
Y Expr
(*AndExpr) Eval(ok func(tag string) bool) bool
(*AndExpr) String() string
*AndExpr : Expr
*AndExpr : expvar.Var
*AndExpr : fmt.Stringer
An Expr is a build tag constraint expression.
The underlying concrete type is *[AndExpr], *[OrExpr], *[NotExpr], or *[TagExpr].
Eval reports whether the expression evaluates to true.
It calls ok(tag) as needed to find out whether a given build tag
is satisfied by the current build configuration.
String returns the string form of the expression,
using the boolean syntax used in //go:build lines.
*AndExpr
*NotExpr
*OrExpr
*TagExpr
Expr : expvar.Var
Expr : fmt.Stringer
func Parse(line string) (Expr, error)
func GoVersion(x Expr) string
func PlusBuildLines(x Expr) ([]string, error)
A NotExpr represents the expression !X (the negation of X).
X Expr
(*NotExpr) Eval(ok func(tag string) bool) bool
(*NotExpr) String() string
*NotExpr : Expr
*NotExpr : expvar.Var
*NotExpr : fmt.Stringer
An OrExpr represents the expression X || Y.
X Expr
Y Expr
(*OrExpr) Eval(ok func(tag string) bool) bool
(*OrExpr) String() string
*OrExpr : Expr
*OrExpr : expvar.Var
*OrExpr : fmt.Stringer
Package-Level Functions (total 5)
GoVersion returns the minimum Go version implied by a given build expression.
If the expression can be satisfied without any Go version tags, GoVersion returns an empty string.
For example:
GoVersion(linux && go1.22) = "go1.22"
GoVersion((linux && go1.22) || (windows && go1.20)) = "go1.20" => go1.20
GoVersion(linux) = ""
GoVersion(linux || (windows && go1.22)) = ""
GoVersion(!go1.22) = ""
GoVersion assumes that any tag or negated tag may independently be true,
so that its analysis can be purely structural, without SAT solving.
“Impossible” subexpressions may therefore affect the result.
For example:
GoVersion((linux && !linux && go1.20) || go1.21) = "go1.20"
IsGoBuild reports whether the line of text is a “//go:build” constraint.
It only checks the prefix of the text, not that the expression itself parses.
IsPlusBuild reports whether the line of text is a “// +build” constraint.
It only checks the prefix of the text, not that the expression itself parses.
Parse parses a single build constraint line of the form “//go:build ...” or “// +build ...”
and returns the corresponding boolean expression.
PlusBuildLines returns a sequence of “// +build” lines that evaluate to the build expression x.
If the expression is too complex to convert directly to “// +build” lines, PlusBuildLines returns an error.
The pages are generated with Golds v0.7.0-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |