本文整理汇总了Golang中go/build.Context.UseAllFiles方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.UseAllFiles方法的具体用法?Golang Context.UseAllFiles怎么用?Golang Context.UseAllFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/build.Context
的用法示例。
在下文中一共展示了Context.UseAllFiles方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: scanPackage
func scanPackage(ctxt *build.Context, t *build.Tree, arg, importPath, dir string, stk *importStack, useAllFiles bool) *Package {
// Read the files in the directory to learn the structure
// of the package.
p := &Package{
ImportPath: importPath,
Dir: dir,
Standard: t.Goroot && !strings.Contains(importPath, "."),
t: t,
}
packageCache[dir] = p
packageCache[importPath] = p
ctxt.UseAllFiles = useAllFiles
info, err := ctxt.ScanDir(dir)
useAllFiles = false // flag does not apply to dependencies
if err != nil {
p.Error = &PackageError{
ImportStack: stk.copy(),
Err: err.Error(),
}
// Look for parser errors.
if err, ok := err.(scanner.ErrorList); ok {
// Prepare error with \n before each message.
// When printed in something like context: %v
// this will put the leading file positions each on
// its own line. It will also show all the errors
// instead of just the first, as err.Error does.
var buf bytes.Buffer
for _, e := range err {
buf.WriteString("\n")
buf.WriteString(e.Error())
}
p.Error.Err = buf.String()
}
p.Incomplete = true
return p
}
p.info = info
p.Name = info.Package
p.Doc = doc.Synopsis(info.PackageComment.Text())
p.Imports = info.Imports
p.GoFiles = info.GoFiles
p.TestGoFiles = info.TestGoFiles
p.XTestGoFiles = info.XTestGoFiles
p.CFiles = info.CFiles
p.HFiles = info.HFiles
p.SFiles = info.SFiles
p.CgoFiles = info.CgoFiles
p.CgoCFLAGS = info.CgoCFLAGS
p.CgoLDFLAGS = info.CgoLDFLAGS
if info.Package == "main" {
_, elem := filepath.Split(importPath)
full := ctxt.GOOS + "_" + ctxt.GOARCH + "/" + elem
if t.Goroot && isGoTool[p.ImportPath] {
p.target = filepath.Join(t.Path, "pkg/tool", full)
} else {
if ctxt.GOOS != toolGOOS || ctxt.GOARCH != toolGOARCH {
// Install cross-compiled binaries to subdirectories of bin.
elem = full
}
p.target = filepath.Join(t.BinDir(), elem)
}
if ctxt.GOOS == "windows" {
p.target += ".exe"
}
} else {
dir := t.PkgDir()
// For gccgo, rewrite p.target with the expected library name.
if _, ok := buildToolchain.(gccgoToolchain); ok {
dir = filepath.Join(filepath.Dir(dir), "gccgo", filepath.Base(dir))
}
p.target = buildToolchain.pkgpath(dir, p)
}
var built time.Time
if fi, err := os.Stat(p.target); err == nil {
built = fi.ModTime()
}
// Build list of full paths to all Go files in the package,
// for use by commands like go fmt.
for _, f := range info.GoFiles {
p.gofiles = append(p.gofiles, filepath.Join(dir, f))
}
for _, f := range info.CgoFiles {
p.gofiles = append(p.gofiles, filepath.Join(dir, f))
}
for _, f := range info.TestGoFiles {
p.gofiles = append(p.gofiles, filepath.Join(dir, f))
}
for _, f := range info.XTestGoFiles {
p.gofiles = append(p.gofiles, filepath.Join(dir, f))
}
sort.Strings(p.gofiles)
srcss := [][]string{
p.GoFiles,
//.........这里部分代码省略.........