1
0
mirror of https://github.com/golang/go synced 2024-11-18 17:54:57 -07:00

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 <adonovan@google.com>
This commit is contained in:
Michael Matloob 2018-10-01 18:02:39 -04:00
parent cb0b336180
commit 34d7740906
2 changed files with 5 additions and 2 deletions

View File

@ -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.

View File

@ -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)
}
}