[go: nahoru, domu]

Skip to content

Commit

Permalink
remove vendor prefix when storing packages
Browse files Browse the repository at this point in the history
This standardizes vendored packages so that they can be found using
the string from another package's .Imports list.
  • Loading branch information
davcamer authored and kisielk committed Feb 6, 2018
1 parent 054b885 commit 0622891
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func processPackage(root string, pkgName string, level int) error {
return nil
}

pkgs[pkg.ImportPath] = pkg
pkgs[normalizeVendor(pkg.ImportPath)] = pkg

// Don't worry about dependencies for stdlib packages
if pkg.Goroot && !*delveGoroot {
Expand All @@ -162,7 +162,7 @@ func getImports(pkg *build.Package) []string {
var imports []string
found := make(map[string]struct{})
for _, imp := range allImports {
if imp == pkg.ImportPath {
if imp == normalizeVendor(pkg.ImportPath) {
// Don't draw a self-reference when foo_test depends on foo.
continue
}
Expand Down Expand Up @@ -195,10 +195,10 @@ func hasPrefixes(s string, prefixes []string) bool {
}

func isIgnored(pkg *build.Package) bool {
if len(onlyPrefixes) > 0 && !hasPrefixes(pkg.ImportPath, onlyPrefixes) {
if len(onlyPrefixes) > 0 && !hasPrefixes(normalizeVendor(pkg.ImportPath), onlyPrefixes) {
return true
}
return ignored[pkg.ImportPath] || (pkg.Goroot && *ignoreStdlib) || hasPrefixes(pkg.ImportPath, ignoredPrefixes)
return ignored[normalizeVendor(pkg.ImportPath)] || (pkg.Goroot && *ignoreStdlib) || hasPrefixes(normalizeVendor(pkg.ImportPath), ignoredPrefixes)
}

func debug(args ...interface{}) {
Expand All @@ -208,3 +208,8 @@ func debug(args ...interface{}) {
func debugf(s string, args ...interface{}) {
fmt.Fprintf(os.Stderr, s, args...)
}

func normalizeVendor(path string) string {
pieces := strings.Split(path, "vendor/")
return pieces[len(pieces) - 1]
}

0 comments on commit 0622891

Please sign in to comment.