Skip to content

Commit

Permalink
Merge branch 'master' of github.com:thought-machine/please
Browse files Browse the repository at this point in the history
  • Loading branch information
peterebden committed Mar 16, 2017
2 parents fc02d9c + f9940b4 commit d078848
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 d078848

Please sign in to comment.