diff --git a/go/packages/golist_fallback.go b/go/packages/golist_fallback.go index ca08cf7e13e..141fa19ac19 100644 --- a/go/packages/golist_fallback.go +++ b/go/packages/golist_fallback.go @@ -89,11 +89,7 @@ func golistDriverFallback(cfg *Config, words ...string) (*driverResponse, error) return "", err } } - // Add a "go-build" component to the path to make the tests think the files are in the cache. - // This allows the same test to test the pre- and post-Go 1.11 go list logic because the Go 1.11 - // go list generates test mains in the cache, and the test code knows not to rely on paths in the - // cache to stay stable. - outdir = filepath.Join(tmpdir, "go-build", strings.Replace(p.ImportPath, "/", "_", -1)) + outdir = filepath.Join(tmpdir, strings.Replace(p.ImportPath, "/", "_", -1)) if err := os.MkdirAll(outdir, 0755); err != nil { outdir = "" return "", err @@ -200,7 +196,11 @@ func golistDriverFallback(cfg *Config, words ...string) (*driverResponse, error) }) return } - testmain := filepath.Join(outdir, "testmain.go") + // Don't use a .go extension on the file, so that the tests think the file is inside GOCACHE. + // This allows the same test to test the pre- and post-Go 1.11 go list logic because the Go 1.11 + // go list generates test mains in the cache, and the test code knows not to rely on paths in the + // cache to stay stable. + testmain := filepath.Join(outdir, "testmain-go") extraimports, extradeps, err := generateTestmain(testmain, testPkg, xtestPkg) if err != nil { testmainPkg.Errors = append(testmainPkg.Errors, Error{ diff --git a/go/packages/packages_test.go b/go/packages/packages_test.go index 3ef87ffa22f..bf7f1da770d 100644 --- a/go/packages/packages_test.go +++ b/go/packages/packages_test.go @@ -1413,19 +1413,19 @@ func testJSON(t *testing.T, exporter packagestest.Exporter) { ID: "golang.org/fake/b", Name: "b", Imports: map[string]*packages.Package{ - "golang.org/fake/a": &packages.Package{ID: "golang.org/fake/a"}, + "golang.org/fake/a": {ID: "golang.org/fake/a"}, }, }, { ID: "golang.org/fake/c", Name: "c", Imports: map[string]*packages.Package{ - "golang.org/fake/b": &packages.Package{ID: "golang.org/fake/b"}, + "golang.org/fake/b": {ID: "golang.org/fake/b"}, }, }, { ID: "golang.org/fake/d", Name: "d", Imports: map[string]*packages.Package{ - "golang.org/fake/b": &packages.Package{ID: "golang.org/fake/b"}, + "golang.org/fake/b": {ID: "golang.org/fake/b"}, }, }} { got := decoded[i] @@ -1646,12 +1646,13 @@ func srcs(p *packages.Package) []string { func cleanPaths(paths []string) []string { result := make([]string, len(paths)) for i, src := range paths { - // The default location for cache data is a subdirectory named go-build - // in the standard user cache directory for the current operating system. - if strings.Contains(filepath.ToSlash(src), "/go-build/") { + // If the source file doesn't have an extension like .go or .s, + // it comes from GOCACHE. The names there aren't predictable. + name := filepath.Base(src) + if !strings.Contains(name, ".") { result[i] = fmt.Sprintf("%d.go", i) // make cache names predictable } else { - result[i] = filepath.Base(src) + result[i] = name } } return result