-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.py
51 lines (38 loc) · 1.28 KB
/
build.py
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
#!/usr/bin/env python
import os
import sys, subprocess
def run_cmd(cmd):
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout = p.communicate()[0].decode('utf-8').strip()
return stdout
# Get last tag.
def get_version():
return run_cmd('git describe --abbrev=0 --tags')
# Assemble build command.
def build_cmd():
build_flag = []
version = get_version()
if version != "":
build_flag.append("-X main.version '{}'".format(version))
return 'go build -ldflags "{}"'.format(" ".join(build_flag))
def main():
goos = "linux"
if sys.argv[1] == "build":
for arch in ["amd64", "arm64", "arm"]:
cmd = 'GOARCH={arch} go build --ldflags "-s -w -X main.version={version}" -o mdns_{goos}_{arch} .'.format(
arch=arch,
version=get_version(),
goos=goos
)
print(cmd)
run_cmd(cmd)
elif sys.argv[1] == "package":
for arch in ["amd64", "arm64", "arm"]:
cmd = 'tar -zcvf mdns_{goos}_{arch}.tar.gz mdns_{goos}_{arch} config.sample.d mdns.service'.format(
arch=arch,
goos=goos,
)
print(cmd)
run_cmd(cmd)
if __name__ == '__main__':
main()