package constraint
import "go/build/constraint"
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 ¶
- func IsGoBuild(line string) bool
- func IsPlusBuild(line string) bool
- func PlusBuildLines(x Expr) ([]string, error)
- type AndExpr
- type Expr
- type NotExpr
- type OrExpr
- type SyntaxError
- type TagExpr
Functions ¶
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 AndExpr ¶
type AndExpr struct { X, Y Expr }
An AndExpr represents the expression X && Y.
func (*AndExpr) Eval ¶
func (*AndExpr) String ¶
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.
func Parse ¶
Parse parses a single build constraint line of the form “//go:build ...” or “// +build ...” and returns the corresponding boolean expression.
type NotExpr ¶
type NotExpr struct { X Expr }
A NotExpr represents the expression !X (the negation of X).
func (*NotExpr) Eval ¶
func (*NotExpr) String ¶
type OrExpr ¶
type OrExpr struct { X, Y Expr }
An OrExpr represents the expression X || Y.
func (*OrExpr) Eval ¶
func (*OrExpr) String ¶
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
type TagExpr ¶
type TagExpr struct { Tag string // for example, “linux” or “cgo” }
A TagExpr is an Expr for the single tag Tag.
func (*TagExpr) Eval ¶
func (*TagExpr) String ¶
Source Files ¶
- Version
- v1.19.9
- Published
- Apr 26, 2023
- Platform
- linux/amd64
- Imports
- 4 packages
- Last checked
- 2 seconds ago –
Tools for package owners.