buildutil

package module
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: BSD-3-Clause, MIT Imports: 20 Imported by: 3

README

github-actions GoDoc

buildutil

Package buildutil provides utilities related to the go/build package in the standard library.

Documentation

Overview

Package buildutil exposes some useful internal functions of the go/build.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrImpossibleGoVersion = errors.New("cannot satisfy go version")
	ErrMatchContext        = errors.New("cannot match context to file")
)
View Source
var DefaultGoPlatforms = []GoPlatform{

	{"darwin", "amd64", true, true},
	{"darwin", "arm64", true, true},
	{"linux", "amd64", true, true},
	{"linux", "arm64", true, true},
	{"windows", "amd64", true, true},
	{"windows", "386", true, true},
	{"linux", "arm", true, true},
	{"linux", "386", true, true},

	{"aix", "ppc64", true, false},
	{"android", "386", true, false},
	{"android", "amd64", true, false},
	{"android", "arm", true, false},
	{"android", "arm64", true, false},
	{"dragonfly", "amd64", true, false},
	{"freebsd", "386", true, false},
	{"freebsd", "amd64", true, false},
	{"freebsd", "arm", true, false},
	{"freebsd", "arm64", true, false},
	{"illumos", "amd64", true, false},
	{"ios", "amd64", true, false},
	{"ios", "arm64", true, false},
	{"js", "wasm", false, false},
	{"linux", "loong64", true, false},
	{"linux", "mips", true, false},
	{"linux", "mips64", true, false},
	{"linux", "mips64le", true, false},
	{"linux", "mipsle", true, false},
	{"linux", "ppc64", false, false},
	{"linux", "ppc64le", true, false},
	{"linux", "riscv64", true, false},
	{"linux", "s390x", true, false},
	{"netbsd", "386", true, false},
	{"netbsd", "amd64", true, false},
	{"netbsd", "arm", true, false},
	{"netbsd", "arm64", true, false},
	{"openbsd", "386", true, false},
	{"openbsd", "amd64", true, false},
	{"openbsd", "arm", true, false},
	{"openbsd", "arm64", true, false},
	{"openbsd", "mips64", true, false},
	{"plan9", "386", false, false},
	{"plan9", "amd64", false, false},
	{"plan9", "arm", false, false},
	{"solaris", "amd64", true, false},
	{"windows", "arm", false, false},
	{"windows", "arm64", true, false},
}

DefaultGoPlatforms are the default supported Go platforms and are ordered by preference and "first class" support.

View Source
var PreferredArchList = createPreferredList([]string{
	runtime.GOARCH,
	"amd64",
	"arm64",
	"arm",
	"386",
	"ppc64",
}, func(p *GoPlatform) string { return p.GOARCH })

PreferredArchList is used to pick an Arch (GOARCH) when matching a build.Context to a file.

View Source
var PreferredOSList = createPreferredList([]string{
	runtime.GOOS,
	"darwin",
	"linux",
	"windows",
	"openbsd",
	"freebsd",
	"netbsd",
}, func(p *GoPlatform) string { return p.GOOS })

PreferredArchList is used to pick an OS (GOOS) when matching a build.Context to a file.

Functions

func BuildTags

func BuildTags(name string, content []byte, allTags map[string]bool)

BuildTags adds and build tags found in name or content to allTags.

func GoCommand added in v0.0.3

func GoCommand(ctxt *build.Context, name string, args ...string) *exec.Cmd

GoCommand returns an exec.Cmd for the provided build.Context. The Cmd's env is set to that of the Context. The args contains a "-tags" flag it is updated to match the build constraints of the Context otherwise the "-tags" are provided via the GOFLAGS env var.

func GoCommandContext added in v0.0.4

func GoCommandContext(ctx context.Context, ctxt *build.Context, name string, args ...string) *exec.Cmd

GoCommandContext returns an exec.Cmd for the provided build.Context and context.Context. The Cmd's env is set to that of the Context. The args contains a "-tags" flag it is updated to match the build constraints of the Context otherwise the "-tags" are provided via the GOFLAGS env var.

func GoodOSArchFile

func GoodOSArchFile(ctxt *build.Context, name string, allTags map[string]bool) bool

GoodOSArchFile returns false if the name contains a $GOOS or $GOARCH suffix which does not match the build Context. The recognized name formats are:

name_$(GOOS).*
name_$(GOARCH).*
name_$(GOOS)_$(GOARCH).*
name_$(GOOS)_test.*
name_$(GOARCH)_test.*
name_$(GOOS)_$(GOARCH)_test.*

An exception: if GOOS=android, then files with GOOS=linux are also matched.

func ImportPath

func ImportPath(ctxt *build.Context, dir string) (string, error)

return ctxt.Import(".", dir, mode)

func Include

func Include(ctxt *build.Context, path string) bool

func IncludeTags

func IncludeTags(ctxt *build.Context, path string, tags map[string]bool) (bool, error)

func KnownArchList

func KnownArchList() []string

KnownArchList returns the known architecture values, sorted.

func KnownOSList

func KnownOSList() []string

KnownOSList returns the known operating system values, sorted.

func MatchContext

func MatchContext(orig *build.Context, filename string, src interface{}) (*build.Context, error)

TODO: make sure CGO support is correct for the selected platform.

MatchContext returns a build.Context that would include filename in a build.

func MatchFile added in v0.0.10

func MatchFile(ctxt *build.Context, dir, name string, src interface{}) (pkgName string, match bool, err error)

MatchFile reports whether the file with the given name matches the context and would be included in a Package created by ImportDir. It also returns the package name of the file.

MatchFile considers the name of the file and may use ctxt.OpenFile to read some or all of the file's content. If src is not nil it will be used as the content of the file.

func ReadImports

func ReadImports(path string, src interface{}) (pkgname string, imports []string, err error)

func ReadPackageName

func ReadPackageName(path string, src interface{}) (string, error)

func ReadPackageNameTags

func ReadPackageNameTags(path string, src interface{}, tags map[string]bool) (string, bool, error)

ReadPackageNameTags evaluates the Go source file at path and returns the package name, if it can be used with build.Context ctxt, populates any build tags (if tags is not nil), and any error that occured.

func ShortImport

func ShortImport(ctxt *build.Context, path string) (string, bool)

TODO (CEV): rename

func ShouldBuild

func ShouldBuild(ctxt *build.Context, content []byte, allTags map[string]bool) bool

ShouldBuild reports whether it is okay to use this file, and adds any build tags to allTags.

Note: only +build tags are checked. Syntactically incorrect content may be marked as build-able if no +build tags are present.

Types

type Constraint added in v0.0.11

type Constraint struct {
	// contains filtered or unexported fields
}

A Constraint stores the build constraints of a Go source file and can be used to check if a file matches a build.Context.

A nil Constraint is safe to use and matches any build.Context.

func NewConstraint added in v0.0.11

func NewConstraint(expr constraint.Expr, tags map[string]bool) *Constraint

NewConstraint returns a new Constraint for the given constraint.Expr and build tags. This is a no-op if both expr and tags are nil.

func ParseConstraint added in v0.0.11

func ParseConstraint(ctxt *build.Context, filename string, src interface{}) (*Constraint, error)

ParseConstraint parses the build constraints of a Go source file, if any. The returned Constraint can be used to check if the file matches a build.Context.

func (*Constraint) Empty added in v0.0.11

func (c *Constraint) Empty() bool

Empty returns true if c has no build constraints. An empty Constraint matches all files.

func (*Constraint) Eval added in v0.0.11

func (c *Constraint) Eval(ctxt *build.Context) bool

Eval reports whether build.Context ctxt matches the build constraint.

func (*Constraint) Expr added in v0.0.11

func (c *Constraint) Expr() constraint.Expr

Expr returns the Constraint's constraint.Expr.

type GoPlatform added in v0.0.7

type GoPlatform struct {
	GOOS         string `json:"GOOS"`
	GOARCH       string `json:"GOARCH"`
	CgoSupported bool   `json:"CgoSupported"`
	FirstClass   bool   `json:"FirstClass"`
}

A GoPlatform is a supported GOOS/GOARCH for go and is generated via: `go tool dist list`

func LoadGoPlatforms added in v0.0.7

func LoadGoPlatforms() ([]GoPlatform, error)

LoadGoPlatforms loads the supported platforms supported by the go executable found on the PATH.

type MatchError added in v0.0.7

type MatchError struct {
	Path      string
	Permanent bool // Error cannot be resolved (e.g. compiler mismatch)
	Err       error
}

A MatchError describes an error matching a build.Context to a file.

func (*MatchError) Error added in v0.0.7

func (e *MatchError) Error() string

func (*MatchError) Unwrap added in v0.0.7

func (e *MatchError) Unwrap() error

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL