gopkg.in/tools/godep.v51@v51.0.0-20160121191931-64044a295f54/pkg.go (about) 1 package main 2 3 import ( 4 "regexp" 5 "strings" 6 ) 7 8 // Package represents a Go package. 9 type Package struct { 10 Dir string 11 Root string 12 ImportPath string 13 Deps []string 14 Standard bool 15 Processed bool 16 17 GoFiles []string 18 CgoFiles []string 19 IgnoredGoFiles []string 20 21 TestGoFiles []string 22 TestImports []string 23 XTestGoFiles []string 24 XTestImports []string 25 26 Error struct { 27 Err string 28 } 29 30 // --- New stuff for now 31 Imports []string 32 } 33 34 // LoadPackages loads the named packages using go list -json. 35 // Unlike the go tool, an empty argument list is treated as an empty list; "." 36 // must be given explicitly if desired. 37 // IgnoredGoFiles will be processed and their dependencies resolved recursively 38 // Files with a build tag of `ignore` are skipped. Files with other build tags 39 // are however processed. 40 func LoadPackages(names ...string) (a []*Package, err error) { 41 debugln("LoadPackages", names) 42 if len(names) == 0 { 43 return nil, nil 44 } 45 for _, i := range importPaths(names) { 46 p, err := listPackage(i) 47 if err != nil { 48 return nil, err 49 } 50 a = append(a, p) 51 } 52 return a, nil 53 } 54 55 func (p *Package) allGoFiles() []string { 56 var a []string 57 a = append(a, p.GoFiles...) 58 a = append(a, p.CgoFiles...) 59 a = append(a, p.TestGoFiles...) 60 a = append(a, p.XTestGoFiles...) 61 a = append(a, p.IgnoredGoFiles...) 62 return a 63 } 64 65 // matchPattern(pattern)(name) reports whether 66 // name matches pattern. Pattern is a limited glob 67 // pattern in which '...' means 'any string' and there 68 // is no other special syntax. 69 // Taken from $GOROOT/src/cmd/go/main.go. 70 func matchPattern(pattern string) func(name string) bool { 71 re := regexp.QuoteMeta(pattern) 72 re = strings.Replace(re, `\.\.\.`, `.*`, -1) 73 // Special case: foo/... matches foo too. 74 if strings.HasSuffix(re, `/.*`) { 75 re = re[:len(re)-len(`/.*`)] + `(/.*)?` 76 } 77 reg := regexp.MustCompile(`^` + re + `$`) 78 return func(name string) bool { 79 return reg.MatchString(name) 80 } 81 }