forked from xiaonanln/goworld
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.go
56 lines (45 loc) · 1.05 KB
/
build.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
package main
import (
"os"
"os/exec"
"path/filepath"
)
func build(sid ServerID) {
showMsg("building server %s ...", sid)
buildServer(sid)
buildDispatcher()
buildGate()
}
func buildServer(sid ServerID) {
serverPath := sid.Path()
showMsg("server directory is %s ...", serverPath)
if !isdir(serverPath) {
showMsgAndQuit("wrong server id: %s, using '\\' instead of '/'?", sid)
}
showMsg("go build %s ...", sid)
buildDirectory(serverPath)
}
func buildDispatcher() {
showMsg("go build dispatcher ...")
buildDirectory(filepath.Join(env.GoWorldRoot, "components", "dispatcher"))
}
func buildGate() {
showMsg("go build gate ...")
buildDirectory(filepath.Join(env.GoWorldRoot, "components", "gate"))
}
func buildDirectory(dir string) {
var err error
var curdir string
curdir, err = os.Getwd()
checkErrorOrQuit(err, "")
err = os.Chdir(dir)
checkErrorOrQuit(err, "")
defer os.Chdir(curdir)
cmd := exec.Command("go", "build", ".")
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
err = cmd.Run()
checkErrorOrQuit(err, "")
return
}