]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/godoc: fixes
authorRuss Cox <rsc@golang.org>
Tue, 6 Mar 2012 03:47:35 +0000 (22:47 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 6 Mar 2012 03:47:35 +0000 (22:47 -0500)
These appear to have been left out of the CL I submitted earlier.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5759043

src/cmd/godoc/main.go

index f66e78413889db443d237ec885862d04a7ae16cd..893f611e76e4fbfb738169d4465b4e596e5559e1 100644 (file)
@@ -368,25 +368,32 @@ func main() {
                return
        }
 
-       // determine paths
+       // Determine paths.
+       //
+       // If we are passed an operating system path like . or ./foo or /foo/bar or c:\mysrc,
+       // we need to map that path somewhere in the fs name space so that routines
+       // like getPageInfo will see it.  We use the arbitrarily-chosen virtual path "/target"
+       // for this.  That is, if we get passed a directory like the above, we map that
+       // directory so that getPageInfo sees it as /target.
+       const target = "/target"
        const cmdPrefix = "cmd/"
        path := flag.Arg(0)
        var forceCmd bool
        var abspath, relpath string
        if filepath.IsAbs(path) {
-               fs.Bind("/target", OS(path), "/", bindReplace)
-               abspath = "/target"
+               fs.Bind(target, OS(path), "/", bindReplace)
+               abspath = target
        } else if build.IsLocalImport(path) {
                cwd, _ := os.Getwd() // ignore errors
                path = filepath.Join(cwd, path)
-               fs.Bind("/target", OS(path), "/", bindReplace)
-               abspath = "/target"
+               fs.Bind(target, OS(path), "/", bindReplace)
+               abspath = target
        } else if strings.HasPrefix(path, cmdPrefix) {
-               abspath = path[len(cmdPrefix):]
+               path = path[len(cmdPrefix):]
                forceCmd = true
        } else if bp, _ := build.Import(path, "", build.FindOnly); bp.Dir != "" && bp.ImportPath != "" {
-               fs.Bind("/target", OS(bp.Dir), "/", bindReplace)
-               abspath = "/target"
+               fs.Bind(target, OS(bp.Dir), "/", bindReplace)
+               abspath = target
                relpath = bp.ImportPath
        } else {
                abspath = pathpkg.Join(pkgHandler.fsRoot, path)
@@ -443,7 +450,8 @@ func main() {
        if info.Err != nil {
                log.Fatalf("%v", info.Err)
        }
-       if info.PDoc.ImportPath == "/target" {
+       if info.PDoc != nil && info.PDoc.ImportPath == target {
+               // Replace virtual /target with actual argument from command line.
                info.PDoc.ImportPath = flag.Arg(0)
        }