Skip to content

Commit

Permalink
cmd/pkgsite: fix setting gorepo flag
Browse files Browse the repository at this point in the history
The value of the gorepo flag variable was being used before flags were
parsed. Fix that.

Also fix a couple of other issues that came up in golang/go#68533:
First, don't print "searching GOPATH" when we're not searching GOPATH.
Second, print the stderr from the go command in the error when it fails
because it's the stderr that usually provides information about the
failure, not the stdout.

For golang/go#68533

Change-Id: Ic6321d6e071dd82415474f2a2c54146e9eabbef7
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/600917
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Michael Matloob <matloob@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
kokoro-CI: kokoro <noreply+kokoro@google.com>
  • Loading branch information
matloob authored and gopherbot committed Jul 24, 2024
1 parent 3166cf6 commit 557c002
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion cmd/internal/pkgsite/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func BuildServer(ctx context.Context, serverCfg ServerConfig) (*frontend.Server,
var err error
cfg.dirs, err = getModuleDirs(ctx, serverCfg.Paths)
if err != nil {
return nil, fmt.Errorf("searching GOPATH: %v", err)
return nil, fmt.Errorf("searching modules: %v", err)
}
}

Expand Down Expand Up @@ -332,6 +332,9 @@ func runGo(dir string, args ...string) ([]byte, error) {
cmd.Dir = dir
out, err := cmd.Output()
if err != nil {
if ee, ok := err.(*exec.ExitError); ok {
out = append(out, ee.Stderr...)
}
return nil, fmt.Errorf("running go with %q: %v: %s", args, err, out)
}
return out, nil
Expand Down
5 changes: 3 additions & 2 deletions cmd/pkgsite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ func main() {
flag.BoolVar(&serverCfg.UseListedMods, "list", true, "for each path, serve all modules in build list")
flag.BoolVar(&serverCfg.DevMode, "dev", false, "enable developer mode (reload templates on each page load, serve non-minified JS/CSS, etc.)")
flag.StringVar(&serverCfg.DevModeStaticDir, "static", "static", "path to folder containing static files served")
serverCfg.UseLocalStdlib = true
serverCfg.GoRepoPath = *goRepoPath

flag.Usage = func() {
out := flag.CommandLine.Output()
Expand All @@ -96,6 +94,9 @@ func main() {
flag.PrintDefaults()
}
flag.Parse()

serverCfg.UseLocalStdlib = true
serverCfg.GoRepoPath = *goRepoPath
serverCfg.Paths = collectPaths(flag.Args())

if serverCfg.UseCache || *useProxy {
Expand Down

0 comments on commit 557c002

Please sign in to comment.