本文整理汇总了Golang中go/build.Package.IgnoredGoFiles方法的典型用法代码示例。如果您正苦于以下问题:Golang Package.IgnoredGoFiles方法的具体用法?Golang Package.IgnoredGoFiles怎么用?Golang Package.IgnoredGoFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/build.Package
的用法示例。
在下文中一共展示了Package.IgnoredGoFiles方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: fillPackage
// fillPackage full of info. Assumes a build.Package discovered in build.FindOnly mode
func fillPackage(p *build.Package) error {
if p.Goroot {
return nil
}
var buildMatch = "+build "
var buildFieldSplit = func(r rune) bool {
return unicode.IsSpace(r) || r == ','
}
debugln("Filling package:", p.ImportPath, "from", p.Dir)
gofiles, err := filepath.Glob(filepath.Join(p.Dir, "*.go"))
if err != nil {
debugln("Error globbing", err)
return err
}
var testImports []string
var imports []string
NextFile:
for _, file := range gofiles {
debugln(file)
fset := token.NewFileSet()
pf, err := parser.ParseFile(fset, file, nil, parser.ParseComments)
if err != nil {
return err
}
testFile := strings.HasSuffix(file, "_test.go")
fname := filepath.Base(file)
if testFile {
p.TestGoFiles = append(p.TestGoFiles, fname)
} else {
p.GoFiles = append(p.GoFiles, fname)
}
if len(pf.Comments) > 0 {
for _, c := range pf.Comments {
ct := c.Text()
if i := strings.Index(ct, buildMatch); i != -1 {
for _, b := range strings.FieldsFunc(ct[i+len(buildMatch):], buildFieldSplit) {
//TODO: appengine is a special case for now: https://github.com/tools/godep/issues/353
if b == "ignore" || b == "appengine" {
p.IgnoredGoFiles = append(p.IgnoredGoFiles, fname)
continue NextFile
}
}
}
}
}
for _, is := range pf.Imports {
name, err := strconv.Unquote(is.Path.Value)
if err != nil {
return err // can't happen?
}
if testFile {
testImports = append(testImports, name)
} else {
imports = append(imports, name)
}
}
}
imports = uniq(imports)
testImports = uniq(testImports)
p.Imports = imports
p.TestImports = testImports
return nil
}
示例2: fillPackage
// fillPackage full of info. Assumes p.Dir is set at a minimum
func fillPackage(p *build.Package) error {
if p.Goroot {
return nil
}
if p.SrcRoot == "" {
for _, base := range build.Default.SrcDirs() {
if strings.HasPrefix(p.Dir, base) {
p.SrcRoot = base
}
}
}
if p.SrcRoot == "" {
return errors.New("Unable to find SrcRoot for package " + p.ImportPath)
}
if p.Root == "" {
p.Root = filepath.Dir(p.SrcRoot)
}
var buildMatch = "+build "
var buildFieldSplit = func(r rune) bool {
return unicode.IsSpace(r) || r == ','
}
debugln("Filling package:", p.ImportPath, "from", p.Dir)
gofiles, err := filepath.Glob(filepath.Join(p.Dir, "*.go"))
if err != nil {
debugln("Error globbing", err)
return err
}
var testImports []string
var imports []string
NextFile:
for _, file := range gofiles {
debugln(file)
pf, err := parser.ParseFile(token.NewFileSet(), file, nil, parser.ImportsOnly|parser.ParseComments)
if err != nil {
return err
}
testFile := strings.HasSuffix(file, "_test.go")
fname := filepath.Base(file)
for _, c := range pf.Comments {
ct := c.Text()
if i := strings.Index(ct, buildMatch); i != -1 {
for _, t := range strings.FieldsFunc(ct[i+len(buildMatch):], buildFieldSplit) {
for _, tag := range ignoreTags {
if t == tag {
p.IgnoredGoFiles = append(p.IgnoredGoFiles, fname)
continue NextFile
}
}
if versionMatch.MatchString(t) && !isSameOrNewer(t, majorGoVersion) {
debugln("Adding", fname, "to ignored list because of version tag", t)
p.IgnoredGoFiles = append(p.IgnoredGoFiles, fname)
continue NextFile
}
if versionNegativeMatch.MatchString(t) && isSameOrNewer(t[1:], majorGoVersion) {
debugln("Adding", fname, "to ignored list because of version tag", t)
p.IgnoredGoFiles = append(p.IgnoredGoFiles, fname)
continue NextFile
}
}
}
}
if testFile {
p.TestGoFiles = append(p.TestGoFiles, fname)
} else {
p.GoFiles = append(p.GoFiles, fname)
}
for _, is := range pf.Imports {
name, err := strconv.Unquote(is.Path.Value)
if err != nil {
return err // can't happen?
}
if testFile {
testImports = append(testImports, name)
} else {
imports = append(imports, name)
}
}
}
imports = uniq(imports)
testImports = uniq(testImports)
p.Imports = imports
p.TestImports = testImports
return nil
}