mirror of
https://github.com/golang/go
synced 2024-11-05 16:26:11 -07:00
go.tools/cmd/godex: make relative package paths work
LGTM=adonovan R=adonovan CC=golang-codereviews https://golang.org/cl/89160044
This commit is contained in:
parent
f8200537d8
commit
de6fbfe0ea
@ -115,13 +115,21 @@ func splitPathIdent(arg string) (path, name string) {
|
||||
// with an error.
|
||||
func tryPrefixes(packages map[string]*types.Package, prefixes chan string, path string, imp types.Importer) (pkg *types.Package, err error) {
|
||||
for prefix := range prefixes {
|
||||
logf("\ttrying prefix %q\n", prefix)
|
||||
prepath := filepath.Join(prefix, path)
|
||||
pkg, err = imp(packages, prepath)
|
||||
actual := path
|
||||
if prefix == "" {
|
||||
// don't use filepath.Join as it will sanitize the path and remove
|
||||
// a leading dot and then the path is not recognized as a relative
|
||||
// package path by the importers anymore
|
||||
logf("\ttrying no prefix\n")
|
||||
} else {
|
||||
actual = filepath.Join(prefix, path)
|
||||
logf("\ttrying prefix %q\n", prefix)
|
||||
}
|
||||
pkg, err = imp(packages, actual)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
logf("\t=> importing %q failed: %s\n", prepath, err)
|
||||
logf("\t=> importing %q failed: %s\n", actual, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user