From 7e60d06cfc83ebba5b8a66663793780dad2ec666 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 28 Mar 2014 14:59:25 -0700 Subject: [PATCH] go.tools/cmd/godex: don't generate prefixes for local and absolute path arguments LGTM=adonovan R=adonovan CC=golang-codereviews https://golang.org/cl/81340047 --- cmd/godex/godex.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/godex/godex.go b/cmd/godex/godex.go index d1e773a3..3948f88a 100644 --- a/cmd/godex/godex.go +++ b/cmd/godex/godex.go @@ -64,9 +64,9 @@ func main() { logf("\tprocessing %q: path = %q, name = %s\n", arg, path, name) // generate possible package path prefixes - // (at the moment we do this for each argument - should probably cache this) + // (at the moment we do this for each argument - should probably cache the generated prefixes) prefixes := make(chan string) - go genPrefixes(prefixes) + go genPrefixes(prefixes, !filepath.IsAbs(path) && !build.IsLocalImport(path)) // import package pkg, err := tryPrefixes(packages, prefixes, path, imp) @@ -172,12 +172,14 @@ func lookup(src string) types.Importer { return nil } -func genPrefixes(out chan string) { - out <- "" // try no prefix - platform := build.Default.GOOS + "_" + build.Default.GOARCH - dirnames := append([]string{build.Default.GOROOT}, filepath.SplitList(build.Default.GOPATH)...) - for _, dirname := range dirnames { - walkDir(filepath.Join(dirname, "pkg", platform), "", out) +func genPrefixes(out chan string, all bool) { + out <- "" + if all { + platform := build.Default.GOOS + "_" + build.Default.GOARCH + dirnames := append([]string{build.Default.GOROOT}, filepath.SplitList(build.Default.GOPATH)...) + for _, dirname := range dirnames { + walkDir(filepath.Join(dirname, "pkg", platform), "", out) + } } close(out) }