Commit 47e5266a authored by Dave Cheney's avatar Dave Cheney

misc/dashboard/builder: set GOPATH before building subrepos

This proposal updates the dashboard builder to avoid relying on the (soon to be removed) support for using go get to download to $GOROOT. The result is

WORKSPACE=$(the value of the -buildRoot flag / $BUILDER_NAME + hg revision)
GOROOT=$WORKSPACE/go
GOPATH=$WORKSPACE

Required for CL 6941058.

R=minux.ma, adg
CC=golang-dev
https://golang.org/cl/7034049
parent f36a53cd
...@@ -281,7 +281,9 @@ func (b *Builder) buildHash(hash string) error { ...@@ -281,7 +281,9 @@ func (b *Builder) buildHash(hash string) error {
} }
// build Go sub-repositories // build Go sub-repositories
b.buildSubrepos(filepath.Join(workpath, "go"), hash) goRoot := filepath.Join(workpath, "go")
goPath := workpath
b.buildSubrepos(goRoot, goPath, hash)
return nil return nil
} }
...@@ -307,7 +309,7 @@ func (b *Builder) failBuild() bool { ...@@ -307,7 +309,7 @@ func (b *Builder) failBuild() bool {
return true return true
} }
func (b *Builder) buildSubrepos(goRoot, goHash string) { func (b *Builder) buildSubrepos(goRoot, goPath, goHash string) {
for _, pkg := range dashboardPackages("subrepo") { for _, pkg := range dashboardPackages("subrepo") {
// get the latest todo for this package // get the latest todo for this package
hash, err := b.todo("build-package", pkg, goHash) hash, err := b.todo("build-package", pkg, goHash)
...@@ -323,7 +325,7 @@ func (b *Builder) buildSubrepos(goRoot, goHash string) { ...@@ -323,7 +325,7 @@ func (b *Builder) buildSubrepos(goRoot, goHash string) {
if *verbose { if *verbose {
log.Printf("buildSubrepos %s: building %q", pkg, hash) log.Printf("buildSubrepos %s: building %q", pkg, hash)
} }
buildLog, err := b.buildSubrepo(goRoot, pkg, hash) buildLog, err := b.buildSubrepo(goRoot, goPath, pkg, hash)
if err != nil { if err != nil {
if buildLog == "" { if buildLog == "" {
buildLog = err.Error() buildLog = err.Error()
...@@ -341,43 +343,37 @@ func (b *Builder) buildSubrepos(goRoot, goHash string) { ...@@ -341,43 +343,37 @@ func (b *Builder) buildSubrepos(goRoot, goHash string) {
// buildSubrepo fetches the given package, updates it to the specified hash, // buildSubrepo fetches the given package, updates it to the specified hash,
// and runs 'go test -short pkg/...'. It returns the build log and any error. // and runs 'go test -short pkg/...'. It returns the build log and any error.
func (b *Builder) buildSubrepo(goRoot, pkg, hash string) (string, error) { func (b *Builder) buildSubrepo(goRoot, goPath, pkg, hash string) (string, error) {
goBin := filepath.Join(goRoot, "bin") goTool := filepath.Join(goRoot, "bin", "go")
goTool := filepath.Join(goBin, "go") env := append(b.envv(), "GOROOT="+goRoot, "GOPATH="+goPath)
env := append(b.envv(), "GOROOT="+goRoot)
// add goBin to PATH // add $GOROOT/bin and $GOPATH/bin to PATH
for i, e := range env { for i, e := range env {
const p = "PATH=" const p = "PATH="
if !strings.HasPrefix(e, p) { if !strings.HasPrefix(e, p) {
continue continue
} }
env[i] = p + goBin + string(os.PathListSeparator) + e[len(p):] sep := string(os.PathListSeparator)
env[i] = p + filepath.Join(goRoot, "bin") + sep + filepath.Join(goPath, "bin") + sep + e[len(p):]
} }
// fetch package and dependencies // fetch package and dependencies
log, status, err := runLog(*cmdTimeout, env, "", goRoot, goTool, "get", "-d", pkg) log, status, err := runLog(*cmdTimeout, env, "", goPath, goTool, "get", "-d", pkg+"/...")
if err == nil && status != 0 { if err == nil && status != 0 {
err = fmt.Errorf("go exited with status %d", status) err = fmt.Errorf("go exited with status %d", status)
} }
if err != nil { if err != nil {
// 'go get -d' will fail for a subrepo because its top-level
// directory does not contain a go package. No matter, just
// check whether an hg directory exists and proceed.
hgDir := filepath.Join(goRoot, "src/pkg", pkg, ".hg")
if fi, e := os.Stat(hgDir); e != nil || !fi.IsDir() {
return log, err return log, err
} }
}
// hg update to the specified hash // hg update to the specified hash
pkgPath := filepath.Join(goRoot, "src/pkg", pkg) pkgPath := filepath.Join(goPath, "src", pkg)
if err := run(*cmdTimeout, nil, pkgPath, hgCmd("update", hash)...); err != nil { if err := run(*cmdTimeout, nil, pkgPath, hgCmd("update", hash)...); err != nil {
return "", err return "", err
} }
// test the package // test the package
log, status, err = runLog(*buildTimeout, env, "", goRoot, goTool, "test", "-short", pkg+"/...") log, status, err = runLog(*buildTimeout, env, "", goPath, goTool, "test", "-short", pkg+"/...")
if err == nil && status != 0 { if err == nil && status != 0 {
err = fmt.Errorf("go exited with status %d", status) err = fmt.Errorf("go exited with status %d", status)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment