Movatterモバイル変換


[0]ホーム

URL:


constraint

packagestandard library
go1.25.2Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2025 License:BSD-3-ClauseImports:5Imported by:158

Details

Repository

cs.opensource.google/go/go

Links

Documentation

Overview

Package constraint implements parsing and evaluation of build constraint lines.Seehttps://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.Seehttps://golang.org/design/draft-gobuild for details about the “//go:build” syntax.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcGoVersionadded ingo1.21.0

func GoVersion(xExpr)string

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.20GoVersion(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"

funcIsGoBuild

func IsGoBuild(linestring)bool

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.

funcIsPlusBuild

func IsPlusBuild(linestring)bool

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.

funcPlusBuildLines

func PlusBuildLines(xExpr) ([]string,error)

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

typeAndExpr

type AndExpr struct {X, YExpr}

An AndExpr represents the expression X && Y.

func (*AndExpr)Eval

func (x *AndExpr) Eval(ok func(tagstring)bool)bool

func (*AndExpr)String

func (x *AndExpr) String()string

typeExpr

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(tagstring)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.

funcParse

func Parse(linestring) (Expr,error)

Parse parses a single build constraint line of the form “//go:build ...” or “// +build ...”and returns the corresponding boolean expression.

typeNotExpr

type NotExpr struct {XExpr}

A NotExpr represents the expression !X (the negation of X).

func (*NotExpr)Eval

func (x *NotExpr) Eval(ok func(tagstring)bool)bool

func (*NotExpr)String

func (x *NotExpr) String()string

typeOrExpr

type OrExpr struct {X, YExpr}

An OrExpr represents the expression X || Y.

func (*OrExpr)Eval

func (x *OrExpr) Eval(ok func(tagstring)bool)bool

func (*OrExpr)String

func (x *OrExpr) String()string

typeSyntaxError

type SyntaxError struct {Offsetint// byte offset in input where error was detectedErrstring// description of error}

A SyntaxError reports a syntax error in a parsed build expression.

func (*SyntaxError)Error

func (e *SyntaxError) Error()string

typeTagExpr

type TagExpr struct {Tagstring// for example, “linux” or “cgo”}

A TagExpr is anExpr for the single tag Tag.

func (*TagExpr)Eval

func (x *TagExpr) Eval(ok func(tagstring)bool)bool

func (*TagExpr)String

func (x *TagExpr) String()string

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp