本文整理匯總了Golang中core.BuildState.LogBuildError方法的典型用法代碼示例。如果您正苦於以下問題:Golang BuildState.LogBuildError方法的具體用法?Golang BuildState.LogBuildError怎麽用?Golang BuildState.LogBuildError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類core.BuildState
的用法示例。
在下文中一共展示了BuildState.LogBuildError方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
示例2: 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)
}
示例3: RunPreBuildFunction
// RunPreBuildFunction runs a pre-build callback function registered on a build target via pre_build = <...>.
//
// This is called before the target is built. It doesn't receive any output like the post-build one does but can
// be useful for other things; for example if you want to investigate a target's transitive labels to adjust
// its build command, you have to do that here (because in general the transitive dependencies aren't known
// when the rule is evaluated).
func RunPreBuildFunction(tid int, state *core.BuildState, target *core.BuildTarget) error {
state.LogBuildResult(tid, target.Label, core.PackageParsing,
fmt.Sprintf("Running pre-build function for %s", target.Label))
pkg := state.Graph.Package(target.Label.PackageName)
pkg.BuildCallbackMutex.Lock()
defer pkg.BuildCallbackMutex.Unlock()
if err := runPreBuildFunction(pkg, target); err != nil {
state.LogBuildError(tid, target.Label, core.ParseFailed, err, "Failed pre-build function for %s", target.Label)
return err
}
rescanDeps(state, pkg)
state.LogBuildResult(tid, target.Label, core.TargetBuilding,
fmt.Sprintf("Finished pre-build function for %s", target.Label))
return nil
}
示例4: Parse
// Parses the package corresponding to a single build label. The label can be :all to add all targets in a package.
// It is not an error if the package has already been parsed.
//
// By default, after the package is parsed, any targets that are now needed for the build and ready
// to be built are queued, and any new packages are queued for parsing. When a specific label is requested
// this is straightforward, but when parsing for pseudo-targets like :all and ..., various flags affect it:
// If 'noDeps' is true, then no new packages will be added and no new targets queued.
// 'include' and 'exclude' refer to the labels of targets to be added. If 'include' is non-empty then only
// targets with at least one matching label are added. Any targets with a label in 'exclude' are not added.
func Parse(tid int, state *core.BuildState, label, dependor core.BuildLabel, noDeps bool, include, exclude []string) {
defer func() {
if r := recover(); r != nil {
state.LogBuildError(tid, label, core.ParseFailed, fmt.Errorf("%s", r), "Failed to parse package")
}
}()
// First see if this package already exists; once it's in the graph it will have been parsed.
pkg := state.Graph.Package(label.PackageName)
if pkg != nil {
// Does exist, all we need to do is toggle on this target
activateTarget(state, pkg, label, dependor, noDeps, include, exclude)
return
}
// We use the name here to signal undeferring of a package. If we get that we need to retry the package regardless.
if dependor.Name != "_UNDEFER_" && !firstToParse(label, dependor) {
// Check this again to avoid a potential race
if pkg = state.Graph.Package(label.PackageName); pkg != nil {
activateTarget(state, pkg, label, dependor, noDeps, include, exclude)
} else {
log.Debug("Adding pending parse for %s", label)
}
return
}
// If we get here then it falls to us to parse this package
state.LogBuildResult(tid, label, core.PackageParsing, "Parsing...")
pkg = parsePackage(state, label, dependor)
if pkg == nil {
state.LogBuildResult(tid, label, core.PackageParsed, "Deferred")
return
}
// Now add any lurking pending targets for this package.
pendingTargetMutex.Lock()
pending := pendingTargets[label.PackageName] // Must be present.
pendingTargets[label.PackageName] = map[string][]core.BuildLabel{} // Empty this to free memory, but leave a sentinel
pendingTargetMutex.Unlock() // Nothing will look up this package in the map again.
for targetName, dependors := range pending {
for _, dependor := range dependors {
lbl := core.BuildLabel{PackageName: label.PackageName, Name: targetName}
activateTarget(state, pkg, lbl, dependor, noDeps, include, exclude)
}
}
state.LogBuildResult(tid, label, core.PackageParsed, "Parsed")
}
示例5: 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
//.........這裏部分代碼省略.........