-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.go
84 lines (73 loc) · 1.31 KB
/
make.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// +build ignore
// This program builds dereddit
package main
import (
"bytes"
"log"
"os"
"os/exec"
)
const (
help = `
Valid targets:
all (default)
deps
clean
help
`
)
var (
deps = []string{"github.com/peterbourgon/diskv", "code.google.com/p/go.net/html"}
)
func fetchDeps(update bool) {
for _, d := range deps {
var output bytes.Buffer
var cmd *exec.Cmd
if update {
cmd = exec.Command("go", "get", "-u", d)
} else {
cmd = exec.Command("go", "get", d)
}
cmd.Stdout = &output
cmd.Stderr = &output
if err := cmd.Run(); err != nil {
log.Fatalf("Error fetching dependencies: %v\n%s", err, output.String())
}
}
}
func build() {
var output bytes.Buffer
cmd := exec.Command("go", "build")
cmd.Stdout = &output
cmd.Stderr = &output
if err := cmd.Run(); err != nil {
log.Fatalf("Error building binary: %v\n%s", err, output.String())
}
}
func clean() {
err := os.Remove("dereddit")
if err != nil {
log.Fatalf("Error cleaning: %v\n", err)
}
}
func main() {
if len(os.Args) == 1 {
os.Args = append(os.Args, "all")
}
switch os.Args[1] {
case "all":
fetchDeps(false)
build()
case "deps":
fetchDeps(false)
case "clean":
clean()
case "update":
fetchDeps(true)
case "help":
log.Println(help)
default:
log.Fatalf("Unrecognized target: %s\n", os.Args[1])
}
os.Exit(0)
}