Documentation
ยถ
Overview ยถ
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.
Index ยถ
Constants ยถ
This section is empty.
Variables ยถ
This section is empty.
Functions ยถ
func GoVersion ยถ added in go1.21.0
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"
func IsGoBuild ยถ
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.
func IsPlusBuild ยถ
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.
func PlusBuildLines ยถ
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.
Types ยถ
type Expr ยถ
type Expr interface {
// String returns the string form of the expression,
// using the boolean syntax used in //go:build lines.
String() string
// 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.
Eval(ok func(tag string) bool) bool
// contains filtered or unexported methods
}
An Expr is a build tag constraint expression. The underlying concrete type is *AndExpr, *OrExpr, *NotExpr, or *TagExpr.
type NotExpr ยถ
type NotExpr struct {
X Expr
}
A NotExpr represents the expression !X (the negation of X).
type SyntaxError ยถ
type SyntaxError struct {
Offset int // byte offset in input where error was detected
Err string // description of error
}
A SyntaxError reports a syntax error in a parsed build expression.
func (*SyntaxError) Error ยถ
func (e *SyntaxError) Error() string