本文整理汇总了Golang中core.BuildTarget.State方法的典型用法代码示例。如果您正苦于以下问题:Golang BuildTarget.State方法的具体用法?Golang BuildTarget.State怎么用?Golang BuildTarget.State使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.BuildTarget
的用法示例。
在下文中一共展示了BuildTarget.State方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getLabels
func getLabels(target *core.BuildTarget, prefix string, minState core.BuildTargetState) []string {
if target.State() < minState {
log.Fatalf("get_labels called on a target that is not yet built: %s", target.Label)
}
labels := map[string]bool{}
done := map[*core.BuildTarget]bool{}
var getLabels func(*core.BuildTarget)
getLabels = func(t *core.BuildTarget) {
for _, label := range t.Labels {
if strings.HasPrefix(label, prefix) {
labels[strings.TrimSpace(strings.TrimPrefix(label, prefix))] = true
}
}
done[t] = true
if !t.OutputIsComplete || t == target {
for _, dep := range t.Dependencies() {
if !done[dep] {
getLabels(dep)
}
}
}
}
getLabels(target)
ret := make([]string, len(labels))
i := 0
for label := range labels {
ret[i] = label
i++
}
sort.Strings(ret)
return ret
}
示例2: record
func (m *metrics) record(target *core.BuildTarget, duration time.Duration) {
if target.Results.NumTests > 0 {
// Tests have run
m.cacheCounter.WithLabelValues(b(target.Results.Cached)).Inc()
m.testCounter.WithLabelValues(b(target.Results.Failed == 0)).Inc()
if target.Results.Cached {
m.cacheHistogram.WithLabelValues().Observe(duration.Seconds())
} else if target.Results.Failed == 0 {
m.testHistogram.WithLabelValues().Observe(duration.Seconds())
}
} else {
// Build has run
state := target.State()
m.cacheCounter.WithLabelValues(b(state == core.Cached)).Inc()
m.buildCounter.WithLabelValues(b(state != core.Failed), b(state != core.Reused)).Inc()
if state == core.Cached {
m.cacheHistogram.WithLabelValues().Observe(duration.Seconds())
} else if state != core.Failed && state >= core.Built {
m.buildHistogram.WithLabelValues().Observe(duration.Seconds())
}
}
m.newMetrics = true
}
示例3: test
func test(tid int, state *core.BuildState, label core.BuildLabel, target *core.BuildTarget) {
startTime := time.Now()
hash, err := build.RuntimeHash(state, target)
if err != nil {
state.LogBuildError(tid, label, core.TargetTestFailed, err, "Failed to calculate target hash")
return
}
// Check the cached output files if the target wasn't rebuilt.
hash = core.CollapseHash(hash)
hashStr := base64.RawURLEncoding.EncodeToString(hash)
resultsFileName := fmt.Sprintf(".test_results_%s_%s", label.Name, hashStr)
coverageFileName := fmt.Sprintf(".test_coverage_%s_%s", label.Name, hashStr)
outputFile := path.Join(target.TestDir(), "test.results")
coverageFile := path.Join(target.TestDir(), "test.coverage")
cachedOutputFile := path.Join(target.OutDir(), resultsFileName)
cachedCoverageFile := path.Join(target.OutDir(), coverageFileName)
needCoverage := state.NeedCoverage && !target.NoTestOutput
cachedTest := func() {
log.Debug("Not re-running test %s; got cached results.", label)
coverage := parseCoverageFile(target, cachedCoverageFile)
results, err := parseTestResults(target, cachedOutputFile, true)
target.Results.Duration = time.Since(startTime).Seconds()
target.Results.Cached = true
if err != nil {
state.LogBuildError(tid, label, core.TargetTestFailed, err, "Failed to parse cached test file %s", cachedOutputFile)
} else if results.Failed > 0 {
panic("Test results with failures shouldn't be cached.")
} else {
logTestSuccess(state, tid, label, results, coverage)
}
}
moveAndCacheOutputFiles := func(results core.TestResults, coverage core.TestCoverage) bool {
// Never cache test results when given arguments; the results may be incomplete.
if len(state.TestArgs) > 0 {
log.Debug("Not caching results for %s, we passed it arguments", label)
return true
}
if err := moveAndCacheOutputFile(state, target, hash, outputFile, cachedOutputFile, resultsFileName, dummyOutput); err != nil {
state.LogTestResult(tid, label, core.TargetTestFailed, results, coverage, err, "Failed to move test output file")
return false
}
if needCoverage || core.PathExists(coverageFile) {
if err := moveAndCacheOutputFile(state, target, hash, coverageFile, cachedCoverageFile, coverageFileName, dummyCoverage); err != nil {
state.LogTestResult(tid, label, core.TargetTestFailed, results, coverage, err, "Failed to move test coverage file")
return false
}
}
for _, output := range target.TestOutputs {
tmpFile := path.Join(target.TestDir(), output)
outFile := path.Join(target.OutDir(), output)
if err := moveAndCacheOutputFile(state, target, hash, tmpFile, outFile, output, ""); err != nil {
state.LogTestResult(tid, label, core.TargetTestFailed, results, coverage, err, "Failed to move test output file")
return false
}
}
return true
}
needToRun := func() bool {
if target.State() == core.Unchanged && core.PathExists(cachedOutputFile) {
// Output file exists already and appears to be valid. We might still need to rerun though
// if the coverage files aren't available.
if needCoverage && !core.PathExists(cachedCoverageFile) {
return true
}
return false
}
// Check the cache for these artifacts.
if state.Cache == nil {
return true
}
cache := *state.Cache
if !cache.RetrieveExtra(target, hash, resultsFileName) {
return true
}
if needCoverage && !cache.RetrieveExtra(target, hash, coverageFileName) {
return true
}
for _, output := range target.TestOutputs {
if !cache.RetrieveExtra(target, hash, output) {
return true
}
}
return false
}
// Don't cache when doing multiple runs, presumably the user explicitly wants to check it.
if state.NumTestRuns <= 1 && !needToRun() {
cachedTest()
return
}
// Remove any cached test result file.
if err := RemoveCachedTestFiles(target); err != nil {
state.LogBuildError(tid, label, core.TargetTestFailed, err, "Failed to remove cached test files")
return
}
numSucceeded := 0
numFlakes := 0
//.........这里部分代码省略.........