Commit cd2ecfb7 authored by Rob Pike's avatar Rob Pike

Ugly hack to provide some mechanism for printing documentation about

Go source outside $GOROOT.

If the argument is a path starting with / or ., disregard $GOROOT.
Also, disable the check for package name matching the directory,
which is counterproductive in this case.

Apologies for the violence to the code but we need some help documenting
Go code outside the standard repository.

R=gri
CC=golang-dev
https://golang.org/cl/201064
parent d5b946f4
...@@ -1043,8 +1043,20 @@ type httpHandler struct { ...@@ -1043,8 +1043,20 @@ type httpHandler struct {
// PageInfo.Dirs is nil. // PageInfo.Dirs is nil.
// //
func (h *httpHandler) getPageInfo(path string, try bool) PageInfo { func (h *httpHandler) getPageInfo(path string, try bool) PageInfo {
// the path is relative to h.fsroot var dirname string
dirname := pathutil.Join(h.fsRoot, path) // If the path starts with a slash or ., ignore $GOROOT.
// It would be nice to handle "./dir" too, but godoc chdirs to $GOROOT. TODO: fix.
if len(path) > 0 && path[0] == '/' {
dirname = path
// --- Start of hack
} else if len(path) > 0 && path[0] == '.' && workingDir != "" {
path = pathutil.Join(workingDir, path)
dirname = path
// --- End of hack
} else {
// the path is relative to h.fsroot
dirname = pathutil.Join(h.fsRoot, path)
}
// the package name is the directory name within its parent // the package name is the directory name within its parent
// (use dirname instead of path because dirname is clean; i.e. has no trailing '/') // (use dirname instead of path because dirname is clean; i.e. has no trailing '/')
...@@ -1053,6 +1065,20 @@ func (h *httpHandler) getPageInfo(path string, try bool) PageInfo { ...@@ -1053,6 +1065,20 @@ func (h *httpHandler) getPageInfo(path string, try bool) PageInfo {
// filter function to select the desired .go files // filter function to select the desired .go files
filter := func(d *os.Dir) bool { filter := func(d *os.Dir) bool {
if isPkgFile(d) { if isPkgFile(d) {
// --- Start of hack.
// An ugly special case: If the path is rooted, just say
// yes in the hope we'll get some output from a directory
// outside $GOROOT. Ugly but effective for command-line
// output but may not find everything if there are multiple
// packages in the directory, since godoc assumes one
// package per directory.
// TODO: Do this better.
if len(path) > 0 && path[0] == '/' {
return true
}
// --- End of hack.
// Some directories contain main packages: Only accept // Some directories contain main packages: Only accept
// files that belong to the expected package so that // files that belong to the expected package so that
// parser.ParsePackage doesn't return "multiple packages // parser.ParsePackage doesn't return "multiple packages
......
...@@ -47,6 +47,9 @@ var ( ...@@ -47,6 +47,9 @@ var (
// layout control // layout control
html = flag.Bool("html", false, "print HTML in command-line mode") html = flag.Bool("html", false, "print HTML in command-line mode")
// --- Hack to remember current directory
workingDir string
) )
...@@ -152,6 +155,13 @@ func main() { ...@@ -152,6 +155,13 @@ func main() {
log.Exitf("negative tabwidth %d", *tabwidth) log.Exitf("negative tabwidth %d", *tabwidth)
} }
// --- Start of hack.
// Remember where we were, so "." works as a directory name.
// Error's not worth worrying about; we just check for empty string
// when we need it.
workingDir, _ = os.Getwd()
// --- End of hack.
if err := os.Chdir(goroot); err != nil { if err := os.Chdir(goroot); err != nil {
log.Exitf("chdir %s: %v", goroot, err) log.Exitf("chdir %s: %v", goroot, err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment