mirror of
https://github.com/golang/go
synced 2024-11-21 18:54:43 -07:00
gobuilder: fixes for windows
R=r, devon.odell, iant, rsc, adg CC=bradfitz, golang-dev, jdpoirier https://golang.org/cl/4536053
This commit is contained in:
parent
a479bc8d02
commit
55dd63bb4e
@ -10,6 +10,7 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -18,6 +19,10 @@ func run(envv []string, dir string, argv ...string) os.Error {
|
||||
if *verbose {
|
||||
log.Println("run", argv)
|
||||
}
|
||||
if runtime.GOOS == "windows" && isBash(argv[0]) {
|
||||
// shell script cannot be executed directly on Windows.
|
||||
argv = append([]string{"bash", "-c"}, argv...)
|
||||
}
|
||||
bin, err := lookPath(argv[0])
|
||||
if err != nil {
|
||||
return err
|
||||
@ -36,6 +41,10 @@ func runLog(envv []string, logfile, dir string, argv ...string) (output string,
|
||||
if *verbose {
|
||||
log.Println("runLog", argv)
|
||||
}
|
||||
if runtime.GOOS == "windows" && isBash(argv[0]) {
|
||||
// shell script cannot be executed directly on Windows.
|
||||
argv = append([]string{"bash", "-c"}, argv...)
|
||||
}
|
||||
bin, err := lookPath(argv[0])
|
||||
if err != nil {
|
||||
return
|
||||
@ -74,3 +83,9 @@ func lookPath(cmd string) (string, os.Error) {
|
||||
}
|
||||
return exec.LookPath(cmd)
|
||||
}
|
||||
|
||||
// isBash determines if name refers to a shell script.
|
||||
func isBash(name string) bool {
|
||||
// TODO(brainman): perhaps it is too simple and needs better check.
|
||||
return strings.HasSuffix(name, ".bash")
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -347,6 +348,9 @@ func (b *Builder) buildHash(hash string) (err os.Error) {
|
||||
|
||||
// envv returns an environment for build/bench execution
|
||||
func (b *Builder) envv() []string {
|
||||
if runtime.GOOS == "windows" {
|
||||
return b.envvWindows()
|
||||
}
|
||||
e := []string{
|
||||
"GOOS=" + b.goos,
|
||||
"GOARCH=" + b.goarch,
|
||||
@ -358,6 +362,42 @@ func (b *Builder) envv() []string {
|
||||
return e
|
||||
}
|
||||
|
||||
// windows version of envv
|
||||
func (b *Builder) envvWindows() []string {
|
||||
start := map[string]string{
|
||||
"GOOS": b.goos,
|
||||
"GOARCH": b.goarch,
|
||||
"GOROOT_FINAL": "/c/go",
|
||||
}
|
||||
for _, name := range extraEnv {
|
||||
start[name] = os.Getenv(name)
|
||||
}
|
||||
skip := map[string]bool{
|
||||
"GOBIN": true,
|
||||
"GOROOT": true,
|
||||
"INCLUDE": true,
|
||||
"LIB": true,
|
||||
}
|
||||
var e []string
|
||||
for name, v := range start {
|
||||
e = append(e, name+"="+v)
|
||||
skip[name] = true
|
||||
}
|
||||
for _, kv := range os.Environ() {
|
||||
s := strings.Split(kv, "=", 2)
|
||||
name := strings.ToUpper(s[0])
|
||||
switch {
|
||||
case name == "":
|
||||
// variables, like "=C:=C:\", just copy them
|
||||
e = append(e, kv)
|
||||
case !skip[name]:
|
||||
e = append(e, kv)
|
||||
skip[name] = true
|
||||
}
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
func isDirectory(name string) bool {
|
||||
s, err := os.Stat(name)
|
||||
return err == nil && s.IsDirectory()
|
||||
|
Loading…
Reference in New Issue
Block a user