-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake.py
98 lines (79 loc) · 2.28 KB
/
make.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
93
94
95
96
97
from subprocess import Popen, PIPE
from utils import makedirs
import sys
INDENT = ""
class CommandException(Exception):
pass
def build():
tasks = {}
try:
made = set(line.strip() for line in open('made'))
except IOError:
made = set()
def make(name, depth = 0, made = made):
if made is None:
made = set()
def _make(name):
make(name, depth + 1, made = made)
def _directory(path):
print '%smkdir -p %s' % (
INDENT * (depth + 1),
path,
)
makedirs(path)
_make.directory = _directory
def _command(args, output = None):
if isinstance(args, basestring):
args = 'bash', '-c', args
args = ["%s" % arg for arg in args]
print '%s%s' % (
INDENT * (depth + 1),
" ".join(args),
)
if output is not None:
output = open(output, 'w')
process = Popen(args, stdout = output)
process.communicate()
if process.returncode != 0:
raise CommandException("Process exited with %d returncode" % process.returncode)
_make.command = _command
def _depends(path):
print '%s# depends: %s' % (
INDENT * (depth + 1),
path,
)
_make.depends = _depends
print "%s# %s:" % (
INDENT * (depth),
name,
)
if name in made:
print "%s# already made %s" % (
INDENT * (depth + 1),
name,
)
return
tasks[name](_make, name)
made.add(name)
made_file = open('made', 'a')
made_file.write("%s\n" % name)
made_file.flush()
made_file.close()
def task(name):
def wrapper(f):
tasks[name] = f
return wrapper
file = task
def enclosure(*args, **kws):
def enclosure(f):
return f(*args, **kws)
return enclosure
exec open('makefile.py') in locals()
try:
import sys
for arg in sys.argv[1:]:
make(arg)
except CommandException, error:
print error
if __name__ == '__main__':
build()