github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/tools/cmd/tip/godoc.go (about) 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 5 package main 6 7 import ( 8 "bytes" 9 "errors" 10 "fmt" 11 "os" 12 "os/exec" 13 "path/filepath" 14 ) 15 16 type godocBuilder struct { 17 } 18 19 func (b godocBuilder) Signature(heads map[string]string) string { 20 return heads["go"] + "-" + heads["tools"] 21 } 22 23 func (b godocBuilder) Init(dir, hostport string, heads map[string]string) (*exec.Cmd, error) { 24 goDir := filepath.Join(dir, "go") 25 toolsDir := filepath.Join(dir, "gopath/src/golang.org/x/tools") 26 if err := checkout(repoURL+"go", heads["go"], goDir); err != nil { 27 return nil, err 28 } 29 if err := checkout(repoURL+"tools", heads["tools"], toolsDir); err != nil { 30 return nil, err 31 } 32 33 make := exec.Command(filepath.Join(goDir, "src/make.bash")) 34 make.Dir = filepath.Join(goDir, "src") 35 if err := runErr(make); err != nil { 36 return nil, err 37 } 38 goBin := filepath.Join(goDir, "bin/go") 39 install := exec.Command(goBin, "install", "golang.org/x/tools/cmd/godoc") 40 install.Env = []string{ 41 "GOROOT=" + goDir, 42 "GOPATH=" + filepath.Join(dir, "gopath"), 43 "GOROOT_BOOTSTRAP=" + os.Getenv("GOROOT_BOOTSTRAP"), 44 } 45 if err := runErr(install); err != nil { 46 return nil, err 47 } 48 49 godocBin := filepath.Join(goDir, "bin/godoc") 50 godoc := exec.Command(godocBin, "-http="+hostport, "-index", "-index_interval=-1s") 51 godoc.Env = []string{"GOROOT=" + goDir} 52 // TODO(adg): log this somewhere useful 53 godoc.Stdout = os.Stdout 54 godoc.Stderr = os.Stderr 55 if err := godoc.Start(); err != nil { 56 return nil, err 57 } 58 return godoc, nil 59 } 60 61 var indexingMsg = []byte("Indexing in progress: result may be inaccurate") 62 63 func (b godocBuilder) HealthCheck(hostport string) error { 64 body, err := getOK(fmt.Sprintf("http://%v/search?q=FALLTHROUGH", hostport)) 65 if err != nil { 66 return err 67 } 68 if bytes.Contains(body, indexingMsg) { 69 return errors.New("still indexing") 70 } 71 return nil 72 }