本文整理匯總了Golang中core.ParseBuildLabel函數的典型用法代碼示例。如果您正苦於以下問題:Golang ParseBuildLabel函數的具體用法?Golang ParseBuildLabel怎麽用?Golang ParseBuildLabel使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ParseBuildLabel函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestAddTarget
func TestAddTarget(t *testing.T) {
pkg := core.NewPackage("src/parse")
addTargetTest1 := func(name string, binary, container, test bool, testCmd string) *core.BuildTarget {
return addTarget(uintptr(unsafe.Pointer(pkg)), name, "true", testCmd, binary, test,
false, false, container, false, false, false, 0, 0, 0, "Building...")
}
addTargetTest := func(name string, binary, container bool) *core.BuildTarget {
return addTargetTest1(name, binary, container, false, "")
}
// Test that labels are correctly applied
target1 := addTargetTest("target1", false, false)
assert.False(t, target1.HasLabel("bin"))
assert.False(t, target1.HasLabel("container"))
target2 := addTargetTest("target2", true, false)
assert.True(t, target2.HasLabel("bin"))
assert.False(t, target2.HasLabel("container"))
target3 := addTargetTest("target3", true, true)
assert.True(t, target3.HasLabel("bin"))
assert.True(t, target3.HasLabel("container"))
assert.Panics(t, func() { addTargetTest(":target1", false, false) },
"Should return nil attempting to add a target with an illegal name")
assert.Nil(t, addTargetTest("target1", false, false),
"Should return nil attempting to add a new target with the same name")
assert.Nil(t, core.State.Graph.Target(core.ParseBuildLabel("//src/parse:target1", "")),
"Shouldn't have added target to the graph yet")
core.State.Graph.AddPackage(pkg)
addTargetTest("target6", true, false)
target6 := core.State.Graph.Target(core.ParseBuildLabel("//src/parse:target6", ""))
assert.NotNil(t, target6, "Should have been added to the graph since the package is added")
assert.True(t, target6.HasLabel("bin"))
}
示例2: makeTarget
func makeTarget(label string, deps ...string) *core.BuildTarget {
target := core.NewBuildTarget(core.ParseBuildLabel(label, ""))
for _, dep := range deps {
target.AddDependency(core.ParseBuildLabel(dep, ""))
}
return target
}
示例3: TestDiffGraphsChangedHash
func TestDiffGraphsChangedHash(t *testing.T) {
changes := readAndDiffGraphs("src/misc/test_data/before.json", "src/misc/test_data/changed_hash.json", nil, nil, nil)
expected := []core.BuildLabel{
core.ParseBuildLabel("//:all_tools", ""),
core.ParseBuildLabel("//src/cache/server:http_cache_server_bin", ""),
}
assert.Equal(t, expected, changes)
}
示例4: TestDiffGraphsSimple
func TestDiffGraphsSimple(t *testing.T) {
changes := readAndDiffGraphs("src/misc/test_data/before.json", "src/misc/test_data/after.json", nil, nil, nil)
expected := []core.BuildLabel{
core.ParseBuildLabel("//src/misc:plz_diff_graphs", ""),
core.ParseBuildLabel("//src/misc:plz_diff_graphs_test", ""),
}
assert.Equal(t, expected, changes)
}
示例5: TestDiffGraphsRemovedPackage2
func TestDiffGraphsRemovedPackage2(t *testing.T) {
changes := readAndDiffGraphs("src/misc/test_data/removed_package.json", "src/misc/test_data/before.json", nil, nil, nil)
expected := []core.BuildLabel{
core.ParseBuildLabel("//:all_tools", ""),
core.ParseBuildLabel("//src/cache/tools:cache_cleaner", ""),
core.ParseBuildLabel("//src/cache/tools:cache_cleaner_platform", ""),
}
assert.Equal(t, expected, changes)
}
示例6: TestDiffGraphsIncludeLabels
func TestDiffGraphsIncludeLabels(t *testing.T) {
changes := readAndDiffGraphs("src/misc/test_data/before.json", "src/misc/test_data/labels2.json", nil, []string{"py"}, nil)
expected := []core.BuildLabel{
core.ParseBuildLabel("//src/build/python:pex_import_test", ""),
}
assert.Equal(t, expected, changes)
}
示例7: TestQuerySingleTarget
func TestQuerySingleTarget(t *testing.T) {
graph := makeJSONGraph(makeGraph(), []core.BuildLabel{core.ParseBuildLabel("//package1:target2", "")})
assert.Equal(t, 1, len(graph.Packages))
pkg1 := graph.Packages["package1"]
assert.Equal(t, 2, len(pkg1.Targets))
assert.Equal(t, []string{"//package1:target1"}, pkg1.Targets["target2"].Deps)
}
示例8: getSubincludeFile
func getSubincludeFile(pkg *core.Package, labelStr string) string {
label := core.ParseBuildLabel(labelStr, pkg.Name)
if label.PackageName == pkg.Name {
return fmt.Sprintf("__Can't subinclude :%s in %s; can't subinclude local targets.", label.Name, pkg.Name)
}
pkgLabel := core.BuildLabel{PackageName: pkg.Name, Name: "all"}
target := core.State.Graph.Target(label)
if target == nil {
// Might not have been parsed yet. Check for that first.
if subincludePackage := core.State.Graph.Package(label.PackageName); subincludePackage == nil {
if deferParse(label, pkg) {
return pyDeferParse // Not an error, they'll just have to wait.
}
target = core.State.Graph.TargetOrDie(label) // Should be there now.
} else {
return fmt.Sprintf("__Failed to subinclude %s; package %s has no target by that name", label, label.PackageName)
}
} else if tmp := core.NewBuildTarget(pkgLabel); !tmp.CanSee(target) {
return fmt.Sprintf("__Can't subinclude %s from %s due to visibility constraints", label, pkg.Name)
} else if len(target.Outputs()) != 1 {
return fmt.Sprintf("__Can't subinclude %s, subinclude targets must have exactly one output", label)
} else if target.State() < core.Built {
if deferParse(label, pkg) {
return pyDeferParse // Again, they'll have to wait for this guy to build.
}
}
pkg.RegisterSubinclude(target.Label)
// Well if we made it to here it's actually ready to go, so tell them where to get it.
return path.Join(target.OutDir(), target.Outputs()[0])
}
示例9: newState
func newState(label string) (*core.BuildState, *core.BuildTarget) {
config, _ := core.ReadConfigFiles(nil)
state := core.NewBuildState(1, nil, 4, config)
target := core.NewBuildTarget(core.ParseBuildLabel(label, ""))
target.Command = fmt.Sprintf("echo 'output of %s' > $OUT", target.Label)
state.Graph.AddTarget(target)
return state, target
}
示例10: makeGraph
func makeGraph() *core.BuildGraph {
core.State = &core.BuildState{}
graph := core.NewGraph()
pkg1 := core.NewPackage("package1")
pkg1.Targets["target1"] = makeTarget("//package1:target1")
pkg1.Targets["target2"] = makeTarget("//package1:target2", "//package1:target1")
graph.AddPackage(pkg1)
graph.AddTarget(pkg1.Targets["target1"])
graph.AddTarget(pkg1.Targets["target2"])
pkg2 := core.NewPackage("package2")
pkg2.Targets["target3"] = makeTarget("//package2:target3", "//package1:target2")
graph.AddPackage(pkg2)
graph.AddTarget(pkg2.Targets["target3"])
graph.AddDependency(core.ParseBuildLabel("//package1:target2", ""), core.ParseBuildLabel("//package1:target1", ""))
graph.AddDependency(core.ParseBuildLabel("//package2:target3", ""), core.ParseBuildLabel("//package1:target2", ""))
return graph
}
示例11: newPyFilegroup
func newPyFilegroup(state *core.BuildState, label, filename string) *core.BuildTarget {
target := core.NewBuildTarget(core.ParseBuildLabel(label, ""))
target.AddSource(core.FileLabel{File: filename, Package: target.Label.PackageName})
target.AddOutput(filename)
target.AddLabel("py")
target.Command = "__FILEGROUP__" // magic
state.Graph.AddTarget(target)
return target
}
示例12: TestMapKeysContainFullPathFromProjectRoot
func TestMapKeysContainFullPathFromProjectRoot(t *testing.T) {
core.State = &core.BuildState{}
graph := core.NewGraph()
makeTarget(graph, "package1", "target1", []string{"out1", "out2"})
makeTarget(graph, "package1", "target2", []string{"out3"})
makeTarget(graph, "package2", "target1", []string{"out4"})
m := filesToLabelMap(graph)
label1 := core.ParseBuildLabel("//package1:target1", "")
label2 := core.ParseBuildLabel("//package1:target2", "")
label3 := core.ParseBuildLabel("//package2:target1", "")
p1 := graph.PackageOrDie("package1")
p2 := graph.PackageOrDie("package2")
assert.Equal(t, m[path.Join(p1.Targets["target1"].OutDir(), "out1")].String(), label1.String())
assert.Equal(t, m[path.Join(p1.Targets["target1"].OutDir(), "out2")].String(), label1.String())
assert.Equal(t, m[path.Join(p1.Targets["target2"].OutDir(), "out3")].String(), label2.String())
assert.Equal(t, m[path.Join(p2.Targets["target1"].OutDir(), "out4")].String(), label3.String())
}
示例13: TestGetSubincludeFile
func TestGetSubincludeFile(t *testing.T) {
assertError := func(t *testing.T, ret, msg string) { assert.True(t, strings.HasPrefix(ret, "__"), msg) }
state := core.NewBuildState(10, nil, 2, core.DefaultConfiguration())
pkg := core.NewPackage("src/parse")
pkg2 := core.NewPackage("src/core")
assert.Equal(t, pyDeferParse, getSubincludeFile(pkg, "//src/core:target"), "Package not loaded yet, should defer")
assertError(t, getSubincludeFile(pkg, "//src/parse:target"), "Should produce an error on attempts for local subincludes.")
assertError(t, getSubincludeFile(pkg, ":target"), "Should produce an error on attempts for local subincludes.")
state.Graph.AddPackage(pkg)
state.Graph.AddPackage(pkg2)
assertError(t, getSubincludeFile(pkg, "//src/core:target"), "Produces an error, target does not exist in package.")
target := core.NewBuildTarget(core.ParseBuildLabel("//src/core:target", ""))
state.Graph.AddTarget(target)
assertError(t, getSubincludeFile(pkg, "//src/core:target"), "Errors, target is not visible to subincluding package.")
target.Visibility = []core.BuildLabel{core.ParseBuildLabel("//src/parse:all", "")}
assertError(t, getSubincludeFile(pkg, "//src/core:target"), "Errors, target doesn't have any outputs to include.")
target.AddOutput("test.py")
assert.Equal(t, pyDeferParse, getSubincludeFile(pkg, "//src/core:target"), "Target isn't built yet, so still deferred")
target.SetState(core.Built)
assert.Equal(t, "plz-out/gen/src/core/test.py", getSubincludeFile(pkg, "//src/core:target"), "Success at last")
}
示例14: TestGetLabels
func TestGetLabels(t *testing.T) {
state := core.NewBuildState(10, nil, 2, core.DefaultConfiguration())
target1 := core.NewBuildTarget(core.ParseBuildLabel("//src/parse:target1", ""))
target2 := core.NewBuildTarget(core.ParseBuildLabel("//src/parse:target2", ""))
target3 := core.NewBuildTarget(core.ParseBuildLabel("//src/parse:target3", ""))
target1.AddLabel("go")
target2.AddLabel("py")
target3.AddLabel("cc")
target1.AddDependency(target2.Label)
target1.AddDependency(target3.Label)
target2.AddDependency(target3.Label)
state.Graph.AddTarget(target1)
state.Graph.AddTarget(target2)
state.Graph.AddTarget(target3)
state.Graph.AddDependency(target1.Label, target2.Label)
state.Graph.AddDependency(target1.Label, target3.Label)
state.Graph.AddDependency(target2.Label, target3.Label)
// Note labels always come out in sorted order.
assert.Equal(t, []string{"cc", "go", "py"}, getLabels(target1, "", core.Inactive))
assert.Equal(t, []string{"cc", "py"}, getLabels(target2, "", core.Inactive))
assert.Equal(t, []string{"cc"}, getLabels(target3, "", core.Inactive))
assert.Equal(t, []string{"y"}, getLabels(target1, "p", core.Inactive))
}
示例15: TestConstructsMapFromGraph
func TestConstructsMapFromGraph(t *testing.T) {
core.State = &core.BuildState{}
graph := core.NewGraph()
m := filesToLabelMap(graph)
assert.Equal(t, 0, len(m))
label := core.ParseBuildLabel("//package1:target1", "")
makeTarget(graph, "package1", "target1", []string{"out1", "out2"})
m = filesToLabelMap(graph)
assert.Equal(t, 2, len(m))
for _, l := range m {
assert.Equal(t, label.String(), l.String())
}
}