This repository was archived by the owner on Jun 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake.py
More file actions
executable file
·162 lines (123 loc) · 3.89 KB
/
Copy pathmake.py
File metadata and controls
executable file
·162 lines (123 loc) · 3.89 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python
# http://stackoverflow.com/a/14050282
def check_antipackage():
from sys import version_info
sys_version = version_info[:2]
found = True
if sys_version < (3, 0):
# 'python 2'
from pkgutil import find_loader
found = find_loader('antipackage') is not None
elif sys_version <= (3, 3):
# 'python <= 3.3'
from importlib import find_loader
found = find_loader('antipackage') is not None
else:
# 'python >= 3.4'
from importlib import util
found = util.find_spec('antipackage') is not None
if not found:
print('Install missing package "antipackage"')
print('Example: pip install git+https://github.com/ellisonbg/antipackage.git#egg=antipackage')
from sys import exit
exit(1)
check_antipackage()
# ref: https://github.com/ellisonbg/antipackage
import antipackage
from github.appscode.libbuild import libbuild
import os
import os.path
import subprocess
import sys
from os.path import expandvars
libbuild.REPO_ROOT = expandvars('$GOPATH') + '/src/github.com/appscode/tillerc'
BUILD_METADATA = libbuild.metadata(libbuild.REPO_ROOT)
libbuild.BIN_MATRIX = {
'tillerc': {
'type': 'go',
'go_version': True,
'use_cgo': False,
'distro': {
'linux': ['amd64']
}
}
}
libbuild.BUCKET_MATRIX = {
'prod': 'gs://appscode-cdn',
'dev': 'gs://appscode-dev'
}
def call(cmd, stdin=None, cwd=libbuild.REPO_ROOT):
print(cmd)
return subprocess.call([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd)
def die(status):
if status:
sys.exit(status)
def check_output(cmd, stdin=None, cwd=libbuild.REPO_ROOT):
print(cmd)
return subprocess.check_output([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd)
def version():
# json.dump(BUILD_METADATA, sys.stdout, sort_keys=True, indent=2)
for k in sorted(BUILD_METADATA):
print(k + '=' + BUILD_METADATA[k])
def fmt():
die(call('goimports -w cmd pkg'))
call('gofmt -s -w cmd pkg')
def vet():
call('go vet ./cmd/... ./pkg/...')
def lint():
call('golint ./cmd/...')
call('golint ./pkg/...')
def gen():
return
def build_cmd(name):
cfg = libbuild.BIN_MATRIX[name]
if cfg['type'] == 'go':
if 'distro' in cfg:
for goos, archs in cfg['distro'].items():
for goarch in archs:
libbuild.go_build(name, goos, goarch, main='cmd/{}/*.go'.format(name))
else:
libbuild.go_build(name, libbuild.GOHOSTOS, libbuild.GOHOSTARCH, main='cmd/{}/*.go'.format(name))
def build_cmds():
gen()
for name in libbuild.BIN_MATRIX:
build_cmd(name)
def build(name=None):
if name:
cfg = libbuild.BIN_MATRIX[name]
if cfg['type'] == 'go':
gen()
build_cmd(name)
else:
build_cmds()
def push(name=None):
if name:
bindir = libbuild.REPO_ROOT + '/dist/' + name
push_bin(bindir)
else:
dist = libbuild.REPO_ROOT + '/dist'
for name in os.listdir(dist):
d = dist + '/' + name
if os.path.isdir(d):
push_bin(d)
def push_bin(bindir):
call('rm -f *.md5', cwd=bindir)
call('rm -f *.sha1', cwd=bindir)
for f in os.listdir(bindir):
if os.path.isfile(bindir + '/' + f):
libbuild.upload_to_cloud(bindir, f, BUILD_METADATA['version'])
def update_registry():
libbuild.update_registry(BUILD_METADATA['version'])
def install():
die(call('GO15VENDOREXPERIMENT=1 ' + libbuild.GOC + ' install ./cmd/...'))
def default():
gen()
fmt()
die(call('GO15VENDOREXPERIMENT=1 ' + libbuild.GOC + ' install ./cmd/...'))
if __name__ == "__main__":
if len(sys.argv) > 1:
# http://stackoverflow.com/a/834451
# http://stackoverflow.com/a/817296
globals()[sys.argv[1]](*sys.argv[2:])
else:
default()