This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmk.py
165 lines (133 loc) · 4.12 KB
/
bmk.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
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
163
164
165
# License: zlib license
# see accompanying LICENSE file
import os, sys, optparse, parse, libutil
from bmkcompilers import compilers
from util import get_platforms
tasks = {}
built = []
START_POINT = "start"
COMPILER = "mingw"
FILE = "build.bmk"
REBUILD = False
def composite_options(platformopts):
options = {}
p = get_platforms()
for platform,opts in platformopts.iteritems():
if platform != "none" and (not platform in p):
continue
for k,v in opts.iteritems():
if k in options: # append to the already-existing option
options[k].extend(v)
continue
options[k] = v
return options
def buildtask(task):
libs = []
source = []
objs = []
requires = []
type = ""
out = ""
if task in built:
print "skipping '%s' - already built" % task
return
if not task in tasks:
print "skipping - unknown task '%s'" % task
return
for k,v in tasks[task].iteritems():
if k == "depends":
for d in v:
print "building depend %s" % d
buildtask(d)
elif k == "libs":
libs = v
elif k == "source":
source = v
elif k == "requires":
requires = v
elif k == "type":
type = v[0]
elif k == "out":
out = v[0]
elif k == "objs":
objs = v
else:
print "unknown option '%s'" % k
if len(source) == 0 and len(objs) == 0:
# no sources or object files, skip it
return
print "<%s>" % task
print " libs:", libs
print " source:", source
print " requires:", requires
print " type:", type
print " out:", out
print ""
c = compilers[COMPILER]() # new instance of compiler
for x in source: c.add_source(x)
for x in libs: c.add_lib(x)
for x in objs: c.add_obj(x)
c.set_type(type)
c.set_out(out)
for d in requires:
l = libutil.find_package(d)
if l is None:
print "error: couldn't find required package '%s'" % d
return
c.add_lib_dir(l[0])
c.add_lib(l[1])
c.prepare()
touched = False
try: otime = os.path.getmtime(c.out)
except:
otime = None
touched = True
for x in source:
if not os.path.exists(x):
print "error: source file '%s' not found" % x
sys.exit(4)
if not touched and not REBUILD and otime is not None:
if os.path.getmtime(x) > otime:
touched = True
if not touched:
print "skipping '%s' - not modified" % task
return # don't need to rebuild
if not c.build():
# build failed
print "build failed"
sys.exit(1)
built.append(task)
def main():
global tasks, START_POINT, FILE, COMPILER, REBUILD
opt = optparse.OptionParser()
opt.add_option("-f", "--in", dest="file", help="input .bmk file", metavar="FILE", default=FILE)
opt.add_option("-s", "--start", dest="startpoint", help="which task to start with", metavar="STARTPOINT", default=START_POINT)
opt.add_option("-c", "--compiler", dest="compiler", help="which compiler to use", metavar="COMPILER", default=COMPILER)
opt.add_option("-r", "--rebuild", dest="rebuild", help="rebuild project (skip checking of file dates)", action="store_true", metavar="REBUILD", default=REBUILD)
opt.add_option("", "--debug", help="turn debugging on", action="store_true", default=False, metavar="DEBUG")
options, args = opt.parse_args()
START_POINT = options.startpoint
FILE = options.file
COMPILER = options.compiler
REBUILD = options.rebuild
print "platform:", get_platforms()
try:
f = open(FILE, "r")
text = f.read()
f.close()
except:
print "error opening file %s" % FILE
sys.exit(1)
p = parse.bmk_parse(text)
tasks = p["tasks"]
# composite them all
for k,platformopts in tasks.iteritems():
tasks[k] = composite_options(platformopts)
print "building %s" % START_POINT
# check for (start)
if START_POINT in tasks:
buildtask(START_POINT)
else:
print "error: no task '%s'" % START_POINT
sys.exit(2)
if __name__ == '__main__': main()