Commit 947ea6f7 authored by Alex Brainman's avatar Alex Brainman

gobuilder: fix windows builder

Do not rewrite commands if they have .bash extnsion.
Use path/filepath to manipulate file paths everywhere.
Use all.bat on windows, not all.bash.
Use HOMEDRIVE/HOMEPATH to find .gobuildkey on windows.

R=rsc
CC=golang-dev
https://golang.org/cl/5630062
parent 1c1ecd74
...@@ -10,7 +10,6 @@ import ( ...@@ -10,7 +10,6 @@ import (
"log" "log"
"os" "os"
"os/exec" "os/exec"
"strings"
) )
// run is a simple wrapper for exec.Run/Close // run is a simple wrapper for exec.Run/Close
...@@ -18,7 +17,6 @@ func run(envv []string, dir string, argv ...string) error { ...@@ -18,7 +17,6 @@ func run(envv []string, dir string, argv ...string) error {
if *verbose { if *verbose {
log.Println("run", argv) log.Println("run", argv)
} }
argv = useBash(argv)
cmd := exec.Command(argv[0], argv[1:]...) cmd := exec.Command(argv[0], argv[1:]...)
cmd.Dir = dir cmd.Dir = dir
cmd.Env = envv cmd.Env = envv
...@@ -35,7 +33,6 @@ func runLog(envv []string, logfile, dir string, argv ...string) (string, int, er ...@@ -35,7 +33,6 @@ func runLog(envv []string, logfile, dir string, argv ...string) (string, int, er
if *verbose { if *verbose {
log.Println("runLog", argv) log.Println("runLog", argv)
} }
argv = useBash(argv)
b := new(bytes.Buffer) b := new(bytes.Buffer)
var w io.Writer = b var w io.Writer = b
...@@ -62,13 +59,3 @@ func runLog(envv []string, logfile, dir string, argv ...string) (string, int, er ...@@ -62,13 +59,3 @@ func runLog(envv []string, logfile, dir string, argv ...string) (string, int, er
} }
return b.String(), 0, err return b.String(), 0, err
} }
// useBash prefixes a list of args with 'bash' if the first argument
// is a bash script.
func useBash(argv []string) []string {
// TODO(brainman): choose a more reliable heuristic here.
if strings.HasSuffix(argv[0], ".bash") {
argv = append([]string{"bash"}, argv...)
}
return argv
}
...@@ -12,7 +12,6 @@ import ( ...@@ -12,7 +12,6 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"path"
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime" "runtime"
...@@ -49,12 +48,12 @@ type Builder struct { ...@@ -49,12 +48,12 @@ type Builder struct {
} }
var ( var (
buildroot = flag.String("buildroot", path.Join(os.TempDir(), "gobuilder"), "Directory under which to build") buildroot = flag.String("buildroot", filepath.Join(os.TempDir(), "gobuilder"), "Directory under which to build")
commitFlag = flag.Bool("commit", false, "upload information about new commits") commitFlag = flag.Bool("commit", false, "upload information about new commits")
dashboard = flag.String("dashboard", "build.golang.org", "Go Dashboard Host") dashboard = flag.String("dashboard", "build.golang.org", "Go Dashboard Host")
buildRelease = flag.Bool("release", false, "Build and upload binary release archives") buildRelease = flag.Bool("release", false, "Build and upload binary release archives")
buildRevision = flag.String("rev", "", "Build specified revision and exit") buildRevision = flag.String("rev", "", "Build specified revision and exit")
buildCmd = flag.String("cmd", "./all.bash", "Build command (specify absolute or relative to go/src/)") buildCmd = flag.String("cmd", filepath.Join(".", allCmd), "Build command (specify relative to go/src/)")
external = flag.Bool("external", false, "Build external packages") external = flag.Bool("external", false, "Build external packages")
parallel = flag.Bool("parallel", false, "Build multiple targets in parallel") parallel = flag.Bool("parallel", false, "Build multiple targets in parallel")
verbose = flag.Bool("v", false, "verbose") verbose = flag.Bool("v", false, "verbose")
...@@ -64,6 +63,9 @@ var ( ...@@ -64,6 +63,9 @@ var (
goroot string goroot string
binaryTagRe = regexp.MustCompile(`^(release\.r|weekly\.)[0-9\-.]+`) binaryTagRe = regexp.MustCompile(`^(release\.r|weekly\.)[0-9\-.]+`)
releaseRe = regexp.MustCompile(`^release\.r[0-9\-.]+`) releaseRe = regexp.MustCompile(`^release\.r[0-9\-.]+`)
allCmd = "all" + suffix
cleanCmd = "clean" + suffix
suffix = defaultSuffix()
) )
func main() { func main() {
...@@ -76,7 +78,7 @@ func main() { ...@@ -76,7 +78,7 @@ func main() {
if len(flag.Args()) == 0 && !*commitFlag { if len(flag.Args()) == 0 && !*commitFlag {
flag.Usage() flag.Usage()
} }
goroot = path.Join(*buildroot, "goroot") goroot = filepath.Join(*buildroot, "goroot")
builders := make([]*Builder, len(flag.Args())) builders := make([]*Builder, len(flag.Args()))
for i, builder := range flag.Args() { for i, builder := range flag.Args() {
b, err := NewBuilder(builder) b, err := NewBuilder(builder)
...@@ -171,7 +173,13 @@ func NewBuilder(builder string) (*Builder, error) { ...@@ -171,7 +173,13 @@ func NewBuilder(builder string) (*Builder, error) {
} }
// read keys from keyfile // read keys from keyfile
fn := path.Join(os.Getenv("HOME"), ".gobuildkey") fn := ""
if runtime.GOOS == "windows" {
fn = os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
} else {
fn = os.Getenv("HOME")
}
fn = filepath.Join(fn, ".gobuildkey")
if s := fn + "-" + b.name; isFile(s) { // builder-specific file if s := fn + "-" + b.name; isFile(s) { // builder-specific file
fn = s fn = s
} }
...@@ -257,7 +265,7 @@ func (b *Builder) buildHash(hash string) error { ...@@ -257,7 +265,7 @@ func (b *Builder) buildHash(hash string) error {
log.Println(b.name, "building", hash) log.Println(b.name, "building", hash)
// create place in which to do work // create place in which to do work
workpath := path.Join(*buildroot, b.name+"-"+hash[:12]) workpath := filepath.Join(*buildroot, b.name+"-"+hash[:12])
if err := os.Mkdir(workpath, mkdirPerm); err != nil { if err := os.Mkdir(workpath, mkdirPerm); err != nil {
return err return err
} }
...@@ -269,16 +277,20 @@ func (b *Builder) buildHash(hash string) error { ...@@ -269,16 +277,20 @@ func (b *Builder) buildHash(hash string) error {
} }
// update to specified revision // update to specified revision
if err := run(nil, path.Join(workpath, "go"), "hg", "update", hash); err != nil { if err := run(nil, filepath.Join(workpath, "go"), "hg", "update", hash); err != nil {
return err return err
} }
srcDir := path.Join(workpath, "go", "src") srcDir := filepath.Join(workpath, "go", "src")
// build // build
logfile := path.Join(workpath, "build.log") logfile := filepath.Join(workpath, "build.log")
cmd := *buildCmd
if !filepath.IsAbs(cmd) {
cmd = filepath.Join(srcDir, cmd)
}
startTime := time.Now() startTime := time.Now()
buildLog, status, err := runLog(b.envv(), logfile, srcDir, *buildCmd) buildLog, status, err := runLog(b.envv(), logfile, srcDir, cmd)
runTime := time.Now().Sub(startTime) runTime := time.Now().Sub(startTime)
if err != nil { if err != nil {
return fmt.Errorf("%s: %s", *buildCmd, err) return fmt.Errorf("%s: %s", *buildCmd, err)
...@@ -314,15 +326,16 @@ func (b *Builder) buildHash(hash string) error { ...@@ -314,15 +326,16 @@ func (b *Builder) buildHash(hash string) error {
releaseHash, release, err := firstTag(binaryTagRe) releaseHash, release, err := firstTag(binaryTagRe)
if hash == releaseHash { if hash == releaseHash {
// clean out build state // clean out build state
if err := run(b.envv(), srcDir, "./clean.bash", "--nopkg"); err != nil { cmd := filepath.Join(srcDir, cleanCmd)
return fmt.Errorf("clean.bash: %s", err) if err := run(b.envv(), srcDir, cmd, "--nopkg"); err != nil {
return fmt.Errorf("%s: %s", cleanCmd, err)
} }
// upload binary release // upload binary release
fn := fmt.Sprintf("go.%s.%s-%s.tar.gz", release, b.goos, b.goarch) fn := fmt.Sprintf("go.%s.%s-%s.tar.gz", release, b.goos, b.goarch)
if err := run(nil, workpath, "tar", "czf", fn, "go"); err != nil { if err := run(nil, workpath, "tar", "czf", fn, "go"); err != nil {
return fmt.Errorf("tar: %s", err) return fmt.Errorf("tar: %s", err)
} }
err := run(nil, workpath, path.Join(goroot, codePyScript), err := run(nil, workpath, filepath.Join(goroot, codePyScript),
"-s", release, "-s", release,
"-p", codeProject, "-p", codeProject,
"-u", b.codeUsername, "-u", b.codeUsername,
...@@ -556,7 +569,7 @@ func commitPoll(key, pkg string) { ...@@ -556,7 +569,7 @@ func commitPoll(key, pkg string) {
pkgRoot := goroot pkgRoot := goroot
if pkg != "" { if pkg != "" {
pkgRoot = path.Join(*buildroot, pkg) pkgRoot = filepath.Join(*buildroot, pkg)
if !hgRepoExists(pkgRoot) { if !hgRepoExists(pkgRoot) {
if err := hgClone(repoURL(pkg), pkgRoot); err != nil { if err := hgClone(repoURL(pkg), pkgRoot); err != nil {
log.Printf("%s: hg clone failed: %v", pkg, err) log.Printf("%s: hg clone failed: %v", pkg, err)
...@@ -719,3 +732,12 @@ func repoURL(importPath string) string { ...@@ -719,3 +732,12 @@ func repoURL(importPath string) string {
} }
return "https://code.google.com/p/" + m[1] return "https://code.google.com/p/" + m[1]
} }
// defaultSuffix returns file extension used for command files in
// current os environment.
func defaultSuffix() string {
if runtime.GOOS == "windows" {
return ".bat"
}
return ".bash"
}
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