github.com/jgarto/itcv@v0.0.0-20180826224514-4eea09c1aa0d/_vendor/src/golang.org/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 fmt.Sprintf("go=%v/tools=%v", 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  	goPath := filepath.Join(dir, "gopath")
    40  	install := exec.Command(goBin, "install", "golang.org/x/tools/cmd/godoc")
    41  	install.Env = []string{
    42  		"GOROOT=" + goDir,
    43  		"GOPATH=" + goPath,
    44  		"GOROOT_BOOTSTRAP=" + os.Getenv("GOROOT_BOOTSTRAP"),
    45  	}
    46  	if err := runErr(install); err != nil {
    47  		return nil, err
    48  	}
    49  
    50  	godocBin := filepath.Join(goPath, "bin/godoc")
    51  	godoc := exec.Command(godocBin, "-http="+hostport, "-index", "-index_interval=-1s")
    52  	godoc.Env = []string{"GOROOT=" + goDir}
    53  	// TODO(adg): log this somewhere useful
    54  	godoc.Stdout = os.Stdout
    55  	godoc.Stderr = os.Stderr
    56  	if err := godoc.Start(); err != nil {
    57  		return nil, err
    58  	}
    59  	return godoc, nil
    60  }
    61  
    62  var indexingMsg = []byte("Indexing in progress: result may be inaccurate")
    63  
    64  func (b godocBuilder) HealthCheck(hostport string) error {
    65  	body, err := getOK(fmt.Sprintf("http://%v/search?q=FALLTHROUGH", hostport))
    66  	if err != nil {
    67  		return err
    68  	}
    69  	if bytes.Contains(body, indexingMsg) {
    70  		return errors.New("still indexing")
    71  	}
    72  	return nil
    73  }