本文整理匯總了Golang中core.BuildGraph類的典型用法代碼示例。如果您正苦於以下問題:Golang BuildGraph類的具體用法?Golang BuildGraph怎麽用?Golang BuildGraph使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了BuildGraph類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: addJSONTarget
func addJSONTarget(graph *core.BuildGraph, ret *JSONGraph, label core.BuildLabel, done map[core.BuildLabel]struct{}) {
if _, present := done[label]; present {
return
}
done[label] = struct{}{}
if label.IsAllTargets() {
pkg := graph.PackageOrDie(label.PackageName)
for _, target := range pkg.Targets {
addJSONTarget(graph, ret, target.Label, done)
}
return
}
target := graph.TargetOrDie(label)
if _, present := ret.Packages[label.PackageName]; present {
ret.Packages[label.PackageName].Targets[label.Name] = makeJSONTarget(graph, target)
} else {
ret.Packages[label.PackageName] = JSONPackage{
Targets: map[string]JSONTarget{
label.Name: makeJSONTarget(graph, target),
},
}
}
for _, dep := range target.Dependencies() {
addJSONTarget(graph, ret, dep.Label, done)
}
}
示例2: Run
// Run implements the running part of 'plz run'.
func Run(graph *core.BuildGraph, label core.BuildLabel, args []string) {
target := graph.TargetOrDie(label)
if !target.IsBinary {
log.Fatalf("Target %s cannot be run; it's not marked as binary", label)
}
// ReplaceSequences always quotes stuff in case it contains spaces or special characters,
// that works fine if we interpret it as a shell but not to pass it as an argument here.
cmd := strings.Trim(build.ReplaceSequences(target, fmt.Sprintf("$(out_exe %s)", target.Label)), "\"")
// Handle targets where $(exe ...) returns something nontrivial
splitCmd := strings.Split(cmd, " ")
if !strings.Contains(splitCmd[0], "/") {
// Probably it's a java -jar, we need an absolute path to it.
cmd, err := exec.LookPath(splitCmd[0])
if err != nil {
log.Fatalf("Can't find binary %s", splitCmd[0])
}
splitCmd[0] = cmd
}
args = append(splitCmd, args...)
log.Info("Running target %s...", strings.Join(args, " "))
output.SetWindowTitle("plz run: " + strings.Join(args, " "))
if err := syscall.Exec(splitCmd[0], args, os.Environ()); err != nil {
log.Fatalf("Error running command %s: %s", strings.Join(args, " "), err)
}
}
示例3: addDeps
func addDeps(graph *core.BuildGraph, pkg *core.Package) {
for _, target := range pkg.Targets {
for _, dep := range target.DeclaredDependencies() {
graph.AddDependency(target.Label, dep)
}
}
}
示例4: updateDependencies
// Set dependency pointers on all contents of the graph.
// Has to be done after to test cycles etc.
func updateDependencies(graph *core.BuildGraph) {
for _, target := range graph.AllTargets() {
for _, dep := range target.DeclaredDependencies() {
graph.AddDependency(target.Label, dep)
}
}
}
示例5: sourceHash
// Calculate the hash of all sources of this rule
func sourceHash(graph *core.BuildGraph, target *core.BuildTarget) ([]byte, error) {
h := sha1.New()
for source := range core.IterSources(graph, target) {
result, err := pathHash(source.Src, false)
if err != nil {
return nil, err
}
h.Write(result)
}
for _, tool := range target.Tools {
if label := tool.Label(); label != nil {
// Note that really it would be more correct to hash the outputs of these rules
// in the same way we calculate a hash of sources for the rule, but that is
// impractical for some cases (notably npm) where tools can be very large.
// Instead we assume calculating the target hash is sufficient.
h.Write(mustTargetHash(core.State, graph.TargetOrDie(*label)))
} else {
result, err := pathHash(tool.FullPaths(graph)[0], false)
if err != nil {
return nil, err
}
h.Write(result)
}
}
return h.Sum(nil), nil
}
示例6: QueryTargetOutputs
// QueryTargetOutputs prints all output files for a set of targets.
func QueryTargetOutputs(graph *core.BuildGraph, labels []core.BuildLabel) {
for _, label := range labels {
target := graph.TargetOrDie(label)
for _, out := range target.Outputs() {
fmt.Printf("%s\n", path.Join(target.OutDir(), out))
}
}
}
示例7: QueryTargetInputs
// QueryTargetInputs prints all inputs for a single target.
func QueryTargetInputs(graph *core.BuildGraph, labels []core.BuildLabel) {
inputPaths := map[string]bool{}
for _, label := range labels {
for sourcePath := range core.IterInputPaths(graph, graph.TargetOrDie(label)) {
inputPaths[sourcePath] = true
}
}
for path := range inputPaths {
fmt.Printf("%s\n", path)
}
}
示例8: querySomePath1
func querySomePath1(graph *core.BuildGraph, target1 *core.BuildTarget, label2 core.BuildLabel, print bool) bool {
// Now we do the same for label2.
if label2.IsAllTargets() {
for _, target2 := range graph.PackageOrDie(label2.PackageName).Targets {
if querySomePath2(graph, target1, target2, false) {
return true
}
}
return false
}
return querySomePath2(graph, target1, graph.TargetOrDie(label2), print)
}
示例9: filesToLabelMap
func filesToLabelMap(graph *core.BuildGraph) map[string]*core.BuildLabel {
packageMap := make(map[string]*core.BuildLabel)
for _, pkg := range graph.PackageMap() {
for _, target := range pkg.Outputs {
for _, output := range target.Outputs() {
artifactPath := path.Join(target.OutDir(), output)
packageMap[artifactPath] = &target.Label
}
}
}
return packageMap
}
示例10: ReverseDeps
// 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)
}
}
示例11: makeJSONGraph
func makeJSONGraph(graph *core.BuildGraph, targets []core.BuildLabel) *JSONGraph {
ret := JSONGraph{Packages: map[string]JSONPackage{}}
if len(targets) == 0 {
for name, pkg := range graph.PackageMap() {
ret.Packages[name] = makeJSONPackage(graph, pkg)
}
} else {
done := map[core.BuildLabel]struct{}{}
for _, target := range targets {
addJSONTarget(graph, &ret, target, done)
}
}
return &ret
}
示例12: QuerySomePath
// QuerySomePath finds and returns a path between two targets.
// Useful for a "why on earth do I depend on this thing" type query.
func QuerySomePath(graph *core.BuildGraph, label1 core.BuildLabel, label2 core.BuildLabel) {
// Awkwardly either target can be :all. This is an extremely useful idiom though so despite
// trickiness is worth supporting.
// Of course this calculation is also quadratic but it's not very obvious how to avoid that.
if label1.IsAllTargets() {
for _, target := range graph.PackageOrDie(label1.PackageName).Targets {
if querySomePath1(graph, target, label2, false) {
return
}
}
fmt.Printf("Couldn't find any dependency path between %s and %s\n", label1, label2)
} else {
querySomePath1(graph, graph.TargetOrDie(label1), label2, true)
}
}
示例13: printSomePath
// 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
}
示例14: QueryCompletions
// Queries a set of possible completions for some build labels.
// If 'binary' is true it will complete only targets that are runnable binaries (but not tests).
// If 'test' is true it will similarly complete only targets that are tests.
func QueryCompletions(graph *core.BuildGraph, labels []core.BuildLabel, binary, test bool) {
for _, label := range labels {
count := 0
for _, target := range graph.PackageOrDie(label.PackageName).Targets {
if (binary && (!target.IsBinary || target.IsTest)) || (test && !target.IsTest) {
continue
}
if !strings.HasPrefix(target.Label.Name, "_") {
fmt.Printf("%s\n", target.Label)
count++
}
}
if !binary && count > 1 {
fmt.Printf("//%s:all\n", label.PackageName)
}
}
}
示例15: unbuiltTargetsMessage
// Prints all targets in the build graph that are marked to be built but not built yet.
func unbuiltTargetsMessage(graph *core.BuildGraph) string {
msg := ""
for _, target := range graph.AllTargets() {
if target.State() == core.Active {
if graph.AllDepsBuilt(target) {
msg += fmt.Sprintf(" %s (waiting for deps to build)\n", target.Label)
} else {
msg += fmt.Sprintf(" %s\n", target.Label)
}
} else if target.State() == core.Pending {
msg += fmt.Sprintf(" %s (pending build)\n", target.Label)
}
}
if msg != "" {
return "\nThe following targets have not yet built:\n" + msg
}
return ""
}