Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/itg/graph/invalidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ func (g *OptimizedGraph) invalidateHashRecursively(ids IntSet, invalidated IntSe
targetID := candidates[curIdx]
curIdx++
target, ok := g.OptimizedTargets[targetID]
if !ok || target.Hash == nil {
if !ok {
return fmt.Errorf("target %d not found", targetID)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is intentional.
if the target doesn't exist (such as external rule targets naturally doesn't exits in OptimizedTargets). There's nothing to invalidate in ITG graph.

what's actually erroring out is removeTarget below.

}
if invalidated.Contains(targetID) {
continue
}

Expand Down
21 changes: 18 additions & 3 deletions core/itg/graph/invalidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,35 @@ func TestInvalidateHashRecursively(t *testing.T) {
assert.False(t, invalidated.Contains(aID))
})

t.Run("targets with nil hash are skipped", func(t *testing.T) {
t.Run("targets with nil hash and their reverse deps are invalidated", func(t *testing.T) {
t.Parallel()
targets := map[string]*targethasher.Target{
"//pkg:a": {Name: "//pkg:a", RuleType: "go_library"}, // Hash=nil
"//pkg:b": {Name: "//pkg:b", RuleType: "go_library", Deps: []string{"//pkg:a"}}, // Hash=nil
"//pkg:c": {Name: "//pkg:c", RuleType: "go_library", Hash: []byte{1}, Deps: []string{"//pkg:b"}},
}
g := OptimizeGraph(targets)
aID := g.TargetNameToID["//pkg:a"]
bID := g.TargetNameToID["//pkg:b"]
cID := g.TargetNameToID["//pkg:c"]

invalidated := NewIntSet()
require.NoError(t, g.invalidateHashRecursively(g.OptimizedTargets[aID].ReverseDeps, invalidated))

// b has a nil hash and is thus skipped; invalidated stays empty
assert.Empty(t, invalidated.UnsortedList())
assert.True(t, invalidated.Contains(bID))
assert.True(t, invalidated.Contains(cID))
assert.Nil(t, g.OptimizedTargets[cID].Hash)
})

t.Run("missing target returns an error", func(t *testing.T) {
t.Parallel()

g := OptimizeGraph(map[string]*targethasher.Target{})
ids := NewIntSet()
ids.Insert(42)
err := g.invalidateHashRecursively(ids, NewIntSet())

require.Error(t, err)
})
}

Expand Down
Loading