forked from cortesi/devd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·101 lines (83 loc) · 2.37 KB
/
build
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python2
import contextlib
import fnmatch
import glob
import os
import shutil
import subprocess
DSTDIR = "./tmp"
ARCHS = [
("darwin", "amd64", "osx64", "tgz"),
("windows", "amd64", "windows64", "zip"),
("linux", "amd64", "linux64", "tgz"),
("linux", "arm", "linuxARM", "tgz"),
("netbsd", "amd64", "netbsd64", "tgz"),
("netbsd", "arm", "netbsdARM", "tgz"),
("openbsd", "amd64", "openbsd64", "tgz"),
]
def cleanrice(directory):
for root, dirs, files in os.walk(directory):
for basename in files:
if basename.endswith("rice-box.go"):
filename = os.path.join(root, basename)
print "\t", filename
os.unlink(filename)
@contextlib.contextmanager
def chdir(newdir):
curdir = os.getcwd()
try:
os.chdir(newdir)
yield
finally:
os.chdir(curdir)
def version():
print "Installing locally"
subprocess.call(["go", "install", "./cmd/devd"])
p = subprocess.Popen(["devd", "--version"], stderr=subprocess.PIPE)
return p.communicate()[1].strip()
def build(vers, goos, goarch, name, archive):
dst = os.path.join(DSTDIR, "devd-%s-%s"%(vers, name))
print "building to ", dst
for f in glob.glob(dst + "*"):
if os.path.isdir(f):
shutil.rmtree(f)
else:
os.unlink(f)
os.makedirs(dst)
env = os.environ.copy()
env["GOOS"] = goos
env["GOARCH"] = goarch
subprocess.check_call(
[
"go", "build",
"-o", os.path.join(dst, "devd"),
"./cmd/devd"
],
env = env
)
if archive == "tgz":
print "\tmaking .tgz"
subprocess.Popen(
["tar", "-czvf", dst + ".tgz", dst],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
).communicate()
elif archive == "zip":
print "\tmaking .zip"
subprocess.Popen(
["zip", "-r", dst + ".zip", dst],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
).communicate()
def main():
print "Making static inclusions..."
subprocess.call(["rice", "embed-go"])
with chdir("livereload"):
subprocess.call(["rice", "embed-go"])
v = version()
print "Version is: ", v
for i in ARCHS:
build(v, *i)
print "Cleaning static inclusions..."
cleanrice(".")
main()