-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
76 lines (68 loc) · 2.79 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
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
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import time
import os
import platform
def build(outname, goos, goarch):
x = time.localtime()
y = x[3] * 60 * 60 + x[4] * 60 + x[5]
mainver = "1.0.0.{0}.{1}".format(
time.strftime("%y%m%d", time.localtime()), y)
r = os.popen('go version')
gover = r.read().strip().replace("go version ", "")
pf = "{0}({1})".format(platform.platform(), platform.node())
r.close()
if goos == "windows":
if goarch == "386":
outpath = "dist_x86"
else:
outpath = "dist_win"
else:
outpath = "dist_linux"
outname = outpath + "/" + outname
buildcmd = 'GOOS={5} GOARCH={6} go build -ldflags="-s -w -X main.version={1} -X \'main.buildDate={2}\' -X \'main.goVersion={3}\' -X \'main.platform={4}\'" -o {0} main.go'.format(
outname, mainver, time.ctime(time.time()), gover, pf, goos, goarch)
# print(buildcmd)
os.system(buildcmd)
# os.system("upx --best {0}".format(outname))
def build_service(outname, goos, goarch):
x = time.localtime()
y = x[3] * 60 * 60 + x[4] * 60 + x[5]
mainver = "1.0.0.{0}.{1}".format(
time.strftime("%y%m%d", time.localtime()), y)
r = os.popen('go version')
gover = r.read().strip().replace("go version ", "")
pf = "{0}({1})".format(platform.platform(), platform.node())
r.close()
if goos == "windows":
if goarch == "386":
outpath = "dist_x86"
else:
outpath = "dist_win"
else:
outpath = "dist_linux"
outname = outpath + "/" + outname
buildcmd = 'GOOS={5} GOARCH={6} go build -ldflags="-s -w -H windowsgui -X main.version={1} -X \'main.buildDate={2}\' -X \'main.goVersion={3}\' -X \'main.platform={4}\'" -o {0} main.go'.format(
outname, mainver, time.ctime(time.time()), gover, pf, goos, goarch)
# print(buildcmd)
os.system(buildcmd)
os.system("upx --best dist_win/{0}".format(outname))
if __name__ == "__main__":
x = time.localtime()
y = x[3] * 60 * 60 + x[4] * 60 + x[5]
nv = "1.0.0.{0}.{1}".format(time.strftime("%y%m%d", time.localtime()), y)
ov = "\"0.0.0\""
r = os.popen('go version')
gv = r.read().strip().replace("go version ", "")
pl = "{0}({1})".format(platform.platform(), platform.node())
r.close()
# print("=== start build windows x86 ...")
# build("sample.exe", "windows", "386")
# print("\n=== start build windows x64 ...")
# build("sample.exe", "windows", "amd64")
# 编译成windows后台程序,不会有黑框,在进程列表中可查看到
# print("\n=== start build windows x64 service ...")
# build("sampled.exe", "windows", "amd64")
print("\n=== start build linux x64 ...")
build("hcloud", "linux", "amd64")
# os.system("cp -f distwin/ecms*.exe ../../python/mwsc/dist/bin/")