Commit 6ea4cfb3 authored by Marvin Stenger's avatar Marvin Stenger Committed by Ian Lance Taylor

cmd/dist: remove trivial variables + functions

This belongs to a series of clean-up changes (see below) for cmd/dist.
This is change (5).

These changes include:
(1)  apply minor fixes
(2)  restore behavior of branchtag
(3)  unleash bootstrap optimization for windows
(4)  use standard generated code header
(5)  remove trivial variables + functions
(6)  move functions for the better
(7)  simplify code segments
(8)  use bytes.Buffer for code generation
(9)  rename variables + functions
(10) remove doc.go

Change-Id: I0efd1271b6a70bb9248d82f8a4d869556f4a557e
Reviewed-on: https://go-review.googlesource.com/61011
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent e86c0676
...@@ -36,7 +36,6 @@ var ( ...@@ -36,7 +36,6 @@ var (
tooldir string tooldir string
oldgoos string oldgoos string
oldgoarch string oldgoarch string
slash string
exe string exe string
defaultcc string defaultcc string
defaultcflags string defaultcflags string
...@@ -93,23 +92,20 @@ func find(p string, l []string) int { ...@@ -93,23 +92,20 @@ func find(p string, l []string) int {
// xinit handles initialization of the various global state, like goroot and goarch. // xinit handles initialization of the various global state, like goroot and goarch.
func xinit() { func xinit() {
goroot = os.Getenv("GOROOT") b := os.Getenv("GOROOT")
if slash == "/" && len(goroot) > 1 || slash == `\` && len(goroot) > 3 { if b == "" {
// if not "/" or "c:\", then strip trailing path separator
goroot = strings.TrimSuffix(goroot, slash)
}
if goroot == "" {
fatal("$GOROOT must be set") fatal("$GOROOT must be set")
} }
goroot = filepath.Clean(b)
goroot_final = os.Getenv("GOROOT_FINAL") goroot_final = os.Getenv("GOROOT_FINAL")
if goroot_final == "" { if goroot_final == "" {
goroot_final = goroot goroot_final = goroot
} }
b := os.Getenv("GOBIN") b = os.Getenv("GOBIN")
if b == "" { if b == "" {
b = goroot + slash + "bin" b = pathf("%s/bin", goroot)
} }
gobin = b gobin = b
...@@ -253,7 +249,7 @@ func chomp(s string) string { ...@@ -253,7 +249,7 @@ func chomp(s string) string {
func branchtag(branch string) (tag string, precise bool) { func branchtag(branch string) (tag string, precise bool) {
b := run(goroot, CheckExit, "git", "log", "--decorate=full", "--format=format:%d", "master.."+branch) b := run(goroot, CheckExit, "git", "log", "--decorate=full", "--format=format:%d", "master.."+branch)
tag = 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 // 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) // (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/. // We need to find an element starting with refs/tags/.
...@@ -441,7 +437,7 @@ func setup() { ...@@ -441,7 +437,7 @@ func setup() {
// If $GOBIN is set and has a Go compiler, it must be cleaned. // If $GOBIN is set and has a Go compiler, it must be cleaned.
for _, char := range "56789" { 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 { for _, old := range oldtool {
xremove(pathf("%s/%s", gobin, old)) xremove(pathf("%s/%s", gobin, old))
} }
...@@ -595,7 +591,7 @@ func install(dir string) { ...@@ -595,7 +591,7 @@ func install(dir string) {
// Convert to absolute paths. // Convert to absolute paths.
for i, p := range files { for i, p := range files {
if !isabs(p) { if !filepath.IsAbs(p) {
files[i] = pathf("%s/%s", path, p) files[i] = pathf("%s/%s", path, p)
} }
} }
...@@ -815,7 +811,7 @@ func shouldbuild(file, dir string) bool { ...@@ -815,7 +811,7 @@ func shouldbuild(file, dir string) bool {
} }
// Check file contents for // +build lines. // Check file contents for // +build lines.
for _, p := range splitlines(readfile(file)) { for _, p := range strings.Split(readfile(file), "\n") {
p = strings.TrimSpace(p) p = strings.TrimSpace(p)
if p == "" { if p == "" {
continue continue
...@@ -837,7 +833,7 @@ func shouldbuild(file, dir string) bool { ...@@ -837,7 +833,7 @@ func shouldbuild(file, dir string) bool {
if !strings.Contains(p, "+build") { if !strings.Contains(p, "+build") {
continue continue
} }
fields := splitfields(p[2:]) fields := strings.Fields(p[2:])
if len(fields) < 1 || fields[0] != "+build" { if len(fields) < 1 || fields[0] != "+build" {
continue continue
} }
......
...@@ -51,18 +51,6 @@ func uniq(list []string) []string { ...@@ -51,18 +51,6 @@ func uniq(list []string) []string {
return keep 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 ( const (
CheckExit = 1 << iota CheckExit = 1 << iota
ShowOutput ShowOutput
...@@ -231,11 +219,6 @@ func mtime(p string) time.Time { ...@@ -231,11 +219,6 @@ func mtime(p string) time.Time {
return fi.ModTime() 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. // readfile returns the content of the named file.
func readfile(file string) string { func readfile(file string) string {
data, err := ioutil.ReadFile(file) data, err := ioutil.ReadFile(file)
...@@ -401,8 +384,6 @@ func main() { ...@@ -401,8 +384,6 @@ func main() {
os.Exit(0) os.Exit(0)
} }
slash = string(filepath.Separator)
gohostos = runtime.GOOS gohostos = runtime.GOOS
switch gohostos { switch gohostos {
case "darwin": case "darwin":
......
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