package work
import "cmd/go/internal/work"
Index ¶
- Variables
- func AddBuildFlags(cmd *base.Command, mask BuildFlagMask)
- func AddCoverFlags(cmd *base.Command, coverProfileFlag *string)
- func BuildInit()
- func BuildInstallFunc(b *Builder, ctx context.Context, a *Action) (err error)
- func CheckGOOSARCHPair(goos, goarch string) error
- func FindExecCmd() []string
- func InstallPackages(ctx context.Context, patterns []string, pkgs []*load.Package)
- type Action
- func (a *Action) BuildActionID() string
- func (a *Action) BuildContentID() string
- func (a *Action) BuildID() string
- func (a *Action) BuiltTarget() string
- type Actor
- type ActorFunc
- type BuildFlagMask
- type BuildMode
- type Builder
- func NewBuilder(workDir string) *Builder
- func (b *Builder) AutoAction(mode, depMode BuildMode, p *load.Package) *Action
- func (b *Builder) CFlags(p *load.Package) (cppflags, cflags, cxxflags, fflags, ldflags []string, err error)
- func (b *Builder) Close() error
- func (b *Builder) CompileAction(mode, depMode BuildMode, p *load.Package) *Action
- func (b *Builder) Do(ctx context.Context, root *Action)
- func (b *Builder) GccCmd(incdir, workdir string) []string
- func (b *Builder) GxxCmd(incdir, workdir string) []string
- func (b *Builder) LinkAction(mode, depMode BuildMode, p *load.Package) *Action
- func (b *Builder) Mkdir(dir string) error
- func (b *Builder) NewObjdir() string
- func (b *Builder) PkgconfigCmd() string
- func (b *Builder) Showcmd(dir string, format string, args ...any)
- func (b *Builder) Symlink(oldname, newname string) error
- func (b *Builder) VetAction(mode, depMode BuildMode, p *load.Package) *Action
Variables ¶
AllowInstall returns a non-nil error if this invocation of the go command is allowed to install a.Target.
The build of cmd/go running under its own test is forbidden from installing to its original GOROOT. The var is exported so it can be set by TestMain.
var BuildToolchain toolchain = noToolchain{}
var CmdBuild = &base.Command{ UsageLine: "go build [-o output] [build flags] [packages]", Short: "compile packages and dependencies", Long: "" /* 9019 byte string literal not displayed */, }
var CmdInstall = &base.Command{ UsageLine: "go install [build flags] [packages]", Short: "compile and install packages and dependencies", Long: "" /* 2647 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 AddCoverFlags ¶
AddCoverFlags adds coverage-related flags to "cmd". If the CoverageRedesign experiment is enabled, we add -cover{mode,pkg} to the build command and only -coverprofile to the test command. If the CoverageRedesign experiment is disabled, -cover* flags are added only to the test command.
func BuildInit ¶
func BuildInit()
func BuildInstallFunc ¶
BuildInstallFunc is the action for installing a single package or executable.
func CheckGOOSARCHPair ¶
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 ¶
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 Actor Actor // 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 ¶
BuildActionID returns the action ID section of a's build ID.
func (*Action) BuildContentID ¶
BuildContentID returns the content ID section of a's build ID.
func (*Action) BuildID ¶
BuildID returns a's build ID.
func (*Action) BuiltTarget ¶
BuiltTarget returns the actual file that was built. This differs from Target when the result was cached.
type Actor ¶
An Actor runs an action.
type ActorFunc ¶
An ActorFunc is an Actor that calls the function.
func (ActorFunc) Act ¶
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?
type Builder ¶
type Builder struct { WorkDir string // the temporary work directory (ends in filepath.Separator) Print func(args ...any) (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 AllowErrors bool // errors don't immediately exit the program // 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 NewBuilder ¶
NewBuilder returns a new Builder ready for use.
If workDir is the empty string, NewBuilder creates a WorkDir if needed and arranges for it to be removed in case of an unclean exit. The caller must Close the builder explicitly to clean up the WorkDir before a clean exit.
func (*Builder) AutoAction ¶
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) Close ¶
func (*Builder) CompileAction ¶
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 ¶
do runs the action graph rooted at root.
func (*Builder) GccCmd ¶
gccCmd returns a gcc command line prefix defaultCC is defined in zdefaultcc.go, written by cmd/dist.
func (*Builder) GxxCmd ¶
gxxCmd returns a g++ command line prefix defaultCXX is defined in zdefaultcc.go, written by cmd/dist.
func (*Builder) LinkAction ¶
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 ¶
mkdir makes the named directory.
func (*Builder) NewObjdir ¶
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 ¶
PkgconfigCmd returns a pkg-config binary name defaultPkgConfig is defined in zdefaultcc.go, written by cmd/dist.
func (*Builder) Showcmd ¶
showcmd prints the given command to standard output for the implementation of -n or -x.
func (*Builder) Symlink ¶
symlink creates a symlink newname -> oldname.
func (*Builder) VetAction ¶
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.20.10
- Published
- Oct 9, 2023
- Platform
- linux/amd64
- Imports
- 44 packages
- Last checked
- 10 seconds ago –
Tools for package owners.