From 34d7740906d5daa29039c6f6c0c9311dabcfc274 Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Mon, 1 Oct 2018 18:02:39 -0400 Subject: [PATCH] gopackages: don't make .go files relative to search path A previous change (golang.org/cl/137096) that made absolute package paths relative to GOROOT or GOPATH entries also accidentally applied to .go filesnames. Filter those out of the list of paths considered to make relative to search path. (package paths that don't start with './' or '/' are relative to GOROOT or GOPATH, but filenames are not.) Change-Id: I67fbd0e5caa7e53f3ab5b77f55d6841fe2132578 Reviewed-on: https://go-review.googlesource.com/c/138880 Reviewed-by: Alan Donovan --- go/packages/golist_fallback.go | 5 ++++- go/packages/packages_test.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/go/packages/golist_fallback.go b/go/packages/golist_fallback.go index 21cffac7..55fe8058 100644 --- a/go/packages/golist_fallback.go +++ b/go/packages/golist_fallback.go @@ -304,7 +304,10 @@ func cleanAbsPaths(cfg *Config, words []string) []string { var cleaned = make([]string, len(words)) for i := range cleaned { cleaned[i] = words[i] - if !filepath.IsAbs(cleaned[i]) { + // Ignore relative directory paths (they must already be goroot-relative) and Go source files + // (absolute source files are already allowed for ad-hoc packages). + // TODO(matloob): Can there be non-.go files in ad-hoc packages. + if !filepath.IsAbs(cleaned[i]) || strings.HasSuffix(cleaned[i], ".go") { continue } // otherwise, it's an absolute path. Search GOPATH and GOROOT to find it. diff --git a/go/packages/packages_test.go b/go/packages/packages_test.go index a91633d4..ff485e7b 100644 --- a/go/packages/packages_test.go +++ b/go/packages/packages_test.go @@ -202,7 +202,7 @@ func TestLoadImportsGraph(t *testing.T) { t.Errorf("failed to obtain metadata for ad-hoc package: %s", err) } else { got := fmt.Sprintf("%s %s", initial[0].ID, srcs(initial[0])) - if want := "command-line-arguments [c.go]"; got != want && !usesOldGolist { + if want := "command-line-arguments [c.go]"; got != want { t.Errorf("oops: got %s, want %s", got, want) } }