1
0
mirror of https://github.com/golang/go synced 2024-09-30 16:28:32 -06:00

godoc: update to use new goroot finding logic

The logic to determine whether a filesystem root was in GOROOT or GOPATH
still relied on runtime.GOROOT(), whereas cmd/godoc was updated to copy
the goroot finding logic from standard library.

Hence, godoc is unable to determine if a filesystem is in GOROOT or not
when the binary is outside runtime.GOROOT(). So we expose a new variable
and set that from cmd/godoc to avoid copying the logic again for the 3rd time.

Fixes golang/go#27162

Change-Id: I160dcdbdd262e671f09f7bf01c329be5eac280ad
Reviewed-on: https://go-review.googlesource.com/130796
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Agniva De Sarker 2018-08-23 10:54:26 +05:30 committed by Brad Fitzpatrick
parent 447b503c8b
commit ba93f9405e
3 changed files with 13 additions and 3 deletions

View File

@ -183,6 +183,9 @@ func main() {
usage()
}
// Setting the resolved goroot.
vfs.GOROOT = *goroot
var fsGate chan bool
fsGate = make(chan bool, 20)

View File

@ -14,6 +14,14 @@ import (
"runtime"
)
// GOROOT returns the GOROOT path under which the godoc binary is running.
// It is needed to check whether a filesystem root is under GOROOT or not.
// This is set from cmd/godoc/main.go
// We expose a new variable because otherwise we need to copy the findGOROOT logic again
// from cmd/godoc which is already copied twice from the standard library.
var GOROOT = runtime.GOROOT()
// OS returns an implementation of FileSystem reading from the
// tree rooted at root. Recording a root is convenient everywhere
// but necessary on Windows, because the slash-separated path
@ -22,7 +30,7 @@ import (
func OS(root string) FileSystem {
var t RootType
switch {
case root == runtime.GOROOT():
case root == GOROOT:
t = RootTypeGoRoot
case isGoPath(root):
t = RootTypeGoPath

View File

@ -25,7 +25,6 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"sort"
"strings"
"time"
@ -87,7 +86,7 @@ func (fs *zipFS) String() string {
func (fs *zipFS) RootType(abspath string) vfs.RootType {
var t vfs.RootType
switch {
case abspath == runtime.GOROOT():
case abspath == vfs.GOROOT:
t = vfs.RootTypeGoRoot
case isGoPath(abspath):
t = vfs.RootTypeGoPath