You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.9 KiB

  1. // Copyright 2015 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package main
  5. import (
  6. "bytes"
  7. "errors"
  8. "fmt"
  9. "os"
  10. "os/exec"
  11. "path/filepath"
  12. )
  13. type godocBuilder struct {
  14. }
  15. func (b godocBuilder) Signature(heads map[string]string) string {
  16. return fmt.Sprintf("go=%v/tools=%v", heads["go"], heads["tools"])
  17. }
  18. func (b godocBuilder) Init(dir, hostport string, heads map[string]string) (*exec.Cmd, error) {
  19. goDir := filepath.Join(dir, "go")
  20. toolsDir := filepath.Join(dir, "gopath/src/golang.org/x/tools")
  21. if err := checkout(repoURL+"go", heads["go"], goDir); err != nil {
  22. return nil, err
  23. }
  24. if err := checkout(repoURL+"tools", heads["tools"], toolsDir); err != nil {
  25. return nil, err
  26. }
  27. make := exec.Command(filepath.Join(goDir, "src/make.bash"))
  28. make.Dir = filepath.Join(goDir, "src")
  29. if err := runErr(make); err != nil {
  30. return nil, err
  31. }
  32. goBin := filepath.Join(goDir, "bin/go")
  33. goPath := filepath.Join(dir, "gopath")
  34. install := exec.Command(goBin, "install", "golang.org/x/tools/cmd/godoc")
  35. install.Env = []string{
  36. "GOROOT=" + goDir,
  37. "GOPATH=" + goPath,
  38. "GOROOT_BOOTSTRAP=" + os.Getenv("GOROOT_BOOTSTRAP"),
  39. }
  40. if err := runErr(install); err != nil {
  41. return nil, err
  42. }
  43. godocBin := filepath.Join(goPath, "bin/godoc")
  44. godoc := exec.Command(godocBin, "-http="+hostport, "-index", "-index_interval=-1s")
  45. godoc.Env = []string{"GOROOT=" + goDir}
  46. // TODO(adg): log this somewhere useful
  47. godoc.Stdout = os.Stdout
  48. godoc.Stderr = os.Stderr
  49. if err := godoc.Start(); err != nil {
  50. return nil, err
  51. }
  52. return godoc, nil
  53. }
  54. var indexingMsg = []byte("Indexing in progress: result may be inaccurate")
  55. func (b godocBuilder) HealthCheck(hostport string) error {
  56. body, err := getOK(fmt.Sprintf("http://%v/search?q=FALLTHROUGH", hostport))
  57. if err != nil {
  58. return err
  59. }
  60. if bytes.Contains(body, indexingMsg) {
  61. return errors.New("still indexing")
  62. }
  63. return nil
  64. }