mirror of
https://github.com/golang/go.git
synced 2025-05-06 08:03:03 +00: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.
|
// with an error.
|
||||||
func tryPrefixes(packages map[string]*types.Package, prefixes chan string, path string, imp types.Importer) (pkg *types.Package, err 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 {
|
for prefix := range prefixes {
|
||||||
|
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)
|
logf("\ttrying prefix %q\n", prefix)
|
||||||
prepath := filepath.Join(prefix, path)
|
}
|
||||||
pkg, err = imp(packages, prepath)
|
pkg, err = imp(packages, actual)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
logf("\t=> importing %q failed: %s\n", prepath, err)
|
logf("\t=> importing %q failed: %s\n", actual, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user