Example #1
0
// ReverseDeps For each input label, finds all targets which depend upon it.
func ReverseDeps(graph *core.BuildGraph, labels []core.BuildLabel) {

	uniqueTargets := make(map[core.BuildLabel]struct{})

	for _, label := range labels {
		for _, child := range graph.PackageOrDie(label.PackageName).AllChildren(graph.TargetOrDie(label)) {
			for _, target := range graph.ReverseDependencies(child) {
				if parent := target.Parent(graph); parent != nil {
					uniqueTargets[parent.Label] = struct{}{}
				} else {
					uniqueTargets[target.Label] = struct{}{}
				}
			}
		}
	}
	// Check for anything subincluding this guy too
	for _, pkg := range graph.PackageMap() {
		for _, label := range labels {
			if pkg.HasSubinclude(label) {
				uniqueTargets[core.BuildLabel{PackageName: pkg.Name, Name: "all"}] = struct{}{}
			}
		}
	}

	targets := make(core.BuildLabels, 0, len(uniqueTargets))
	for target := range uniqueTargets {
		targets = append(targets, target)
	}
	sort.Sort(targets)
	for _, target := range targets {
		fmt.Printf("%s\n", target)
	}
}
Example #2
0
// This is just a simple DFS through the graph.
func printSomePath(graph *core.BuildGraph, target1, target2 *core.BuildTarget) bool {
	if target1 == target2 {
		fmt.Printf("Found path:\n  %s\n", target1.Label)
		return true
	}
	for _, target := range graph.ReverseDependencies(target2) {
		if printSomePath(graph, target1, target) {
			if target2.Parent(graph) != target {
				fmt.Printf("  %s\n", target2.Label)
			}
			return true
		}
	}
	return false
}
func handleAffectedTargets(graph *core.BuildGraph, affectedTargets <-chan *core.BuildTarget, done chan<- bool, include, exclude []string, tests, transitive bool) {
	seenTargets := map[*core.BuildTarget]bool{}

	var inner func(*core.BuildTarget)
	inner = func(target *core.BuildTarget) {
		if !seenTargets[target] {
			seenTargets[target] = true
			if transitive {
				for _, revdep := range graph.ReverseDependencies(target) {
					inner(revdep)
				}
			}
			if (!tests || target.IsTest) && target.ShouldInclude(include, exclude) {
				fmt.Printf("%s\n", target.Label)
			}
		}
	}
	for target := range affectedTargets {
		inner(target)
	}
	done <- true
}