// buildRunProgram is the action for running a binary that has already
// been compiled. We ignore exit status.
-func buildRunProgram(b *work.Builder, a *work.Action) error {
+func buildRunProgram(b *work.Builder, ctx context.Context, a *work.Action) error {
cmdline := str.StringList(work.FindExecCmd(), a.Deps[0].Target, a.Args)
if cfg.BuildN || cfg.BuildX {
b.Showcmd("", "%s", strings.Join(cmdline, " "))
}
// builderRunTest is the action for running a test binary.
-func (c *runCache) builderRunTest(b *work.Builder, a *work.Action) error {
+func (c *runCache) builderRunTest(b *work.Builder, ctx context.Context, a *work.Action) error {
if a.Failed {
// We were unable to build the binary.
a.Failed = false
}
// builderCleanTest is the action for cleaning up after a test.
-func builderCleanTest(b *work.Builder, a *work.Action) error {
+func builderCleanTest(b *work.Builder, ctx context.Context, a *work.Action) error {
if cfg.BuildWork {
return nil
}
}
// builderPrintTest is the action for printing a test result.
-func builderPrintTest(b *work.Builder, a *work.Action) error {
+func builderPrintTest(b *work.Builder, ctx context.Context, a *work.Action) error {
clean := a.Deps[0]
run := clean.Deps[0]
if run.TestOutput != nil {
}
// builderNoTest is the action for testing a package with no test files.
-func builderNoTest(b *work.Builder, a *work.Action) error {
+func builderNoTest(b *work.Builder, ctx context.Context, a *work.Action) error {
var stdout io.Writer = os.Stdout
if testJSON {
json := test2json.NewConverter(lockedStdout{}, a.Package.ImportPath, test2json.Timestamp)
}
// printExitStatus is the action for printing the exit status
-func printExitStatus(b *work.Builder, a *work.Action) error {
+func printExitStatus(b *work.Builder, ctx context.Context, a *work.Action) error {
if !testJSON && len(pkgArgs) != 0 {
if base.GetExitStatus() != 0 {
fmt.Println("FAIL")
"bufio"
"bytes"
"container/heap"
+ "context"
"debug/elf"
"encoding/json"
"fmt"
// An Action represents a single action in the action graph.
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
+ 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
triggers []*Action // inverse of deps
desc += "(" + a.Mode + " " + a.Package.Desc() + ")"
}
ctx, span := trace.StartSpan(ctx, desc)
- _ = ctx
- err = a.Func(b, a)
+ err = a.Func(b, ctx, a)
span.Done()
}
if a.json != nil {
// build is the action for building a single package.
// Note that any new influence on this logic must be reported in b.buildActionID above as well.
-func (b *Builder) build(a *Action) (err error) {
+func (b *Builder) build(ctx context.Context, a *Action) (err error) {
p := a.Package
bit := func(x uint32, b bool) uint32 {
// VetExplicit records whether the vet flags were set explicitly on the command line.
var VetExplicit bool
-func (b *Builder) vet(a *Action) error {
+func (b *Builder) vet(ctx context.Context, a *Action) error {
// a.Deps[0] is the build of the package being vetted.
// a.Deps[1] is the build of the "fmt" package.
// link is the action for linking a single command.
// Note that any new influence on this logic must be reported in b.linkActionID above as well.
-func (b *Builder) link(a *Action) (err error) {
+func (b *Builder) link(ctx context.Context, a *Action) (err error) {
if b.useCache(a, b.linkActionID(a), a.Package.Target) || b.IsCmdList {
return nil
}
return
}
-func (b *Builder) installShlibname(a *Action) error {
+func (b *Builder) installShlibname(ctx context.Context, a *Action) error {
if err := allowInstall(a); err != nil {
return err
}
return h.Sum()
}
-func (b *Builder) linkShared(a *Action) (err error) {
+func (b *Builder) linkShared(ctx context.Context, a *Action) (err error) {
if b.useCache(a, b.linkSharedActionID(a), a.Target) || b.IsCmdList {
return nil
}
}
// BuildInstallFunc is the action for installing a single package or executable.
-func BuildInstallFunc(b *Builder, a *Action) (err error) {
+func BuildInstallFunc(b *Builder, ctx context.Context, a *Action) (err error) {
defer func() {
if err != nil && err != errPrintedOutput {
// a.Package == nil is possible for the go install -buildmode=shared
}
// Install the cgo export header file, if there is one.
-func (b *Builder) installHeader(a *Action) error {
+func (b *Builder) installHeader(ctx context.Context, a *Action) error {
src := a.Objdir + "_cgo_install.h"
if _, err := os.Stat(src); os.IsNotExist(err) {
// If the file does not exist, there are no exported