当前位置: 首页>>代码示例>>Golang>>正文


Golang BuildGraph.PackageMap方法代码示例

本文整理汇总了Golang中core.BuildGraph.PackageMap方法的典型用法代码示例。如果您正苦于以下问题:Golang BuildGraph.PackageMap方法的具体用法?Golang BuildGraph.PackageMap怎么用?Golang BuildGraph.PackageMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在core.BuildGraph的用法示例。


在下文中一共展示了BuildGraph.PackageMap方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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)
	}
}
开发者ID:thought-machine,项目名称:please,代码行数:34,代码来源:reverse_deps.go

示例2: QueryAffectedTargets

// QueryAffectedTargets walks over the build graph and identifies all targets that have a transitive
// dependency on the given set of files.
// Targets are filtered by given include / exclude labels and if 'tests' is true only
// test targets will be returned.
func QueryAffectedTargets(graph *core.BuildGraph, files, include, exclude []string, tests, transitive bool) {
	affectedTargets := make(chan *core.BuildTarget, 100)
	done := make(chan bool)

	filePaths := map[string]bool{}
	for _, file := range files {
		filePaths[file] = true
	}

	// Check all the targets to see if any own one of these files
	go func() {
		for _, target := range graph.AllTargets() {
			for _, source := range target.AllSourcePaths(graph) {
				if _, present := filePaths[source]; present {
					affectedTargets <- target
					break
				}
			}
		}
		done <- true
	}()

	// Check all the packages to see if any are defined by these files.
	// This is pretty pessimistic, we have to just assume the whole package is invalidated.
	// A better approach involves using plz query graph and plz_diff_graphs - see that tool
	// for more explanation.
	go func() {
		invalidatePackage := func(pkg *core.Package) {
			for _, target := range pkg.Targets {
				affectedTargets <- target
			}
		}
		for _, pkg := range graph.PackageMap() {
			if _, present := filePaths[pkg.Filename]; present {
				invalidatePackage(pkg)
			} else {
				for _, subinclude := range pkg.Subincludes {
					for _, source := range graph.TargetOrDie(subinclude).AllSourcePaths(graph) {
						if _, present := filePaths[source]; present {
							invalidatePackage(pkg)
							break
						}
					}
				}
			}
		}
		done <- true
	}()

	go handleAffectedTargets(graph, affectedTargets, done, include, exclude, tests, transitive)

	<-done
	<-done
	close(affectedTargets)
	<-done
}
开发者ID:thought-machine,项目名称:please,代码行数:60,代码来源:affected_targets.go

示例3: 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
}
开发者ID:thought-machine,项目名称:please,代码行数:12,代码来源:whatoutputs.go

示例4: 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
}
开发者ID:thought-machine,项目名称:please,代码行数:14,代码来源:graph.go


注:本文中的core.BuildGraph.PackageMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。