tooldir string
oldgoos string
oldgoarch string
- slash string
exe string
defaultcc string
defaultcflags string
// xinit handles initialization of the various global state, like goroot and goarch.
func xinit() {
- goroot = os.Getenv("GOROOT")
- if slash == "/" && len(goroot) > 1 || slash == `\` && len(goroot) > 3 {
- // if not "/" or "c:\", then strip trailing path separator
- goroot = strings.TrimSuffix(goroot, slash)
- }
- if goroot == "" {
+ b := os.Getenv("GOROOT")
+ if b == "" {
fatal("$GOROOT must be set")
}
+ goroot = filepath.Clean(b)
goroot_final = os.Getenv("GOROOT_FINAL")
if goroot_final == "" {
goroot_final = goroot
}
- b := os.Getenv("GOBIN")
+ b = os.Getenv("GOBIN")
if b == "" {
- b = goroot + slash + "bin"
+ b = pathf("%s/bin", goroot)
}
gobin = b
func branchtag(branch string) (tag string, precise bool) {
b := run(goroot, CheckExit, "git", "log", "--decorate=full", "--format=format:%d", "master.."+branch)
tag = branch
- for row, line := range splitlines(b) {
+ for row, line := range strings.Split(b, "\n") {
// Each line is either blank, or looks like
// (tag: refs/tags/go1.4rc2, refs/remotes/origin/release-branch.go1.4, refs/heads/release-branch.go1.4)
// We need to find an element starting with refs/tags/.
// If $GOBIN is set and has a Go compiler, it must be cleaned.
for _, char := range "56789" {
- if isfile(pathf("%s%s%c%s", gobin, slash, char, "g")) {
+ if isfile(pathf("%s/%c%s", gobin, char, "g")) {
for _, old := range oldtool {
xremove(pathf("%s/%s", gobin, old))
}
// Convert to absolute paths.
for i, p := range files {
- if !isabs(p) {
+ if !filepath.IsAbs(p) {
files[i] = pathf("%s/%s", path, p)
}
}
}
// Check file contents for // +build lines.
- for _, p := range splitlines(readfile(file)) {
+ for _, p := range strings.Split(readfile(file), "\n") {
p = strings.TrimSpace(p)
if p == "" {
continue
if !strings.Contains(p, "+build") {
continue
}
- fields := splitfields(p[2:])
+ fields := strings.Fields(p[2:])
if len(fields) < 1 || fields[0] != "+build" {
continue
}
return keep
}
-// splitlines returns a slice with the result of splitting
-// the input p after each \n.
-func splitlines(p string) []string {
- return strings.SplitAfter(p, "\n")
-}
-
-// splitfields replaces the vector v with the result of splitting
-// the input p into non-empty fields containing no spaces.
-func splitfields(p string) []string {
- return strings.Fields(p)
-}
-
const (
CheckExit = 1 << iota
ShowOutput
return fi.ModTime()
}
-// isabs reports whether p is an absolute path.
-func isabs(p string) bool {
- return filepath.IsAbs(p)
-}
-
// readfile returns the content of the named file.
func readfile(file string) string {
data, err := ioutil.ReadFile(file)
os.Exit(0)
}
- slash = string(filepath.Separator)
-
gohostos = runtime.GOOS
switch gohostos {
case "darwin":