diff --git a/go/loader/stdlib_test.go b/go/loader/stdlib_test.go index 3eba7b29b0..7c09322b66 100644 --- a/go/loader/stdlib_test.go +++ b/go/loader/stdlib_test.go @@ -17,42 +17,17 @@ import ( "go/build" "go/token" "io/ioutil" - "os" "path/filepath" "runtime" "strings" "testing" "time" + "code.google.com/p/go.tools/go/buildutil" "code.google.com/p/go.tools/go/loader" "code.google.com/p/go.tools/go/types" ) -func allPackages() []string { - var pkgs []string - root := filepath.Join(runtime.GOROOT(), "src") + string(os.PathSeparator) - filepath.Walk(root, func(path string, info os.FileInfo, err error) error { - // Prune the search if we encounter any of these names: - switch filepath.Base(path) { - case "testdata", ".hg": - return filepath.SkipDir - } - if info.IsDir() { - pkg := filepath.ToSlash(strings.TrimPrefix(path, root)) - switch pkg { - case "builtin", "pkg": - return filepath.SkipDir // skip these subtrees - case "": - return nil // ignore root of tree - } - pkgs = append(pkgs, pkg) - } - - return nil - }) - return pkgs -} - func TestStdlib(t *testing.T) { runtime.GC() t0 := time.Now() @@ -61,8 +36,10 @@ func TestStdlib(t *testing.T) { alloc := memstats.Alloc // Load, parse and type-check the program. - var conf loader.Config - for _, path := range allPackages() { + ctxt := build.Default // copy + ctxt.GOPATH = "" // disable GOPATH + conf := loader.Config{Build: &ctxt} + for _, path := range buildutil.AllPackagesList(conf.Build) { if err := conf.ImportWithTests(path); err != nil { t.Error(err) } diff --git a/go/pointer/stdlib_test.go b/go/pointer/stdlib_test.go index f6a2ab4879..d0fd4f6447 100644 --- a/go/pointer/stdlib_test.go +++ b/go/pointer/stdlib_test.go @@ -14,14 +14,12 @@ package pointer import ( "flag" + "go/build" "go/token" - "os" - "path/filepath" - "runtime" - "strings" "testing" "time" + "code.google.com/p/go.tools/go/buildutil" "code.google.com/p/go.tools/go/loader" "code.google.com/p/go.tools/go/ssa" "code.google.com/p/go.tools/go/ssa/ssautil" @@ -29,42 +27,19 @@ import ( var runStdlibTest = flag.Bool("stdlib", false, "Run the (slow) stdlib test") -// TODO(adonovan): move this to go/buildutil package since we have four copies: -// go/{loader,pointer,ssa}/stdlib_test.go and godoc/analysis/analysis.go. -func allPackages() []string { - var pkgs []string - root := filepath.Join(runtime.GOROOT(), "src") + string(os.PathSeparator) - filepath.Walk(root, func(path string, info os.FileInfo, err error) error { - // Prune the search if we encounter any of these names: - switch filepath.Base(path) { - case "testdata", ".hg": - return filepath.SkipDir - } - if info.IsDir() { - pkg := filepath.ToSlash(strings.TrimPrefix(path, root)) - switch pkg { - case "builtin", "pkg": - return filepath.SkipDir // skip these subtrees - case "": - return nil // ignore root of tree - } - pkgs = append(pkgs, pkg) - } - - return nil - }) - return pkgs -} - func TestStdlib(t *testing.T) { if !*runStdlibTest { t.Skip("skipping (slow) stdlib test (use --stdlib)") } // Load, parse and type-check the program. - var conf loader.Config - conf.SourceImports = true - if _, err := conf.FromArgs(allPackages(), true); err != nil { + ctxt := build.Default // copy + ctxt.GOPATH = "" // disable GOPATH + conf := loader.Config{ + SourceImports: true, + Build: &ctxt, + } + if _, err := conf.FromArgs(buildutil.AllPackagesList(conf.Build), true); err != nil { t.Errorf("FromArgs failed: %v", err) return } diff --git a/go/ssa/stdlib_test.go b/go/ssa/stdlib_test.go index 708c1ae6db..14a8b54e75 100644 --- a/go/ssa/stdlib_test.go +++ b/go/ssa/stdlib_test.go @@ -10,51 +10,30 @@ package ssa_test // Run test with GOMAXPROCS=8. import ( + "go/build" "go/token" - "os" - "path/filepath" "runtime" - "strings" "testing" "time" + "code.google.com/p/go.tools/go/buildutil" "code.google.com/p/go.tools/go/loader" "code.google.com/p/go.tools/go/ssa" "code.google.com/p/go.tools/go/ssa/ssautil" ) -func allPackages() []string { - var pkgs []string - root := filepath.Join(runtime.GOROOT(), "src") + string(os.PathSeparator) - filepath.Walk(root, func(path string, info os.FileInfo, err error) error { - // Prune the search if we encounter any of these names: - switch filepath.Base(path) { - case "testdata", ".hg": - return filepath.SkipDir - } - if info.IsDir() { - pkg := filepath.ToSlash(strings.TrimPrefix(path, root)) - switch pkg { - case "builtin", "pkg": - return filepath.SkipDir // skip these subtrees - case "": - return nil // ignore root of tree - } - pkgs = append(pkgs, pkg) - } - - return nil - }) - return pkgs -} - func TestStdlib(t *testing.T) { // Load, parse and type-check the program. t0 := time.Now() - var conf loader.Config - conf.SourceImports = true - if _, err := conf.FromArgs(allPackages(), true); err != nil { + // Load, parse and type-check the program. + ctxt := build.Default // copy + ctxt.GOPATH = "" // disable GOPATH + conf := loader.Config{ + SourceImports: true, + Build: &ctxt, + } + if _, err := conf.FromArgs(buildutil.AllPackagesList(conf.Build), true); err != nil { t.Errorf("FromArgs failed: %v", err) return } diff --git a/godoc/analysis/analysis.go b/godoc/analysis/analysis.go index f426f13f19..ae84bbcca7 100644 --- a/godoc/analysis/analysis.go +++ b/godoc/analysis/analysis.go @@ -575,6 +575,8 @@ func (a linksByStart) Len() int { return len(a) } // specified package root directory, e.g. $GOROOT/src or $GOPATH/src. // Derived from from go/ssa/stdlib_test.go // root must end with os.PathSeparator. +// +// TODO(adonovan): use buildutil.AllPackages when the tree thaws. func allPackages(root string) []string { var pkgs []string filepath.Walk(root, func(path string, info os.FileInfo, err error) error {