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>
diff --git a/cmd/godoc/main.go b/cmd/godoc/main.go
index 5e5bc22..9e70469 100644
--- a/cmd/godoc/main.go
+++ b/cmd/godoc/main.go
@@ -356,6 +356,7 @@
return
}
+ build.Default.GOROOT = *goroot
if err := godoc.CommandLine(os.Stdout, fs, pres, flag.Args()); err != nil {
log.Print(err)
}
diff --git a/godoc/cmdline.go b/godoc/cmdline.go
index b531b4d..8686159 100644
--- a/godoc/cmdline.go
+++ b/godoc/cmdline.go
@@ -134,18 +134,25 @@
// 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
}