Go: cmd/go/internal/work Index | Files

package work

import "cmd/go/internal/work"


Package Files

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


var BuildToolchain toolchain = noToolchain{}
var CmdBuild = &base.Command{
    UsageLine: "go build [-o output] [-i] [build flags] [packages]",
    Short:     "compile packages and dependencies",
    Long:      "" /* 6414 byte string literal not displayed */,
var CmdInstall = &base.Command{
    UsageLine: "go install [-i] [build flags] [packages]",
    Short:     "compile and install packages and dependencies",
    Long:      "" /* 760 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.

func AddBuildFlags Uses

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

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

func AddModCommonFlags Uses

func AddModCommonFlags(cmd *base.Command)

AddModCommonFlags adds the module-related flags common to build commands and 'go mod' subcommands.

func BuildInit Uses

func BuildInit()

func BuildInstallFunc Uses

func BuildInstallFunc(b *Builder, a *Action) (err error)

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

func CheckGOOSARCHPair Uses

func CheckGOOSARCHPair(goos, goarch string) error

func FindExecCmd Uses

func FindExecCmd() []string

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

func InstallPackages Uses

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

type Action Uses

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, *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 Uses

func (a *Action) BuildActionID() string

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

func (*Action) BuildContentID Uses

func (a *Action) BuildContentID() string

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

func (*Action) BuildID Uses

func (a *Action) BuildID() string

BuildID returns a's build ID.

func (*Action) BuiltTarget Uses

func (a *Action) BuiltTarget() string

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

type BuildFlagMask Uses

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

type BuildMode Uses

type BuildMode int

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

const (
    ModeBuild BuildMode = iota

    ModeVetOnly = 1 << 8

type Builder Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (b *Builder) Do(root *Action)

do runs the action graph rooted at root.

func (*Builder) GccCmd Uses

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 Uses

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 Uses

func (b *Builder) Init()

func (*Builder) LinkAction Uses

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 Uses

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

mkdir makes the named directory.

func (*Builder) NewObjdir Uses

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 Uses

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 Uses

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 Uses

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.

Package work imports 33 packages (graph) and is imported by 44 packages. Updated 2020-12-06. Refresh now. Tools for package owners.