package work

import "cmd/go/internal/work"

Index

Constants

const ArgLengthForResponseFile = (30 << 10)

Windows has a limit of 32 KB arguments. To be conservative and not worry about whether that includes spaces or not, just use 30 KB. Darwin's limit is less clear. The OS claims 256KB, but we've seen failures with arglen as small as 50KB.

Variables

var BuildToolchain toolchain = noToolchain{}
var CmdBuild = &base.Command{
	UsageLine: "go build [-o output] [build flags] [packages]",
	Short:     "compile packages and dependencies",
	Long:      "" /* 7463 byte string literal not displayed */,
}
var CmdInstall = &base.Command{
	UsageLine: "go install [build flags] [packages]",
	Short:     "compile and install packages and dependencies",
	Long:      "" /* 2398 byte string literal not displayed */,
}
var ExecCmd []string

ExecCmd is the command to use to run user binaries. Normally it is empty, meaning run the binaries directly. If cross-compiling and running on a remote system or simulator, it is typically go_GOOS_GOARCH_exec, with the target GOOS and GOARCH substituted. The -exec flag overrides these defaults.

var GccgoName, GccgoBin string
var VetExplicit bool

VetExplicit records whether the vet flags were set explicitly on the command line.

var VetFlags []string

VetFlags are the default flags to pass to vet. The caller is expected to set them before executing any vet actions.

var VetTool string

VetTool is the path to an alternate vet tool binary. The caller is expected to set it (if needed) before executing any vet actions.

Functions

func AddBuildFlags

func AddBuildFlags(cmd *base.Command, mask BuildFlagMask)

AddBuildFlags adds the flags common to the build, clean, get, install, list, run, and test commands.

func BuildInit

func BuildInit()

func BuildInstallFunc

func BuildInstallFunc(b *Builder, ctx context.Context, a *Action) (err error)

BuildInstallFunc is the action for installing a single package or executable.

func CheckGOOSARCHPair

func CheckGOOSARCHPair(goos, goarch string) error

func FindExecCmd

func FindExecCmd() []string

FindExecCmd derives the value of ExecCmd to use. It returns that value and leaves ExecCmd set for direct use.

func InstallPackages

func InstallPackages(ctx context.Context, patterns []string, pkgs []*load.Package)

Types

type Action

type Action struct {
	Mode       string                                         // description of action operation
	Package    *load.Package                                  // the package this action works on
	Deps       []*Action                                      // actions that must happen before this one
	Func       func(*Builder, context.Context, *Action) error // the action itself (nil = no-op)
	IgnoreFail bool                                           // whether to run f even if dependencies fail
	TestOutput *bytes.Buffer                                  // test output buffer
	Args       []string                                       // additional args for runProgram

	TryCache func(*Builder, *Action) bool // callback for cache bypass

	// Generated files, directories.
	Objdir string // directory for intermediate objects
	Target string // goal of the action: the created package or executable

	VetxOnly bool // Mode=="vet": only being called to supply info about dependencies

	Failed bool // whether the action failed
	// contains filtered or unexported fields
}

An Action represents a single action in the action graph.

func (*Action) BuildActionID

func (a *Action) BuildActionID() string

BuildActionID returns the action ID section of a's build ID.

func (*Action) BuildContentID

func (a *Action) BuildContentID() string

BuildContentID returns the content ID section of a's build ID.

func (*Action) BuildID

func (a *Action) BuildID() string

BuildID returns a's build ID.

func (*Action) BuiltTarget

func (a *Action) BuiltTarget() string

BuiltTarget returns the actual file that was built. This differs from Target when the result was cached.

type BuildFlagMask

type BuildFlagMask int
const (
	DefaultBuildFlags BuildFlagMask = 0
	OmitModFlag       BuildFlagMask = 1 << iota
	OmitModCommonFlags
	OmitVFlag
)

type BuildMode

type BuildMode int

BuildMode specifies the build mode: are we just building things or also installing the results?

const (
	ModeBuild BuildMode = iota
	ModeInstall
	ModeBuggyInstall

	ModeVetOnly = 1 << 8
)

type Builder

type Builder struct {
	WorkDir string // the temporary work directory (ends in filepath.Separator)

	Print func(args ...interface{}) (int, error)

	IsCmdList           bool // running as part of go list; set p.Stale and additional fields below
	NeedError           bool // list needs p.Error
	NeedExport          bool // list needs p.Export
	NeedCompiledGoFiles bool // list needs p.CompiledGoFiles
	// contains filtered or unexported fields
}

A Builder holds global state about a build. It does not hold per-package state, because we build packages in parallel, and the builder is shared.

func (*Builder) AutoAction

func (b *Builder) AutoAction(mode, depMode BuildMode, p *load.Package) *Action

AutoAction returns the "right" action for go build or go install of p.

func (*Builder) CFlags

func (b *Builder) CFlags(p *load.Package) (cppflags, cflags, cxxflags, fflags, ldflags []string, err error)

CFlags returns the flags to use when invoking the C, C++ or Fortran compilers, or cgo.

func (*Builder) CompileAction

func (b *Builder) CompileAction(mode, depMode BuildMode, p *load.Package) *Action

CompileAction returns the action for compiling and possibly installing (according to mode) the given package. The resulting action is only for building packages (archives), never for linking executables. depMode is the action (build or install) to use when building dependencies. To turn package main into an executable, call b.Link instead.

func (*Builder) Do

func (b *Builder) Do(ctx context.Context, root *Action)

do runs the action graph rooted at root.

func (*Builder) GccCmd

func (b *Builder) GccCmd(incdir, workdir string) []string

gccCmd returns a gcc command line prefix defaultCC is defined in zdefaultcc.go, written by cmd/dist.

func (*Builder) GxxCmd

func (b *Builder) GxxCmd(incdir, workdir string) []string

gxxCmd returns a g++ command line prefix defaultCXX is defined in zdefaultcc.go, written by cmd/dist.

func (*Builder) Init

func (b *Builder) Init()

func (*Builder) LinkAction

func (b *Builder) LinkAction(mode, depMode BuildMode, p *load.Package) *Action

LinkAction returns the action for linking p into an executable and possibly installing the result (according to mode). depMode is the action (build or install) to use when compiling dependencies.

func (*Builder) Mkdir

func (b *Builder) Mkdir(dir string) error

mkdir makes the named directory.

func (*Builder) NewObjdir

func (b *Builder) NewObjdir() string

NewObjdir returns the name of a fresh object directory under b.WorkDir. It is up to the caller to call b.Mkdir on the result at an appropriate time. The result ends in a slash, so that file names in that directory can be constructed with direct string addition.

NewObjdir must be called only from a single goroutine at a time, so it is safe to call during action graph construction, but it must not be called during action graph execution.

func (*Builder) PkgconfigCmd

func (b *Builder) PkgconfigCmd() string

PkgconfigCmd returns a pkg-config binary name defaultPkgConfig is defined in zdefaultcc.go, written by cmd/dist.

func (*Builder) Showcmd

func (b *Builder) Showcmd(dir string, format string, args ...interface{})

showcmd prints the given command to standard output for the implementation of -n or -x.

func (b *Builder) Symlink(oldname, newname string) error

symlink creates a symlink newname -> oldname.

func (*Builder) VetAction

func (b *Builder) VetAction(mode, depMode BuildMode, p *load.Package) *Action

VetAction returns the action for running go vet on package p. It depends on the action for compiling p. If the caller may be causing p to be installed, it is up to the caller to make sure that the install depends on (runs after) vet.

Source Files

action.go build.go buildid.go exec.go gc.go gccgo.go init.go security.go

Version
v1.16.11
Published
Dec 2, 2021
Platform
linux/amd64
Imports
43 packages
Last checked
3 seconds ago

Tools for package owners.