LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2013 The Go Authors. All rights reserved. | 1 // Copyright 2013 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // +build ignore | 5 // +build ignore |
6 | 6 |
7 // The run program is invoked via "go run" from src/run.bash or | 7 // The run program is invoked via "go run" from src/run.bash or |
8 // src/run.bat conditionally builds and runs the cmd/api tool. | 8 // src/run.bat conditionally builds and runs the cmd/api tool. |
9 // | 9 // |
10 // TODO(bradfitz): the "conditional" condition is always true. | 10 // TODO(bradfitz): the "conditional" condition is always true. |
11 // We should only do this if the user has the hg codereview extension | 11 // We should only do this if the user has the hg codereview extension |
12 // enabled and verifies that the go.tools subrepo is checked out with | 12 // enabled and verifies that the go.tools subrepo is checked out with |
13 // a suitably recently version. In prep for the cmd/api rewrite. | 13 // a suitably recently version. In prep for the cmd/api rewrite. |
14 package main | 14 package main |
15 | 15 |
16 import ( | 16 import ( |
17 "fmt" | 17 "fmt" |
18 "log" | 18 "log" |
19 "net/http" | 19 "net/http" |
20 "os" | 20 "os" |
21 "os/exec" | 21 "os/exec" |
22 "os/user" | 22 "os/user" |
23 "path/filepath" | 23 "path/filepath" |
| 24 "runtime" |
24 "strings" | 25 "strings" |
25 ) | 26 ) |
26 | 27 |
27 // goToolsVersion is the hg revision of the go.tools subrepo we need | 28 // goToolsVersion is the hg revision of the go.tools subrepo we need |
28 // to build cmd/api. This only needs to be updated whenever a go/types | 29 // to build cmd/api. This only needs to be updated whenever a go/types |
29 // bug fix is needed by the cmd/api tool. | 30 // bug fix is needed by the cmd/api tool. |
30 const goToolsVersion = "6698ca2900e2" | 31 const goToolsVersion = "6698ca2900e2" |
31 | 32 |
32 var goroot string | 33 var goroot string |
33 | 34 |
(...skipping 12 matching lines...) Expand all Loading... |
46 gopath := prepGoPath() | 47 gopath := prepGoPath() |
47 | 48 |
48 cmd := exec.Command("go", "install", "--tags=api_tool", "cmd/api") | 49 cmd := exec.Command("go", "install", "--tags=api_tool", "cmd/api") |
49 cmd.Env = append(filterOut(os.Environ(), "GOARCH", "GOPATH"), "GOPATH="+
gopath) | 50 cmd.Env = append(filterOut(os.Environ(), "GOARCH", "GOPATH"), "GOPATH="+
gopath) |
50 out, err := cmd.CombinedOutput() | 51 out, err := cmd.CombinedOutput() |
51 if err != nil { | 52 if err != nil { |
52 log.Fatalf("Error installing cmd/api: %v\n%s", err, out) | 53 log.Fatalf("Error installing cmd/api: %v\n%s", err, out) |
53 } | 54 } |
54 | 55 |
55 out, err = exec.Command("go", "tool", "api", | 56 out, err = exec.Command("go", "tool", "api", |
56 » » "-c", file("go1", "go1.1", "go1.2", "go1.3"), | 57 » » "-c", file("go1", "go1.1", "go1.2", "go1.3", "go1.4"), |
57 "-next", file("next"), | 58 "-next", file("next"), |
58 "-except", file("except")).CombinedOutput() | 59 "-except", file("except")).CombinedOutput() |
59 if err != nil { | 60 if err != nil { |
60 log.Fatalf("Error running API checker: %v\n%s", err, out) | 61 log.Fatalf("Error running API checker: %v\n%s", err, out) |
61 } | 62 } |
62 fmt.Print(string(out)) | 63 fmt.Print(string(out)) |
63 } | 64 } |
64 | 65 |
65 // filterOut returns a copy of the src environment without environment | 66 // filterOut returns a copy of the src environment without environment |
66 // variables from remove. | 67 // variables from remove. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 if err == nil { | 99 if err == nil { |
99 username = u.Username | 100 username = u.Username |
100 } else { | 101 } else { |
101 username = os.Getenv("USER") | 102 username = os.Getenv("USER") |
102 if username == "" { | 103 if username == "" { |
103 username = "nobody" | 104 username = "nobody" |
104 } | 105 } |
105 } | 106 } |
106 | 107 |
107 // The GOPATH we'll return | 108 // The GOPATH we'll return |
108 » gopath := filepath.Join(os.TempDir(), "gopath-api-"+cleanUsername(userna
me), goToolsVersion) | 109 » gopath := filepath.Join(os.TempDir(), "gopath-api-"+cleanUsername(userna
me)+"-"+cleanUsername(strings.Fields(runtime.Version())[0]), goToolsVersion) |
109 | 110 |
110 // cloneDir is where we run "hg clone". | 111 // cloneDir is where we run "hg clone". |
111 cloneDir := filepath.Join(gopath, "src", "code.google.com", "p") | 112 cloneDir := filepath.Join(gopath, "src", "code.google.com", "p") |
112 | 113 |
113 // The dir we clone into. We only atomically rename it to finalDir on | 114 // The dir we clone into. We only atomically rename it to finalDir on |
114 // clone success. | 115 // clone success. |
115 tmpDir := filepath.Join(cloneDir, tempBase) | 116 tmpDir := filepath.Join(cloneDir, tempBase) |
116 | 117 |
117 // finalDir is where the checkout will live once it's complete. | 118 // finalDir is where the checkout will live once it's complete. |
118 finalDir := filepath.Join(cloneDir, "go.tools") | 119 finalDir := filepath.Join(cloneDir, "go.tools") |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 176 |
176 cmd = exec.Command("hg", "status") | 177 cmd = exec.Command("hg", "status") |
177 cmd.Dir = dir | 178 cmd.Dir = dir |
178 out, err = cmd.Output() | 179 out, err = cmd.Output() |
179 if err != nil || len(out) > 0 { | 180 if err != nil || len(out) > 0 { |
180 return false | 181 return false |
181 } | 182 } |
182 | 183 |
183 return true | 184 return true |
184 } | 185 } |
LEFT | RIGHT |