Skip to content

Commit

Permalink
cmd/go: track root failing Action
Browse files Browse the repository at this point in the history
Currently, each Action tracks whether it failed, which is propagated
up from dependencies. Shortly, we'll need to know the root cause if a
test fails because of a build failure. To support this, replace the
Failed boolean with a Failed *Action that tracks the root Action that
failed and caused other Actions to fail.

For #62067.

Change-Id: I8f84a51067354043ae9531a4368c6f8b11d688d5
Reviewed-on: https://go-review.googlesource.com/c/go/+/536398
Reviewed-by: Russ Cox <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
aclements committed Nov 17, 2024
1 parent 49b3ab0 commit 9060fa5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/cmd/go/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1387,9 +1387,9 @@ func (r *runTestActor) Act(b *work.Builder, ctx context.Context, a *work.Action)
// Release next test to start (test2json.NewConverter writes the start event).
close(r.next)

if a.Failed {
if a.Failed != nil {
// We were unable to build the binary.
a.Failed = false
a.Failed = nil
fmt.Fprintf(stdout, "FAIL\t%s [build failed]\n", a.Package.ImportPath)
// Tell the JSON converter that this was a failure, not a passing run.
err = errors.New("build failed")
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/go/internal/work/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type Action struct {
// Execution state.
pending int // number of deps yet to complete
priority int // relative execution priority
Failed bool // whether the action failed
Failed *Action // set to root cause if the action failed
json *actionJSON // action graph information
nonGoOverlay map[string]string // map from non-.go source files to copied files in objdir. Nil if no overlay is used.
traceSpan *trace.Span
Expand Down Expand Up @@ -218,7 +218,7 @@ func actionGraphJSON(a *Action) string {
Args: a.Args,
Objdir: a.Objdir,
Target: a.Target,
Failed: a.Failed,
Failed: a.Failed != nil,
Priority: a.priority,
Built: a.built,
VetxOnly: a.VetxOnly,
Expand Down
14 changes: 8 additions & 6 deletions src/cmd/go/internal/work/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (b *Builder) Do(ctx context.Context, root *Action) {
a.json.TimeStart = time.Now()
}
var err error
if a.Actor != nil && (!a.Failed || a.IgnoreFail) {
if a.Actor != nil && (a.Failed == nil || a.IgnoreFail) {
// TODO(matloob): Better action descriptions
desc := "Executing action (" + a.Mode
if a.Package != nil {
Expand Down Expand Up @@ -176,12 +176,14 @@ func (b *Builder) Do(ctx context.Context, root *Action) {
sh := b.Shell(a)
sh.Errorf("%s", err)
}
a.Failed = true
if a.Failed == nil {
a.Failed = a
}
}

for _, a0 := range a.triggers {
if a.Failed {
a0.Failed = true
if a.Failed != nil {
a0.Failed = a.Failed
}
if a0.pending--; a0.pending == 0 {
b.ready.push(a0)
Expand Down Expand Up @@ -1242,9 +1244,9 @@ 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.

a.Failed = false // vet of dependency may have failed but we can still succeed
a.Failed = nil // vet of dependency may have failed but we can still succeed

if a.Deps[0].Failed {
if a.Deps[0].Failed != nil {
// The build of the package has failed. Skip vet check.
// Vet could return export data for non-typecheck errors,
// but we ignore it because the package cannot be compiled.
Expand Down

0 comments on commit 9060fa5

Please sign in to comment.