• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang core.BuildGraph类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了BuildGraph类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
	}
}
开发者ID:thought-machine,项目名称:please,代码行数:26,代码来源:graph.go


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


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


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


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


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


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


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


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


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


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


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


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


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


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


示例16: handleAffectedTargets

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


示例17: WriteResultsToFileOrDie

// Write test results out to a file in xUnit format. Dies on any errors.
func WriteResultsToFileOrDie(graph *core.BuildGraph, filename string) {
	if err := os.MkdirAll(path.Dir(filename), core.DirPermissions); err != nil {
		log.Fatalf("Failed to create directory for test output")
	}
	results := JUnitXMLTestResults{}
	results.XMLName.Local = "testsuites"
	for _, target := range graph.AllTargets() {
		if target.Results.NumTests > 0 {
			suite := JUnitXMLTestSuite{
				Name:     target.Label.String(),
				Failures: target.Results.Failed,
				Tests:    target.Results.NumTests,
			}
			for _, pass := range target.Results.Passes {
				suite.TestCases = append(suite.TestCases, JUnitXMLTest{Name: pass})
			}
			for _, fail := range target.Results.Failures {
				suite.TestCases = append(suite.TestCases, JUnitXMLTest{
					Name:   fail.Name,
					Type:   fail.Type,
					Stdout: fail.Stdout,
					Stderr: fail.Stderr,
					Error: &JUnitXMLFailure{
						Type:      fail.Type,
						Traceback: fail.Traceback,
					},
				})
			}
			results.TestSuites = append(results.TestSuites, suite)
		}
	}
	if b, err := xml.MarshalIndent(results, "", "    "); err != nil {
		log.Fatalf("Failed to serialise XML: %s", err)
	} else if err = ioutil.WriteFile(filename, b, 0644); err != nil {
		log.Fatalf("Failed to write XML to %s: %s", filename, err)
	}
}
开发者ID:thought-machine,项目名称:please,代码行数:38,代码来源:xml_results.go


示例18: 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


示例19: makeTarget

func makeTarget(g *core.BuildGraph, packageName string, labelName string, outputs []string) *core.BuildTarget {
	l := core.ParseBuildLabel(fmt.Sprintf("//%s:%s", packageName, labelName), "")
	t := core.NewBuildTarget(l)

	p := g.Package(packageName)
	if p == nil {
		p = core.NewPackage(packageName)
		g.AddPackage(p)
	}
	for _, out := range outputs {
		t.AddOutput(out)
		p.MustRegisterOutput(out, t)
	}
	p.Targets[labelName] = t
	g.AddTarget(t)
	return t
}
开发者ID:thought-machine,项目名称:please,代码行数:17,代码来源:whatoutputs_test.go


示例20: QueryPrint

// QueryPrint produces a Python call which would (hopefully) regenerate the same build rule if run.
// This is of course not ideal since they were almost certainly created as a java_library
// or some similar wrapper rule, but we've lost that information by now.
func QueryPrint(graph *core.BuildGraph, labels []core.BuildLabel) {
	for _, label := range labels {
		target := graph.TargetOrDie(label)
		fmt.Printf("%s:\n", label)
		if target.IsFilegroup() {
			fmt.Printf("  filegroup(\n")
		} else {
			fmt.Printf("  build_rule(\n")
		}
		fmt.Printf("      name = '%s'\n", target.Label.Name)
		if len(target.Sources) > 0 {
			fmt.Printf("      srcs = [\n")
			for _, src := range target.Sources {
				fmt.Printf("          '%s',\n", src)
			}
			fmt.Printf("      ],\n")
		} else if target.NamedSources != nil {
			fmt.Printf("      srcs = {\n")
			for name, srcs := range target.NamedSources {
				fmt.Printf("          '%s': [\n", name)
				for _, src := range srcs {
					fmt.Printf("              '%s'\n", src)
				}
				fmt.Printf("          ],\n")
			}
			fmt.Printf("      },\n")
		}
		if len(target.DeclaredOutputs()) > 0 && !target.IsFilegroup() {
			fmt.Printf("      outs = [\n")
			for _, out := range target.DeclaredOutputs() {
				fmt.Printf("          '%s',\n", out)
			}
			fmt.Printf("      ],\n")
		}
		stringList("optional_outs", target.OptionalOutputs)
		pythonDict(target.Commands, "cmd")
		if !target.IsFilegroup() {
			fmt.Printf("      cmd = '%s'\n", target.Command)
		}
		pythonDict(target.TestCommands, "test_cmd")
		if target.TestCommand != "" {
			fmt.Printf("      test_cmd = '%s'\n", target.TestCommand)
		}
		pythonBool("binary", target.IsBinary)
		pythonBool("test", target.IsTest)
		pythonBool("needs_transitive_deps", target.NeedsTransitiveDependencies)
		if !target.IsFilegroup() {
			pythonBool("output_is_complete", target.OutputIsComplete)
			if target.BuildingDescription != core.DefaultBuildingDescription {
				fmt.Printf("      building_description = '%s',\n", target.BuildingDescription)
			}
		}
		pythonBool("stamp", target.Stamp)
		if target.ContainerSettings != nil {
			fmt.Printf("      container = {\n")
			fmt.Printf("          'docker_image': '%s',\n", target.ContainerSettings.DockerImage)
			fmt.Printf("          'docker_user': '%s',\n", target.ContainerSettings.DockerUser)
			fmt.Printf("          'docker_run_args': '%s',\n", target.ContainerSettings.DockerRunArgs)
		} else {
			pythonBool("container", target.Containerise)
		}
		pythonBool("no_test_output", target.NoTestOutput)
		pythonBool("test_only", target.TestOnly)
		labelList("deps", excludeLabels(target.DeclaredDependencies(), target.ExportedDependencies(), sourceLabels(target)), target)
		labelList("exported_deps", target.ExportedDependencies(), target)
		if len(target.Tools) > 0 {
			fmt.Printf("      tools = [\n")
			for _, tool := range target.Tools {
				fmt.Printf("          '%s',\n", tool)
			}
			fmt.Printf("      ],\n")
		}
		if len(target.Data) > 0 {
			fmt.Printf("      data = [\n")
			for _, datum := range target.Data {
				fmt.Printf("          '%s',\n", datum)
			}
			fmt.Printf("      ],\n")
		}
		stringList("labels", excludeStrings(target.Labels, target.Requires))
		stringList("hashes", target.Hashes)
		stringList("licences", target.Licences)
		stringList("test_outputs", target.TestOutputs)
		stringList("requires", target.Requires)
		if len(target.Provides) > 0 {
			fmt.Printf("      provides = {\n")
			for k, v := range target.Provides {
				if v.PackageName == target.Label.PackageName {
					fmt.Printf("          '%s': ':%s',\n", k, v.Name)
				} else {
					fmt.Printf("          '%s': '%s',\n", k, v)
				}
			}
			fmt.Printf("      },\n")
		}
		if target.Flakiness > 0 {
			fmt.Printf("      flaky = %d,\n", target.Flakiness)
//.........这里部分代码省略.........
开发者ID:thought-machine,项目名称:please,代码行数:101,代码来源:print.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang core.BuildLabel类代码示例发布时间:2022-05-24
下一篇:
Golang core.PathExists函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap