本文整理汇总了Golang中core.BuildTarget类的典型用法代码示例。如果您正苦于以下问题:Golang BuildTarget类的具体用法?Golang BuildTarget怎么用?Golang BuildTarget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BuildTarget类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: RetrieveExtra
func (cache *dirCache) RetrieveExtra(target *core.BuildTarget, key []byte, out string) bool {
outDir := path.Join(core.RepoRoot, target.OutDir())
cacheDir := cache.getPath(target, key)
cachedOut := path.Join(cacheDir, out)
realOut := path.Join(outDir, out)
if !core.PathExists(cachedOut) {
log.Debug("%s: %s doesn't exist in dir cache", target.Label, cachedOut)
return false
}
log.Debug("Retrieving %s: %s from dir cache...", target.Label, cachedOut)
if dir := path.Dir(realOut); dir != "." {
if err := os.MkdirAll(dir, core.DirPermissions); err != nil {
log.Warning("Failed to create output directory %s: %s", dir, err)
return false
}
}
// It seems to be quite important that we unlink the existing file first to avoid ETXTBSY errors
// in cases where we're running an existing binary (as Please does during bootstrap, for example).
if err := os.RemoveAll(realOut); err != nil {
log.Warning("Failed to unlink existing output %s: %s", realOut, err)
return false
}
// Recursively hardlink files back out of the cache
if err := core.RecursiveCopyFile(cachedOut, realOut, fileMode(target), true, true); err != nil {
log.Warning("Failed to move cached file to output: %s -> %s: %s", cachedOut, realOut, err)
return false
}
log.Debug("Retrieved %s: %s from dir cache", target.Label, cachedOut)
return true
}
开发者ID:thought-machine,项目名称:please,代码行数:30,代码来源:dir_cache.go
示例2: StoreExtra
func (cache *httpCache) StoreExtra(target *core.BuildTarget, key []byte, file string) {
if cache.Writeable {
artifact := path.Join(
cache.OSName,
target.Label.PackageName,
target.Label.Name,
base64.RawURLEncoding.EncodeToString(key),
file,
)
log.Info("Storing %s: %s in http cache...", target.Label, artifact)
// NB. Don't need to close this file, http.Post will do it for us.
file, err := os.Open(path.Join(target.OutDir(), file))
if err != nil {
log.Warning("Failed to read artifact: %s", err)
return
}
response, err := http.Post(cache.Url+"/artifact/"+artifact, "application/octet-stream", file)
if err != nil {
log.Warning("Failed to send artifact to %s: %s", cache.Url+"/artifact/"+artifact, err)
} else if response.StatusCode < 200 || response.StatusCode > 299 {
log.Warning("Failed to send artifact to %s: got response %s", cache.Url+"/artifact/"+artifact, response.Status)
}
response.Body.Close()
}
}
开发者ID:thought-machine,项目名称:please,代码行数:26,代码来源:http_cache.go
示例3: retrieveArtifacts
func (cache *rpcCache) retrieveArtifacts(target *core.BuildTarget, req *pb.RetrieveRequest, remove bool) bool {
ctx, cancel := context.WithTimeout(context.Background(), cache.timeout)
defer cancel()
response, err := cache.client.Retrieve(ctx, req)
if err != nil {
log.Warning("Failed to retrieve artifacts for %s", target.Label)
cache.error()
return false
} else if !response.Success {
// Quiet, this is almost certainly just a 'not found'
log.Debug("Couldn't retrieve artifacts for %s [key %s] from RPC cache", target.Label, base64.RawURLEncoding.EncodeToString(req.Hash))
return false
}
// Remove any existing outputs first; this is important for cases where the output is a
// directory, because we get back individual artifacts, and we need to make sure that
// only the retrieved artifacts are present in the output.
if remove {
for _, out := range target.Outputs() {
out := path.Join(target.OutDir(), out)
if err := os.RemoveAll(out); err != nil {
log.Error("Failed to remove artifact %s: %s", out, err)
return false
}
}
}
for _, artifact := range response.Artifacts {
if !cache.writeFile(target, artifact.File, artifact.Body) {
return false
}
}
// Sanity check: if we don't get anything back, assume it probably wasn't really a success.
return len(response.Artifacts) > 0
}
开发者ID:thought-machine,项目名称:please,代码行数:33,代码来源:rpc_cache.go
示例4: collectAllFiles
// Collects all the source files from a single target
func collectAllFiles(state *core.BuildState, target *core.BuildTarget, coveragePackages, allFiles map[string]bool, doneTargets map[*core.BuildTarget]bool, includeAllFiles bool) {
doneTargets[target] = true
if !includeAllFiles && !coveragePackages[target.Label.PackageName] {
return
}
// Small hack here; explore these targets when we don't have any sources yet. Helps languages
// like Java where we generate a wrapper target with a complete one immediately underneath.
// TODO(pebers): do we still need this now we have Java sourcemaps?
if !target.OutputIsComplete || len(allFiles) == 0 {
for _, dep := range target.Dependencies() {
if !doneTargets[dep] {
collectAllFiles(state, dep, coveragePackages, allFiles, doneTargets, includeAllFiles)
}
}
}
if target.IsTest {
return // Test sources don't count for coverage.
}
for _, path := range target.AllSourcePaths(state.Graph) {
extension := filepath.Ext(path)
for _, ext := range state.Config.Cover.FileExtension {
if ext == extension {
allFiles[path] = target.IsTest || target.TestOnly // Skip test source files from actual coverage display
break
}
}
}
}
开发者ID:thought-machine,项目名称:please,代码行数:29,代码来源:coverage.go
示例5: 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
}
开发者ID:thought-machine,项目名称:please,代码行数:32,代码来源:interpreter.go
示例6: checkAndReplaceSequence
func checkAndReplaceSequence(target, dep *core.BuildTarget, in string, runnable, multiple, dir, outPrefix, hash, test, allOutputs, tool bool) string {
if allOutputs && !multiple && len(dep.Outputs()) != 1 {
// Label must have only one output.
panic(fmt.Sprintf("Rule %s can't use %s; %s has multiple outputs.", target.Label, in, dep.Label))
} else if runnable && !dep.IsBinary {
panic(fmt.Sprintf("Rule %s can't $(exe %s), it's not executable", target.Label, dep.Label))
} else if runnable && len(dep.Outputs()) == 0 {
panic(fmt.Sprintf("Rule %s is tagged as binary but produces no output.", dep.Label))
}
if hash {
return base64.RawURLEncoding.EncodeToString(mustShortTargetHash(core.State, dep))
}
output := ""
for _, out := range dep.Outputs() {
if allOutputs || out == in {
if tool {
abs, err := filepath.Abs(handleDir(dep.OutDir(), out, dir))
if err != nil {
log.Fatalf("Couldn't calculate relative path: %s", err)
}
output += quote(abs) + " "
} else {
output += quote(fileDestination(target, dep, out, dir, outPrefix, test)) + " "
}
if dir {
break
}
}
}
if runnable && dep.HasLabel("java_non_exe") {
// The target is a Java target that isn't self-executable, hence it needs something to run it.
output = "java -jar " + output
}
return strings.TrimRight(output, " ")
}
开发者ID:thought-machine,项目名称:please,代码行数:35,代码来源:command_replacements.go
示例7: findGraphCycle
// Attempts to detect cycles in the build graph. Returns an empty slice if none is found,
// otherwise returns a slice of labels describing the cycle.
func findGraphCycle(graph *core.BuildGraph, target *core.BuildTarget) []*core.BuildTarget {
index := func(haystack []*core.BuildTarget, needle *core.BuildTarget) int {
for i, straw := range haystack {
if straw == needle {
return i
}
}
return -1
}
var detectCycle func(*core.BuildTarget, []*core.BuildTarget) []*core.BuildTarget
detectCycle = func(target *core.BuildTarget, deps []*core.BuildTarget) []*core.BuildTarget {
if i := index(deps, target); i != -1 {
return deps[i:]
}
deps = append(deps, target)
for _, dep := range target.Dependencies() {
if cycle := detectCycle(dep, deps); len(cycle) > 0 {
return cycle
}
}
return nil
}
return detectCycle(target, nil)
}
开发者ID:thought-machine,项目名称:please,代码行数:27,代码来源:shell_output.go
示例8: loadArtifacts
func (cache *rpcCache) loadArtifacts(target *core.BuildTarget, file string) ([]*pb.Artifact, int, error) {
artifacts := []*pb.Artifact{}
outDir := target.OutDir()
root := path.Join(outDir, file)
totalSize := 1000 // Allow a little space for encoding overhead.
err := filepath.Walk(root, func(name string, info os.FileInfo, err error) error {
if err != nil {
return err
} else if !info.IsDir() {
content, err := ioutil.ReadFile(name)
if err != nil {
return err
}
artifacts = append(artifacts, &pb.Artifact{
Package: target.Label.PackageName,
Target: target.Label.Name,
File: name[len(outDir)+1:],
Body: content,
})
totalSize += len(content)
}
return nil
})
return artifacts, totalSize, err
}
开发者ID:thought-machine,项目名称:please,代码行数:25,代码来源:rpc_cache.go
示例9: fileDestination
func fileDestination(target, dep *core.BuildTarget, out string, dir, outPrefix, test bool) string {
if outPrefix {
return handleDir(dep.OutDir(), out, dir)
}
if test && target == dep {
// Slightly fiddly case because tests put binaries in a possibly slightly unusual place.
return "./" + out
}
return handleDir(dep.Label.PackageName, out, dir)
}
开发者ID:thought-machine,项目名称:please,代码行数:10,代码来源:command_replacements.go
示例10: cacheArtifacts
// Yields all cacheable artifacts from this target. Useful for cache implementations
// to not have to reinvent logic around post-build functions etc.
func cacheArtifacts(target *core.BuildTarget) <-chan string {
ch := make(chan string, 10)
go func() {
for _, out := range target.Outputs() {
ch <- out
}
close(ch)
}()
return ch
}
开发者ID:thought-machine,项目名称:please,代码行数:12,代码来源:cache.go
示例11: RemoveOutputs
// RemoveOutputs removes all generated outputs for a rule.
func RemoveOutputs(target *core.BuildTarget) error {
if err := os.Remove(ruleHashFileName(target)); err != nil && !os.IsNotExist(err) {
return err
}
for _, output := range target.Outputs() {
if err := os.RemoveAll(path.Join(target.OutDir(), output)); err != nil {
return err
}
}
return nil
}
开发者ID:thought-machine,项目名称:please,代码行数:12,代码来源:build_step.go
示例12: loadPostBuildOutput
// For targets that have post-build functions, we have to store and retrieve the target's
// output to feed to it
func loadPostBuildOutput(state *core.BuildState, target *core.BuildTarget) string {
// Normally filegroups don't have post-build functions, but we use this sometimes for testing.
if target.IsFilegroup() {
return ""
}
out, err := ioutil.ReadFile(postBuildOutputFileName(target))
if err != nil {
panic(err)
}
return string(out)
}
开发者ID:thought-machine,项目名称:please,代码行数:13,代码来源:incrementality.go
示例13: runTest
func runTest(state *core.BuildState, target *core.BuildTarget) ([]byte, error) {
replacedCmd := build.ReplaceTestSequences(target, target.GetTestCommand())
env := core.BuildEnvironment(state, target, true)
if len(state.TestArgs) > 0 {
args := strings.Join(state.TestArgs, " ")
replacedCmd += " " + args
env = append(env, "TESTS="+args)
}
log.Debug("Running test %s\nENVIRONMENT:\n%s\n%s", target.Label, strings.Join(env, "\n"), replacedCmd)
_, out, err := core.ExecWithTimeoutShell(target.TestDir(), env, target.TestTimeout, state.Config.Test.Timeout, state.ShowAllOutput, replacedCmd)
return out, err
}
开发者ID:thought-machine,项目名称:please,代码行数:12,代码来源:test_step.go
示例14: retrieveFile
// retrieveFile retrieves a single file (or directory) from a Docker container.
func retrieveFile(target *core.BuildTarget, cid []byte, filename string, warn bool) {
log.Debug("Attempting to retrieve file %s for %s...", filename, target.Label)
timeout := core.State.Config.Docker.ResultsTimeout
cmd := []string{"docker", "cp", string(cid) + ":/tmp/test/" + filename, target.TestDir()}
if out, err := core.ExecWithTimeoutSimple(timeout, cmd...); err != nil {
if warn {
log.Warning("Failed to retrieve results for %s: %s [%s]", target.Label, err, out)
} else {
log.Debug("Failed to retrieve results for %s: %s [%s]", target.Label, err, out)
}
}
}
开发者ID:thought-machine,项目名称:please,代码行数:13,代码来源:container.go
示例15: writeFile
func (cache *rpcCache) writeFile(target *core.BuildTarget, file string, body []byte) bool {
out := path.Join(target.OutDir(), file)
if err := os.MkdirAll(path.Dir(out), core.DirPermissions); err != nil {
log.Warning("Failed to create directory for artifacts: %s", err)
return false
}
if err := core.WriteFile(bytes.NewReader(body), out, fileMode(target)); err != nil {
log.Warning("RPC cache failed to write file %s", err)
return false
}
log.Debug("Retrieved %s - %s from RPC cache", target.Label, file)
return true
}
开发者ID:thought-machine,项目名称:please,代码行数:13,代码来源:rpc_cache.go
示例16: replaceSequenceLabel
func replaceSequenceLabel(target *core.BuildTarget, label core.BuildLabel, in string, runnable, multiple, dir, outPrefix, hash, test, allOutputs bool) string {
// Check this label is a dependency of the target, otherwise it's not allowed.
if label == target.Label { // targets can always use themselves.
return checkAndReplaceSequence(target, target, in, runnable, multiple, dir, outPrefix, hash, test, allOutputs, false)
}
deps := target.DependenciesFor(label)
if len(deps) == 0 {
panic(fmt.Sprintf("Rule %s can't use %s; doesn't depend on target %s", target.Label, in, label))
}
// TODO(pebers): this does not correctly handle the case where there are multiple deps here
// (but is better than the previous case where it never worked at all)
return checkAndReplaceSequence(target, deps[0], in, runnable, multiple, dir, outPrefix, hash, test, allOutputs, target.IsTool(label))
}
开发者ID:thought-machine,项目名称:please,代码行数:13,代码来源:command_replacements.go
示例17: prepareTestDir
func prepareTestDir(graph *core.BuildGraph, target *core.BuildTarget) error {
if err := os.RemoveAll(target.TestDir()); err != nil {
return err
}
if err := os.MkdirAll(target.TestDir(), core.DirPermissions); err != nil {
return err
}
for out := range core.IterRuntimeFiles(graph, target, true) {
if err := core.PrepareSourcePair(out); err != nil {
return err
}
}
return nil
}
开发者ID:thought-machine,项目名称:please,代码行数:14,代码来源:test_step.go
示例18: OutputHash
// OutputHash calculates the hash of a target's outputs.
func OutputHash(target *core.BuildTarget) ([]byte, error) {
h := sha1.New()
for _, output := range target.Outputs() {
// NB. Always force a recalculation of the output hashes here. Memoisation is not
// useful because by definition we are rebuilding a target, and can actively hurt
// in cases where we compare the retrieved cache artifacts with what was there before.
h2, err := pathHash(path.Join(target.OutDir(), output), true)
if err != nil {
return nil, err
}
h.Write(h2)
}
return h.Sum(nil), nil
}
开发者ID:thought-machine,项目名称:please,代码行数:15,代码来源:build_step.go
示例19: printTarget
func printTarget(state *core.BuildState, target *core.BuildTarget, indent string, targets map[*core.BuildTarget]bool, unique bool) {
if unique && targets[target] {
return
}
targets[target] = true
if target.ShouldInclude(state.Include, state.Exclude) {
fmt.Printf("%s%s\n", indent, target.Label)
}
if !unique {
indent = indent + " "
}
for _, dep := range target.Dependencies() {
printTarget(state, dep, indent, targets, unique)
}
}
开发者ID:thought-machine,项目名称:please,代码行数:15,代码来源:deps.go
示例20: replaceSequence
// Replaces a single escape sequence in a command.
func replaceSequence(target *core.BuildTarget, in string, runnable, multiple, dir, outPrefix, hash, test bool) string {
if core.LooksLikeABuildLabel(in) {
label := core.ParseBuildLabel(in, target.Label.PackageName)
return replaceSequenceLabel(target, label, in, runnable, multiple, dir, outPrefix, hash, test, true)
}
for _, src := range target.AllSources() {
if label := src.Label(); label != nil && src.String() == in {
return replaceSequenceLabel(target, *label, in, runnable, multiple, dir, outPrefix, hash, test, false)
}
}
if hash {
return base64.RawURLEncoding.EncodeToString(mustPathHash(path.Join(target.Label.PackageName, in)))
}
return quote(path.Join(target.Label.PackageName, in))
}
开发者ID:thought-machine,项目名称:please,代码行数:16,代码来源:command_replacements.go
注:本文中的core.BuildTarget类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论