diff options
Diffstat (limited to 'bitbake/lib/bb/build.py')
-rw-r--r-- | bitbake/lib/bb/build.py | 110 |
1 files changed, 75 insertions, 35 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py index 8e169e002a..942bdc1a39 100644 --- a/bitbake/lib/bb/build.py +++ b/bitbake/lib/bb/build.py | |||
@@ -25,18 +25,9 @@ You should have received a copy of the GNU General Public License along with | |||
25 | Based on functions from the base bb module, Copyright 2003 Holger Schurig | 25 | Based on functions from the base bb module, Copyright 2003 Holger Schurig |
26 | """ | 26 | """ |
27 | 27 | ||
28 | from bb import debug, data, fetch, fatal, error, note, event, mkdirhier, utils | 28 | from bb import data, fetch, event, mkdirhier, utils |
29 | import bb, os | 29 | import bb, os |
30 | 30 | ||
31 | # data holds flags and function name for a given task | ||
32 | _task_data = data.init() | ||
33 | |||
34 | # graph represents task interdependencies | ||
35 | _task_graph = bb.digraph() | ||
36 | |||
37 | # stack represents execution order, excepting dependencies | ||
38 | _task_stack = [] | ||
39 | |||
40 | # events | 31 | # events |
41 | class FuncFailed(Exception): | 32 | class FuncFailed(Exception): |
42 | """Executed function failed""" | 33 | """Executed function failed""" |
@@ -76,13 +67,6 @@ class InvalidTask(TaskBase): | |||
76 | 67 | ||
77 | # functions | 68 | # functions |
78 | 69 | ||
79 | def init(data): | ||
80 | global _task_data, _task_graph, _task_stack | ||
81 | _task_data = data.init() | ||
82 | _task_graph = bb.digraph() | ||
83 | _task_stack = [] | ||
84 | |||
85 | |||
86 | def exec_func(func, d, dirs = None): | 70 | def exec_func(func, d, dirs = None): |
87 | """Execute an BB 'function'""" | 71 | """Execute an BB 'function'""" |
88 | 72 | ||
@@ -163,7 +147,7 @@ def exec_func_shell(func, d): | |||
163 | 147 | ||
164 | f = open(runfile, "w") | 148 | f = open(runfile, "w") |
165 | f.write("#!/bin/sh -e\n") | 149 | f.write("#!/bin/sh -e\n") |
166 | if bb.debug_level > 0: f.write("set -x\n") | 150 | if bb.msg.debug_level['default'] > 0: f.write("set -x\n") |
167 | data.emit_env(f, d) | 151 | data.emit_env(f, d) |
168 | 152 | ||
169 | f.write("cd %s\n" % os.getcwd()) | 153 | f.write("cd %s\n" % os.getcwd()) |
@@ -171,18 +155,18 @@ def exec_func_shell(func, d): | |||
171 | f.close() | 155 | f.close() |
172 | os.chmod(runfile, 0775) | 156 | os.chmod(runfile, 0775) |
173 | if not func: | 157 | if not func: |
174 | error("Function not specified") | 158 | bb.msg.error(bb.msg.domain.Build, "Function not specified") |
175 | raise FuncFailed() | 159 | raise FuncFailed() |
176 | 160 | ||
177 | # open logs | 161 | # open logs |
178 | si = file('/dev/null', 'r') | 162 | si = file('/dev/null', 'r') |
179 | try: | 163 | try: |
180 | if bb.debug_level > 0: | 164 | if bb.msg.debug_level['default'] > 0: |
181 | so = os.popen("tee \"%s\"" % logfile, "w") | 165 | so = os.popen("tee \"%s\"" % logfile, "w") |
182 | else: | 166 | else: |
183 | so = file(logfile, 'w') | 167 | so = file(logfile, 'w') |
184 | except OSError, e: | 168 | except OSError, e: |
185 | bb.error("opening log file: %s" % e) | 169 | bb.msg.error(bb.msg.domain.Build, "opening log file: %s" % e) |
186 | pass | 170 | pass |
187 | 171 | ||
188 | se = so | 172 | se = so |
@@ -205,7 +189,10 @@ def exec_func_shell(func, d): | |||
205 | else: | 189 | else: |
206 | maybe_fakeroot = '' | 190 | maybe_fakeroot = '' |
207 | ret = os.system('%ssh -e %s' % (maybe_fakeroot, runfile)) | 191 | ret = os.system('%ssh -e %s' % (maybe_fakeroot, runfile)) |
208 | os.chdir(prevdir) | 192 | try: |
193 | os.chdir(prevdir) | ||
194 | except: | ||
195 | pass | ||
209 | 196 | ||
210 | if not interact: | 197 | if not interact: |
211 | # restore the backups | 198 | # restore the backups |
@@ -224,14 +211,14 @@ def exec_func_shell(func, d): | |||
224 | os.close(ose[0]) | 211 | os.close(ose[0]) |
225 | 212 | ||
226 | if ret==0: | 213 | if ret==0: |
227 | if bb.debug_level > 0: | 214 | if bb.msg.debug_level['default'] > 0: |
228 | os.remove(runfile) | 215 | os.remove(runfile) |
229 | # os.remove(logfile) | 216 | # os.remove(logfile) |
230 | return | 217 | return |
231 | else: | 218 | else: |
232 | error("function %s failed" % func) | 219 | bb.msg.error(bb.msg.domain.Build, "function %s failed" % func) |
233 | if data.getVar("BBINCLUDELOGS", d): | 220 | if data.getVar("BBINCLUDELOGS", d): |
234 | error("log data follows (%s)" % logfile) | 221 | bb.msg.error(bb.msg.domain.Build, "log data follows (%s)" % logfile) |
235 | f = open(logfile, "r") | 222 | f = open(logfile, "r") |
236 | while True: | 223 | while True: |
237 | l = f.readline() | 224 | l = f.readline() |
@@ -241,7 +228,7 @@ def exec_func_shell(func, d): | |||
241 | print '| %s' % l | 228 | print '| %s' % l |
242 | f.close() | 229 | f.close() |
243 | else: | 230 | else: |
244 | error("see log in %s" % logfile) | 231 | bb.msg.error(bb.msg.domain.Build, "see log in %s" % logfile) |
245 | raise FuncFailed( logfile ) | 232 | raise FuncFailed( logfile ) |
246 | 233 | ||
247 | 234 | ||
@@ -281,7 +268,7 @@ def exec_task(task, d): | |||
281 | return 1 | 268 | return 1 |
282 | 269 | ||
283 | try: | 270 | try: |
284 | debug(1, "Executing task %s" % item) | 271 | bb.msg.debug(1, bb.msg.domain.Build, "Executing task %s" % item) |
285 | old_overrides = data.getVar('OVERRIDES', d, 0) | 272 | old_overrides = data.getVar('OVERRIDES', d, 0) |
286 | localdata = data.createCopy(d) | 273 | localdata = data.createCopy(d) |
287 | data.setVar('OVERRIDES', 'task_%s:%s' % (item, old_overrides), localdata) | 274 | data.setVar('OVERRIDES', 'task_%s:%s' % (item, old_overrides), localdata) |
@@ -292,21 +279,63 @@ def exec_task(task, d): | |||
292 | task_cache.append(item) | 279 | task_cache.append(item) |
293 | data.setVar('_task_cache', task_cache, d) | 280 | data.setVar('_task_cache', task_cache, d) |
294 | except FuncFailed, reason: | 281 | except FuncFailed, reason: |
295 | note( "Task failed: %s" % reason ) | 282 | bb.msg.note(1, bb.msg.domain.Build, "Task failed: %s" % reason ) |
296 | failedevent = TaskFailed(item, d) | 283 | failedevent = TaskFailed(item, d) |
297 | event.fire(failedevent) | 284 | event.fire(failedevent) |
298 | raise EventException("Function failed in task: %s" % reason, failedevent) | 285 | raise EventException("Function failed in task: %s" % reason, failedevent) |
299 | 286 | ||
300 | # execute | 287 | if data.getVarFlag(task, 'dontrundeps', d): |
301 | task_graph.walkdown(task, execute) | 288 | execute(None, task) |
289 | else: | ||
290 | task_graph.walkdown(task, execute) | ||
302 | 291 | ||
303 | # make stamp, or cause event and raise exception | 292 | # make stamp, or cause event and raise exception |
304 | if not data.getVarFlag(task, 'nostamp', d): | 293 | if not data.getVarFlag(task, 'nostamp', d): |
305 | mkstamp(task, d) | 294 | mkstamp(task, d) |
306 | 295 | ||
296 | def stamp_is_current_cache(dataCache, file_name, task, checkdeps = 1): | ||
297 | """ | ||
298 | Check status of a given task's stamp. | ||
299 | Returns 0 if it is not current and needs updating. | ||
300 | Same as stamp_is_current but works against the dataCache instead of d | ||
301 | """ | ||
302 | task_graph = dataCache.task_queues[file_name] | ||
303 | |||
304 | if not dataCache.stamp[file_name]: | ||
305 | return 0 | ||
306 | |||
307 | stampfile = "%s.%s" % (dataCache.stamp[file_name], task) | ||
308 | if not os.access(stampfile, os.F_OK): | ||
309 | return 0 | ||
310 | |||
311 | if checkdeps == 0: | ||
312 | return 1 | ||
313 | |||
314 | import stat | ||
315 | tasktime = os.stat(stampfile)[stat.ST_MTIME] | ||
316 | |||
317 | _deps = [] | ||
318 | def checkStamp(graph, task): | ||
319 | # check for existance | ||
320 | if 'nostamp' in dataCache.task_deps[file_name] and task in dataCache.task_deps[file_name]['nostamp']: | ||
321 | return 1 | ||
322 | |||
323 | if not stamp_is_current_cache(dataCache, file_name, task, 0): | ||
324 | return 0 | ||
325 | |||
326 | depfile = "%s.%s" % (dataCache.stamp[file_name], task) | ||
327 | deptime = os.stat(depfile)[stat.ST_MTIME] | ||
328 | if deptime > tasktime: | ||
329 | return 0 | ||
330 | return 1 | ||
331 | |||
332 | return task_graph.walkdown(task, checkStamp) | ||
307 | 333 | ||
308 | def stamp_is_current(task, d, checkdeps = 1): | 334 | def stamp_is_current(task, d, checkdeps = 1): |
309 | """Check status of a given task's stamp. returns 0 if it is not current and needs updating.""" | 335 | """ |
336 | Check status of a given task's stamp. | ||
337 | Returns 0 if it is not current and needs updating. | ||
338 | """ | ||
310 | task_graph = data.getVar('_task_graph', d) | 339 | task_graph = data.getVar('_task_graph', d) |
311 | if not task_graph: | 340 | if not task_graph: |
312 | task_graph = bb.digraph() | 341 | task_graph = bb.digraph() |
@@ -360,7 +389,6 @@ def mkstamp(task, d): | |||
360 | f = open(stamp, "w") | 389 | f = open(stamp, "w") |
361 | f.close() | 390 | f.close() |
362 | 391 | ||
363 | |||
364 | def add_task(task, deps, d): | 392 | def add_task(task, deps, d): |
365 | task_graph = data.getVar('_task_graph', d) | 393 | task_graph = data.getVar('_task_graph', d) |
366 | if not task_graph: | 394 | if not task_graph: |
@@ -374,6 +402,21 @@ def add_task(task, deps, d): | |||
374 | # don't assume holding a reference | 402 | # don't assume holding a reference |
375 | data.setVar('_task_graph', task_graph, d) | 403 | data.setVar('_task_graph', task_graph, d) |
376 | 404 | ||
405 | task_deps = data.getVar('_task_deps', d) | ||
406 | if not task_deps: | ||
407 | task_deps = {} | ||
408 | def getTask(name): | ||
409 | deptask = data.getVarFlag(task, name, d) | ||
410 | if deptask: | ||
411 | if not name in task_deps: | ||
412 | task_deps[name] = {} | ||
413 | task_deps[name][task] = deptask | ||
414 | getTask('deptask') | ||
415 | getTask('rdeptask') | ||
416 | getTask('recrdeptask') | ||
417 | getTask('nostamp') | ||
418 | |||
419 | data.setVar('_task_deps', task_deps, d) | ||
377 | 420 | ||
378 | def remove_task(task, kill, d): | 421 | def remove_task(task, kill, d): |
379 | """Remove an BB 'task'. | 422 | """Remove an BB 'task'. |
@@ -399,6 +442,3 @@ def task_exists(task, d): | |||
399 | task_graph = bb.digraph() | 442 | task_graph = bb.digraph() |
400 | data.setVar('_task_graph', task_graph, d) | 443 | data.setVar('_task_graph', task_graph, d) |
401 | return task_graph.hasnode(task) | 444 | return task_graph.hasnode(task) |
402 | |||
403 | def get_task_data(): | ||
404 | return _task_data | ||