aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gerrand <adg@golang.org>2011-07-02 14:07:06 +1000
committerAndrew Gerrand <adg@golang.org>2011-07-02 14:07:06 +1000
commit3cd8f27d79604ac119ce732e87ac8a44fb998aaf (patch)
tree3fa722e978ff12856452e51bb5c109ef5e30ea24
parent72a73198dfac573e824d7aeb83be5cae6df45fd2 (diff)
downloadgo-3cd8f27d79604ac119ce732e87ac8a44fb998aaf.tar.gz
go-3cd8f27d79604ac119ce732e87ac8a44fb998aaf.zip
godoc: search GOPATH for documentation
R=rsc, mattn.jp CC=golang-dev https://golang.org/cl/4627065
-rw-r--r--src/cmd/godoc/godoc.go11
-rw-r--r--src/cmd/godoc/main.go6
-rw-r--r--src/cmd/godoc/mapping.go12
3 files changed, 21 insertions, 8 deletions
diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go
index 8209781225..20ebd31835 100644
--- a/src/cmd/godoc/godoc.go
+++ b/src/cmd/godoc/godoc.go
@@ -9,6 +9,7 @@ import (
"flag"
"fmt"
"go/ast"
+ "go/build"
"go/doc"
"go/printer"
"go/token"
@@ -83,7 +84,15 @@ var (
func initHandlers() {
- fsMap.Init(*pkgPath)
+ paths := filepath.SplitList(*pkgPath)
+ for _, t := range build.Path {
+ if t.Goroot {
+ continue
+ }
+ paths = append(paths, t.SrcDir())
+ }
+ fsMap.Init(paths)
+
fileServer = http.FileServer(http.Dir(*goroot))
cmdHandler = httpHandler{"/cmd/", filepath.Join(*goroot, "src", "cmd"), false}
pkgHandler = httpHandler{"/pkg/", filepath.Join(*goroot, "src", "pkg"), true}
diff --git a/src/cmd/godoc/main.go b/src/cmd/godoc/main.go
index 55f6031bc4..51fcf8dd05 100644
--- a/src/cmd/godoc/main.go
+++ b/src/cmd/godoc/main.go
@@ -31,6 +31,7 @@ import (
"flag"
"fmt"
"go/ast"
+ "go/build"
"http"
_ "http/pprof" // to serve /debug/pprof/*
"io"
@@ -332,7 +333,10 @@ func main() {
}
relpath := path
abspath := path
- if !filepath.IsAbs(path) {
+ if t, pkg, err := build.FindTree(path); err == nil {
+ relpath = pkg
+ abspath = filepath.Join(t.SrcDir(), pkg)
+ } else if !filepath.IsAbs(path) {
abspath = absolutePath(path, pkgHandler.fsRoot)
} else {
relpath = relativeURL(path)
diff --git a/src/cmd/godoc/mapping.go b/src/cmd/godoc/mapping.go
index 73f1881a2d..83f34810cc 100644
--- a/src/cmd/godoc/mapping.go
+++ b/src/cmd/godoc/mapping.go
@@ -59,10 +59,10 @@ type mapping struct {
}
-// Init initializes the Mapping from a list of paths separated by
-// filepath.ListSeparator. Empty paths are ignored; relative paths
-// are assumed to be relative to the current working directory and
-// converted to absolute paths. For each path of the form:
+// Init initializes the Mapping from a list of paths.
+// Empty paths are ignored; relative paths are assumed to be relative to
+// the current working directory and converted to absolute paths.
+// For each path of the form:
//
// dirname/localname
//
@@ -80,8 +80,8 @@ type mapping struct {
// user -> /home/user
// public -> /home/build/public
//
-func (m *Mapping) Init(paths string) {
- pathlist := canonicalizePaths(filepath.SplitList(paths), nil)
+func (m *Mapping) Init(paths []string) {
+ pathlist := canonicalizePaths(paths, nil)
list := make([]mapping, len(pathlist))
// create mapping list