-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.py
executable file
·92 lines (65 loc) · 2.39 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
import os
import sys
import argparse
import contextlib
import subprocess
parser = argparse.ArgumentParser()
parser.add_argument('--plugin', action='append', help='additional plugins to build')
parser.add_argument('--build-dir', default='build', help='directory to build in')
parser.add_argument('--run', action='store_true', help='run after building')
parser.add_argument('--build', default='debug', help='dub build mode')
parser.add_argument('--update', default=False, action='store_true', help='update modules before building')
parser.add_argument('--force', default=False, action='store_true', help='force build')
def command(cmd):
ret = subprocess.check_call(cmd.split(' '))
if ret != 0:
raise Exception("Error running command `{}`:".format(cmd))
@contextlib.contextmanager
def cd(directory):
cwd = os.getcwd()
os.chdir(directory)
yield
os.chdir(cwd)
def run():
os.system("./jeff")
def dub_cmd(args):
extras = ["--build={}".format(args.build)]
if args.force:
extras.append("--force")
return 'dub build --parallel {}'.format(' '.join(extras))
def build_plugin(plugin, plugin_path, cmd, update):
print ' Building plugin {}...'.format(plugin)
author, name = plugin.split('/')
if not os.path.exists(name):
command('git clone --depth 1 git@github.com:{}.git'.format(plugin))
elif update:
with cd(name):
command('git reset --hard')
command('git pull')
with cd(name):
command(cmd)
if not os.path.exists('lib{}.so'.format(name)):
print 'ERROR building {}: no plugin dynamic library found'.format(plugin)
return
command('mv lib{}.so {}'.format(name, plugin_path))
def build(build, plugins, directory, update):
print 'Building with {} plugins...'.format(len(plugins))
if not os.path.exists('plugins'):
os.mkdir('plugins')
if not os.path.exists(directory):
os.mkdir(directory)
plugin_path = os.path.join(os.getcwd(), 'plugins')
with cd(directory):
for plugin in plugins:
build_plugin(plugin, plugin_path, build, update)
print ' Building jeff...'
command(build)
print 'DONE'
def main():
args = parser.parse_args()
build(dub_cmd(args), args.plugin or [], args.build_dir, args.update)
if args.run:
run()
if __name__ == '__main__':
sys.exit(main() or 0)