Skip to content

Commit

Permalink
Support for expanding ... if they end up in state.OriginalTargets.
Browse files Browse the repository at this point in the history
Theoretically this wasn't supposed to happen, in practice it does for things like revdeps that need to parse the whole graph separately, so it's nice to catch it generically.
  • Loading branch information
peterebden committed Mar 15, 2017
1 parent 0a73edf commit f9940b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/core/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,20 @@ func (state *BuildState) NumDone() int {
// from the set of original targets.
func (state *BuildState) ExpandOriginalTargets() BuildLabels {
ret := BuildLabels{}
addPackage := func(pkg *Package) {
for _, target := range pkg.Targets {
if target.ShouldInclude(state.Include, state.Exclude) && (!state.NeedTests || target.IsTest) {
ret = append(ret, target.Label)
}
}
}
for _, label := range state.OriginalTargets {
if label.IsAllTargets() {
for _, target := range state.Graph.PackageOrDie(label.PackageName).Targets {
if target.ShouldInclude(state.Include, state.Exclude) && (!state.NeedTests || target.IsTest) {
ret = append(ret, target.Label)
addPackage(state.Graph.PackageOrDie(label.PackageName))
} else if label.IsAllSubpackages() {
for name, pkg := range state.Graph.PackageMap() {
if label.Includes(BuildLabel{PackageName: name}) {
addPackage(pkg)
}
}
} else {
Expand Down
13 changes: 13 additions & 0 deletions src/core/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ func TestExpandVisibleOriginalTargets(t *testing.T) {
assert.Equal(t, state.ExpandVisibleOriginalTargets(), BuildLabels{{"src/core", "target1"}})
}

func TestExpandOriginalSubTargets(t *testing.T) {
state := NewBuildState(1, nil, 4, DefaultConfiguration())
state.OriginalTargets = []BuildLabel{{"src/core", "..."}}
state.Include = []string{"go"}
state.Exclude = []string{"py"}
addTarget(state, "//src/core:target1", "go")
addTarget(state, "//src/core:target2", "py")
addTarget(state, "//src/core/tests:target3", "go")
// Only the one target comes out here; it must be a test and otherwise follows
// the same include / exclude logic as the previous test.
assert.Equal(t, state.ExpandOriginalTargets(), BuildLabels{{"src/core", "target1"}, {"src/core/tests", "target3"}})
}

func TestComparePendingTasks(t *testing.T) {
p := func(taskType TaskType) pendingTask { return pendingTask{Type: taskType} }
// NB. "Higher priority" means the task comes first, does not refer to numeric values.
Expand Down

0 comments on commit f9940b4

Please sign in to comment.