From f1247de5721e9160ce5be066f0064d59a1750281 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Mon, 21 Apr 2014 18:34:22 -0400 Subject: [PATCH] go.tools/cmd/doc: make filename logic separator-agnostic (Speculative fix for broken cmd/godoc test on Windows.) LGTM=gri R=gri CC=golang-codereviews https://golang.org/cl/90090043 --- godoc/analysis/analysis.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/godoc/analysis/analysis.go b/godoc/analysis/analysis.go index 8eb1c4a2..8c6254ab 100644 --- a/godoc/analysis/analysis.go +++ b/godoc/analysis/analysis.go @@ -311,17 +311,17 @@ func Run(pta bool, result *Result) { errors[err.Pos] = append(errors[err.Pos], err.Msg) } - var roots, args []string + var roots, args []string // roots[i] ends with os.PathSeparator // Enumerate packages in $GOROOT. - root := runtime.GOROOT() + "/src/pkg/" + root := filepath.Join(runtime.GOROOT(), "src", "pkg") + string(os.PathSeparator) roots = append(roots, root) args = allPackages(root) log.Printf("GOROOT=%s: %s\n", root, args) // Enumerate packages in $GOPATH. for i, dir := range filepath.SplitList(build.Default.GOPATH) { - root := dir + "/src/" + root := filepath.Join(dir, "src") + string(os.PathSeparator) roots = append(roots, root) pkgs := allPackages(root) log.Printf("GOPATH[%d]=%s: %s\n", i, root, pkgs) @@ -524,10 +524,8 @@ func (a linksByStart) Len() int { return len(a) } // allPackages returns a new sorted slice of all packages beneath the // specified package root directory, e.g. $GOROOT/src/pkg or $GOPATH/src. // Derived from from go/ssa/stdlib_test.go +// root must end with os.PathSeparator. func allPackages(root string) []string { - if !strings.HasSuffix(root, "/") { - root += "/" - } var pkgs []string filepath.Walk(root, func(path string, info os.FileInfo, err error) error { if info == nil {