]> Cypherpunks repositories - gostls13.git/commitdiff
Ugly hack to provide some mechanism for printing documentation about
authorRob Pike <r@golang.org>
Fri, 5 Feb 2010 21:53:46 +0000 (08:53 +1100)
committerRob Pike <r@golang.org>
Fri, 5 Feb 2010 21:53:46 +0000 (08:53 +1100)
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

src/cmd/godoc/godoc.go
src/cmd/godoc/main.go

index b49487e5b89c0e32a1875fe7214429efa4b1abbc..97ed329fe25f1586b402d2cd9be39a9630545fbd 100644 (file)
@@ -1043,8 +1043,20 @@ type httpHandler struct {
 // PageInfo.Dirs is nil.
 //
 func (h *httpHandler) getPageInfo(path string, try bool) PageInfo {
-       // the path is relative to h.fsroot
-       dirname := pathutil.Join(h.fsRoot, path)
+       var dirname string
+       // 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
        // (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 {
        // filter function to select the desired .go files
        filter := func(d *os.Dir) bool {
                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
                        // files that belong to the expected package so that
                        // parser.ParsePackage doesn't return "multiple packages
index 7a3b9f384a10605a750d36cb83c5c631bc3c9e3b..f475d8fa1026efd3d0f60f6e3e4d69bf57fb837d 100644 (file)
@@ -47,6 +47,9 @@ var (
 
        // layout control
        html = flag.Bool("html", false, "print HTML in command-line mode")
+
+       // --- Hack to remember current directory
+       workingDir string
 )
 
 
@@ -152,6 +155,13 @@ func main() {
                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 {
                log.Exitf("chdir %s: %v", goroot, err)
        }