本文整理汇总了Golang中core.BuildState类的典型用法代码示例。如果您正苦于以下问题:Golang BuildState类的具体用法?Golang BuildState怎么用?Golang BuildState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BuildState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: printLines
func printLines(state *core.BuildState, buildingTargets []buildingTarget, maxLines, cols int) {
now := time.Now()
printf("Building [%d/%d, %3.1fs]:\n", state.NumDone(), state.NumActive(), time.Since(startTime).Seconds())
for i := 0; i < len(buildingTargets) && i < maxLines; i++ {
buildingTargets[i].Lock()
// Take a local copy of the structure, which isn't *that* big, so we don't need to retain the lock
// while we do potentially blocking things like printing.
target := buildingTargets[i].buildingTargetData
buildingTargets[i].Unlock()
label := target.Label.Parent()
if target.Active {
lprintf(cols, "${BOLD_WHITE}=> [%4.1fs] ${RESET}%s%s ${BOLD_WHITE}%s${ERASE_AFTER}\n",
now.Sub(target.Started).Seconds(), target.Colour, label, target.Description)
} else if time.Since(target.Finished).Seconds() < 0.5 {
// Only display finished targets for half a second after they're done.
duration := target.Finished.Sub(target.Started).Seconds()
if target.Failed {
lprintf(cols, "${BOLD_RED}=> [%4.1fs] ${RESET}%s%s ${BOLD_RED}Failed${ERASE_AFTER}\n",
duration, target.Colour, label)
} else if target.Cached {
lprintf(cols, "${BOLD_WHITE}=> [%4.1fs] ${RESET}%s%s ${BOLD_GREY}%s${ERASE_AFTER}\n",
duration, target.Colour, label, target.Description)
} else {
lprintf(cols, "${BOLD_WHITE}=> [%4.1fs] ${RESET}%s%s ${WHITE}%s${ERASE_AFTER}\n",
duration, target.Colour, label, target.Description)
}
} else {
printf("${BOLD_GREY}=|${ERASE_AFTER}\n")
}
}
printf("${RESET}")
}
示例2: printBuildResults
func printBuildResults(state *core.BuildState, duration float64) {
// Count incrementality.
totalBuilt := 0
totalReused := 0
for _, target := range state.Graph.AllTargets() {
if target.State() == core.Built {
totalBuilt++
} else if target.State() == core.Reused {
totalReused++
}
}
incrementality := 100.0 * float64(totalReused) / float64(totalBuilt+totalReused)
if totalBuilt+totalReused == 0 {
incrementality = 100 // avoid NaN
}
// Print this stuff so we always see it.
printf("Build finished; total time %0.2fs, incrementality %.1f%%. Outputs:\n", duration, incrementality)
for _, label := range state.ExpandOriginalTargets() {
target := state.Graph.TargetOrDie(label)
fmt.Printf("%s:\n", label)
for _, result := range buildResult(target) {
fmt.Printf(" %s\n", result)
}
}
}
示例3: setWindowTitle
// setWindowTitle sets the title of the current shell window based on the current build state.
func setWindowTitle(state *core.BuildState) {
if state == nil {
SetWindowTitle("plz: finishing up")
} else {
SetWindowTitle(fmt.Sprintf("plz: %d / %d tasks, %3.1fs", state.NumDone(), state.NumActive(), time.Since(startTime).Seconds()))
}
}
示例4: addTarget
func addTarget(state *core.BuildState, i int) *core.BuildTarget {
// Create and add a new target, with a parent and a dependency.
target := core.NewBuildTarget(label(i))
target.Command = "__FILEGROUP__" // Will mean it doesn't have to shell out to anything.
target.SetState(core.Active)
state.Graph.AddTarget(target)
if i <= size {
if i > 10 {
target.Flakiness = i // Stash this here, will be useful later.
target.PostBuildFunction = reflect.ValueOf(&postBuildFunc).Pointer()
}
if i < size/10 {
for j := 0; j < 10; j++ {
dep := label(i*10 + j)
log.Info("Adding dependency %s -> %s", target.Label, dep)
target.AddDependency(dep)
state.Graph.AddDependency(target.Label, dep)
}
} else {
// These are buildable now
state.AddPendingBuild(target.Label, false)
}
}
state.AddActiveTarget()
return target
}
示例5: Test
func Test(tid int, state *core.BuildState, label core.BuildLabel) {
state.LogBuildResult(tid, label, core.TargetTesting, "Testing...")
startTime := time.Now()
target := state.Graph.TargetOrDie(label)
test(tid, state, label, target)
metrics.Record(target, time.Since(startTime))
}
示例6: prepareAndRunTest
// prepareAndRunTest sets up a test directory and runs the test.
func prepareAndRunTest(tid int, state *core.BuildState, target *core.BuildTarget) (out []byte, err error) {
if err = prepareTestDir(state.Graph, target); err != nil {
state.LogBuildError(tid, target.Label, core.TargetTestFailed, err, "Failed to prepare test directory for %s: %s", target.Label, err)
return []byte{}, err
}
return runPossiblyContainerisedTest(state, target)
}
示例7: findOriginalTask
func findOriginalTask(state *core.BuildState, target core.BuildLabel) {
if target.IsAllSubpackages() {
for pkg := range utils.FindAllSubpackages(state.Config, target.PackageName, "") {
state.AddOriginalTarget(core.NewBuildLabel(pkg, "all"))
}
} else {
state.AddOriginalTarget(target)
}
}
示例8: MonitorState
func MonitorState(state *core.BuildState, numThreads int, plainOutput, keepGoing, shouldBuild, shouldTest, shouldRun bool, traceFile string) bool {
failedTargetMap := map[core.BuildLabel]error{}
buildingTargets := make([]buildingTarget, numThreads, numThreads)
displayDone := make(chan interface{})
stop := make(chan interface{})
if !plainOutput {
go display(state, &buildingTargets, stop, displayDone)
}
aggregatedResults := core.TestResults{}
failedTargets := []core.BuildLabel{}
failedNonTests := []core.BuildLabel{}
for result := range state.Results {
processResult(state, result, buildingTargets, &aggregatedResults, plainOutput, keepGoing, &failedTargets, &failedNonTests, failedTargetMap, traceFile != "")
}
if !plainOutput {
stop <- struct{}{}
<-displayDone
}
if traceFile != "" {
writeTrace(traceFile)
}
duration := time.Since(startTime).Seconds()
if len(failedNonTests) > 0 { // Something failed in the build step.
if state.Verbosity > 0 {
printFailedBuildResults(failedNonTests, failedTargetMap, duration)
}
// Die immediately and unsuccessfully, this avoids awkward interactions with
// --failing_tests_ok later on.
os.Exit(-1)
}
// Check all the targets we wanted to build actually have been built.
for _, label := range state.ExpandOriginalTargets() {
if target := state.Graph.Target(label); target == nil {
log.Fatalf("Target %s doesn't exist in build graph", label)
} else if (state.NeedHashesOnly || state.PrepareOnly) && target.State() == core.Stopped {
// Do nothing, we will output about this shortly.
} else if shouldBuild && target != nil && target.State() < core.Built && len(failedTargetMap) == 0 {
cycle := graphCycleMessage(state.Graph, target)
log.Fatalf("Target %s hasn't built but we have no pending tasks left.\n%s", label, cycle)
}
}
if state.Verbosity > 0 && shouldBuild {
if shouldTest { // Got to the test phase, report their results.
printTestResults(state, aggregatedResults, failedTargets, duration)
} else if state.NeedHashesOnly {
printHashes(state, duration)
} else if state.PrepareOnly {
printTempDirs(state, duration)
} else if !shouldRun { // Must be plz build or similar, report build outputs.
printBuildResults(state, duration)
}
}
return len(failedTargetMap) == 0
}
示例9: printHashes
func printHashes(state *core.BuildState, duration float64) {
fmt.Printf("Hashes calculated, total time %0.2fs:\n", duration)
for _, label := range state.ExpandOriginalTargets() {
hash, err := build.OutputHash(state.Graph.TargetOrDie(label))
if err != nil {
fmt.Printf(" %s: cannot calculate: %s\n", label, err)
} else {
fmt.Printf(" %s: %s\n", label, hex.EncodeToString(hash))
}
}
}
示例10: printTempDirs
func printTempDirs(state *core.BuildState, duration float64) {
fmt.Printf("Temp directories prepared, total time %0.2fs:\n", duration)
for _, label := range state.ExpandOriginalTargets() {
target := state.Graph.TargetOrDie(label)
cmd := build.ReplaceSequences(target, target.GetCommand())
env := core.BuildEnvironment(state, target, false)
fmt.Printf(" %s: %s\n", label, target.TmpDir())
fmt.Printf(" Command: %s\n", cmd)
fmt.Printf(" Expanded: %s\n", os.Expand(cmd, core.ReplaceEnvironment(env)))
}
}
示例11: findOriginalTasks
// findOriginalTasks finds the original parse tasks for the original set of targets.
func findOriginalTasks(state *core.BuildState, targets []core.BuildLabel) {
for _, target := range targets {
if target == core.BuildLabelStdin {
for label := range utils.ReadStdin() {
findOriginalTask(state, core.ParseBuildLabels([]string{label})[0])
}
} else {
findOriginalTask(state, target)
}
}
state.TaskDone() // initial target adding counts as one.
}
示例12: logTestSuccess
func logTestSuccess(state *core.BuildState, tid int, label core.BuildLabel, results core.TestResults, coverage core.TestCoverage) {
var description string
tests := pluralise("test", results.NumTests)
if results.Skipped != 0 || results.ExpectedFailures != 0 {
failures := pluralise("failure", results.ExpectedFailures)
description = fmt.Sprintf("%d %s passed. %d skipped, %d expected %s",
results.NumTests, tests, results.Skipped, results.ExpectedFailures, failures)
} else {
description = fmt.Sprintf("%d %s passed.", results.NumTests, tests)
}
state.LogTestResult(tid, label, core.TargetTested, results, coverage, nil, description)
}
示例13: please
// please mimics the core build 'loop' from src/please.go.
func please(tid int, state *core.BuildState) {
for {
label, _, t := state.NextTask()
switch t {
case core.Stop, core.Kill:
return
case core.Build:
Build(tid, state, label)
default:
panic(fmt.Sprintf("unexpected task type: %d", t))
}
state.TaskDone()
}
}
示例14: Build
func Build(tid int, state *core.BuildState, label core.BuildLabel) {
start := time.Now()
target := state.Graph.TargetOrDie(label)
target.SetState(core.Building)
if err := buildTarget(tid, state, target); err != nil {
if err == stopTarget {
target.SetState(core.Stopped)
state.LogBuildResult(tid, target.Label, core.TargetBuildStopped, "Build stopped")
return
}
state.LogBuildError(tid, label, core.TargetBuildFailed, err, "Build failed: %s", err)
if err := RemoveOutputs(target); err != nil {
log.Errorf("Failed to remove outputs for %s: %s", target.Label, err)
}
target.SetState(core.Failed)
return
}
metrics.Record(target, time.Since(start))
// Add any of the reverse deps that are now fully built to the queue.
for _, reverseDep := range state.Graph.ReverseDependencies(target) {
if reverseDep.State() == core.Active && state.Graph.AllDepsBuilt(reverseDep) && reverseDep.SyncUpdateState(core.Active, core.Pending) {
state.AddPendingBuild(reverseDep.Label, false)
}
}
if target.IsTest && state.NeedTests {
state.AddPendingTest(target.Label)
}
parse.UndeferAnyParses(state, target)
}
示例15: updateTarget
func updateTarget(state *core.BuildState, plainOutput bool, buildingTarget *buildingTarget, label core.BuildLabel,
active bool, failed bool, cached bool, description string, err error, colour string) {
updateTarget2(buildingTarget, label, active, failed, cached, description, err, colour)
if plainOutput {
if failed {
log.Errorf("%s: %s", label.String(), description)
} else {
if !active {
active := pluralise(state.NumActive(), "task", "tasks")
log.Notice("[%d/%s] %s: %s [%3.1fs]", state.NumDone(), active, label.String(), description, time.Now().Sub(buildingTarget.Started).Seconds())
} else {
log.Info("%s: %s", label.String(), description)
}
}
}
}