godoc: set the GOROOT path properly in cmdline mode
- Setting the GOROOT build path to the value passed from the command line. - Clarified the return values to named parameters for extra clarity. - And while here, added some missed out error handling. Just logging the error to preserve original behavior. Fixes golang/go#13296 Change-Id: I91427eee790928a3cfb51ae207747e9a17bd5496 Reviewed-on: https://go-review.googlesource.com/110275 Run-TryBot: Andrew Bonventre <andybons@golang.org> Reviewed-by: Andrew Bonventre <andybons@golang.org>
This commit is contained in:
parent
5c8013c561
commit
a25dedfa53
|
@ -356,6 +356,7 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
build.Default.GOROOT = *goroot
|
||||
if err := godoc.CommandLine(os.Stdout, fs, pres, flag.Args()); err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
|
|
@ -134,18 +134,25 @@ func CommandLine(w io.Writer, fs vfs.NameSpace, pres *Presentation, args []strin
|
|||
// for this. That is, if we get passed a directory like the above, we map that
|
||||
// directory so that getPageInfo sees it as /target.
|
||||
// Returns the absolute and relative paths.
|
||||
func paths(fs vfs.NameSpace, pres *Presentation, path string) (string, string) {
|
||||
func paths(fs vfs.NameSpace, pres *Presentation, path string) (abspath, relpath string) {
|
||||
if filepath.IsAbs(path) {
|
||||
fs.Bind(target, vfs.OS(path), "/", vfs.BindReplace)
|
||||
return target, target
|
||||
}
|
||||
if build.IsLocalImport(path) {
|
||||
cwd, _ := os.Getwd() // ignore errors
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("error while getting working directory: %v", err)
|
||||
}
|
||||
path = filepath.Join(cwd, path)
|
||||
fs.Bind(target, vfs.OS(path), "/", vfs.BindReplace)
|
||||
return target, target
|
||||
}
|
||||
if bp, _ := build.Import(path, "", build.FindOnly); bp.Dir != "" && bp.ImportPath != "" {
|
||||
bp, err := build.Import(path, "", build.FindOnly)
|
||||
if err != nil {
|
||||
log.Printf("error while importing build package: %v", err)
|
||||
}
|
||||
if bp.Dir != "" && bp.ImportPath != "" {
|
||||
fs.Bind(target, vfs.OS(bp.Dir), "/", vfs.BindReplace)
|
||||
return target, bp.ImportPath
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue