mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00: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:
parent
447b503c8b
commit
ba93f9405e
@ -183,6 +183,9 @@ func main() {
|
|||||||
usage()
|
usage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setting the resolved goroot.
|
||||||
|
vfs.GOROOT = *goroot
|
||||||
|
|
||||||
var fsGate chan bool
|
var fsGate chan bool
|
||||||
fsGate = make(chan bool, 20)
|
fsGate = make(chan bool, 20)
|
||||||
|
|
||||||
|
@ -14,6 +14,14 @@ import (
|
|||||||
"runtime"
|
"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
|
// OS returns an implementation of FileSystem reading from the
|
||||||
// tree rooted at root. Recording a root is convenient everywhere
|
// tree rooted at root. Recording a root is convenient everywhere
|
||||||
// but necessary on Windows, because the slash-separated path
|
// but necessary on Windows, because the slash-separated path
|
||||||
@ -22,7 +30,7 @@ import (
|
|||||||
func OS(root string) FileSystem {
|
func OS(root string) FileSystem {
|
||||||
var t RootType
|
var t RootType
|
||||||
switch {
|
switch {
|
||||||
case root == runtime.GOROOT():
|
case root == GOROOT:
|
||||||
t = RootTypeGoRoot
|
t = RootTypeGoRoot
|
||||||
case isGoPath(root):
|
case isGoPath(root):
|
||||||
t = RootTypeGoPath
|
t = RootTypeGoPath
|
||||||
|
@ -25,7 +25,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -87,7 +86,7 @@ func (fs *zipFS) String() string {
|
|||||||
func (fs *zipFS) RootType(abspath string) vfs.RootType {
|
func (fs *zipFS) RootType(abspath string) vfs.RootType {
|
||||||
var t vfs.RootType
|
var t vfs.RootType
|
||||||
switch {
|
switch {
|
||||||
case abspath == runtime.GOROOT():
|
case abspath == vfs.GOROOT:
|
||||||
t = vfs.RootTypeGoRoot
|
t = vfs.RootTypeGoRoot
|
||||||
case isGoPath(abspath):
|
case isGoPath(abspath):
|
||||||
t = vfs.RootTypeGoPath
|
t = vfs.RootTypeGoPath
|
||||||
|
Loading…
x
Reference in New Issue
Block a user