diff --git a/cmd/godoc/main.go b/cmd/godoc/main.go index 66beabdbf5..89e9bba8f6 100644 --- a/cmd/godoc/main.go +++ b/cmd/godoc/main.go @@ -183,6 +183,9 @@ func main() { usage() } + // Setting the resolved goroot. + vfs.GOROOT = *goroot + var fsGate chan bool fsGate = make(chan bool, 20) diff --git a/godoc/vfs/os.go b/godoc/vfs/os.go index 8cc9ed1990..78719b46ad 100644 --- a/godoc/vfs/os.go +++ b/godoc/vfs/os.go @@ -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 diff --git a/godoc/vfs/zipfs/zipfs.go b/godoc/vfs/zipfs/zipfs.go index 6d27f63624..b216f55827 100644 --- a/godoc/vfs/zipfs/zipfs.go +++ b/godoc/vfs/zipfs/zipfs.go @@ -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