diff options
author | Richard Purdie <rpurdie@linux.intel.com> | 2010-08-16 16:37:29 +0100 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-08-19 22:36:25 +0100 |
commit | b6bfe1420517aa5aa190e17dca40ea70f09effd9 (patch) | |
tree | 2591a26f18290e8d929517df71f24645394c57fb /bitbake/lib/bb/build.py | |
parent | a45e1d54e19d4cd728e90df929b212e41ef70d4b (diff) | |
download | poky-b6bfe1420517aa5aa190e17dca40ea70f09effd9.tar.gz |
bitbake: Switch to use subprocess for forking tasks and FAKEROOTENV to run shell and python under a fakeroot environment
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb/build.py')
-rw-r--r-- | bitbake/lib/bb/build.py | 64 |
1 files changed, 41 insertions, 23 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py index 0bf0154cb4..77af92abee 100644 --- a/bitbake/lib/bb/build.py +++ b/bitbake/lib/bb/build.py | |||
@@ -44,12 +44,6 @@ class FuncFailed(Exception): | |||
44 | Second paramter is a logfile (optional) | 44 | Second paramter is a logfile (optional) |
45 | """ | 45 | """ |
46 | 46 | ||
47 | class EventException(Exception): | ||
48 | """Exception which is associated with an Event.""" | ||
49 | |||
50 | def __init__(self, msg, event): | ||
51 | self.args = msg, event | ||
52 | |||
53 | class TaskBase(event.Event): | 47 | class TaskBase(event.Event): |
54 | """Base class for task events""" | 48 | """Base class for task events""" |
55 | 49 | ||
@@ -80,7 +74,7 @@ class TaskFailed(TaskBase): | |||
80 | self.msg = msg | 74 | self.msg = msg |
81 | TaskBase.__init__(self, t, d) | 75 | TaskBase.__init__(self, t, d) |
82 | 76 | ||
83 | class InvalidTask(TaskBase): | 77 | class TaskInvalid(TaskBase): |
84 | """Invalid Task""" | 78 | """Invalid Task""" |
85 | 79 | ||
86 | # functions | 80 | # functions |
@@ -94,7 +88,7 @@ def exec_func(func, d, dirs = None): | |||
94 | return | 88 | return |
95 | 89 | ||
96 | flags = data.getVarFlags(func, d) | 90 | flags = data.getVarFlags(func, d) |
97 | for item in ['deps', 'check', 'interactive', 'python', 'cleandirs', 'dirs', 'lockfiles', 'fakeroot']: | 91 | for item in ['deps', 'check', 'interactive', 'python', 'cleandirs', 'dirs', 'lockfiles', 'fakeroot', 'task']: |
98 | if not item in flags: | 92 | if not item in flags: |
99 | flags[item] = None | 93 | flags[item] = None |
100 | 94 | ||
@@ -138,7 +132,7 @@ def exec_func(func, d, dirs = None): | |||
138 | # Handle logfiles | 132 | # Handle logfiles |
139 | si = file('/dev/null', 'r') | 133 | si = file('/dev/null', 'r') |
140 | try: | 134 | try: |
141 | if bb.msg.debug_level['default'] > 0 or ispython: | 135 | if bb.msg.debug_level['default'] > 0 and not ispython: |
142 | so = os.popen("tee \"%s\"" % logfile, "w") | 136 | so = os.popen("tee \"%s\"" % logfile, "w") |
143 | else: | 137 | else: |
144 | so = file(logfile, 'w') | 138 | so = file(logfile, 'w') |
@@ -158,6 +152,8 @@ def exec_func(func, d, dirs = None): | |||
158 | os.dup2(so.fileno(), oso[1]) | 152 | os.dup2(so.fileno(), oso[1]) |
159 | os.dup2(se.fileno(), ose[1]) | 153 | os.dup2(se.fileno(), ose[1]) |
160 | 154 | ||
155 | bb.event.useStdout = True | ||
156 | |||
161 | locks = [] | 157 | locks = [] |
162 | lockfiles = flags['lockfiles'] | 158 | lockfiles = flags['lockfiles'] |
163 | if lockfiles: | 159 | if lockfiles: |
@@ -183,6 +179,8 @@ def exec_func(func, d, dirs = None): | |||
183 | for lock in locks: | 179 | for lock in locks: |
184 | bb.utils.unlockfile(lock) | 180 | bb.utils.unlockfile(lock) |
185 | 181 | ||
182 | bb.event.useStdout = False | ||
183 | |||
186 | # Restore the backup fds | 184 | # Restore the backup fds |
187 | os.dup2(osi[0], osi[1]) | 185 | os.dup2(osi[0], osi[1]) |
188 | os.dup2(oso[0], oso[1]) | 186 | os.dup2(oso[0], oso[1]) |
@@ -221,6 +219,7 @@ def exec_func_python(func, d, runfile, logfile): | |||
221 | raise | 219 | raise |
222 | raise FuncFailed("Function %s failed" % func, logfile) | 220 | raise FuncFailed("Function %s failed" % func, logfile) |
223 | 221 | ||
222 | |||
224 | def exec_func_shell(func, d, runfile, logfile, flags): | 223 | def exec_func_shell(func, d, runfile, logfile, flags): |
225 | """Execute a shell BB 'function' Returns true if execution was successful. | 224 | """Execute a shell BB 'function' Returns true if execution was successful. |
226 | 225 | ||
@@ -251,12 +250,11 @@ def exec_func_shell(func, d, runfile, logfile, flags): | |||
251 | raise FuncFailed("Function not specified for exec_func_shell") | 250 | raise FuncFailed("Function not specified for exec_func_shell") |
252 | 251 | ||
253 | # execute function | 252 | # execute function |
254 | if flags['fakeroot']: | 253 | if flags['fakeroot'] and not flags['task']: |
255 | maybe_fakeroot = "PATH=\"%s\" %s " % (bb.data.getVar("PATH", d, 1), bb.data.getVar("FAKEROOT", d, 1) or "fakeroot") | 254 | bb.fatal("Function %s specifies fakeroot but isn't a task?!" % func) |
256 | else: | 255 | |
257 | maybe_fakeroot = '' | ||
258 | lang_environment = "LC_ALL=C " | 256 | lang_environment = "LC_ALL=C " |
259 | ret = os.system('%s%ssh -e %s' % (lang_environment, maybe_fakeroot, runfile)) | 257 | ret = os.system('%ssh -e %s' % (lang_environment, runfile)) |
260 | 258 | ||
261 | if ret == 0: | 259 | if ret == 0: |
262 | return | 260 | return |
@@ -273,7 +271,13 @@ def exec_task(task, d): | |||
273 | 271 | ||
274 | # Check whther this is a valid task | 272 | # Check whther this is a valid task |
275 | if not data.getVarFlag(task, 'task', d): | 273 | if not data.getVarFlag(task, 'task', d): |
276 | raise EventException("No such task", InvalidTask(task, d)) | 274 | event.fire(TaskInvalid(task, d), d) |
275 | bb.msg.error(bb.msg.domain.Build, "No such task: %s" % task) | ||
276 | return 1 | ||
277 | |||
278 | quieterr = False | ||
279 | if d.getVarFlag(task, "quieterrors") is not None: | ||
280 | quieterr = True | ||
277 | 281 | ||
278 | try: | 282 | try: |
279 | bb.msg.debug(1, bb.msg.domain.Build, "Executing task %s" % task) | 283 | bb.msg.debug(1, bb.msg.domain.Build, "Executing task %s" % task) |
@@ -292,6 +296,11 @@ def exec_task(task, d): | |||
292 | for func in postfuncs: | 296 | for func in postfuncs: |
293 | exec_func(func, localdata) | 297 | exec_func(func, localdata) |
294 | event.fire(TaskSucceeded(task, localdata), localdata) | 298 | event.fire(TaskSucceeded(task, localdata), localdata) |
299 | |||
300 | # make stamp, or cause event and raise exception | ||
301 | if not data.getVarFlag(task, 'nostamp', d) and not data.getVarFlag(task, 'selfstamp', d): | ||
302 | make_stamp(task, d) | ||
303 | |||
295 | except FuncFailed as message: | 304 | except FuncFailed as message: |
296 | # Try to extract the optional logfile | 305 | # Try to extract the optional logfile |
297 | try: | 306 | try: |
@@ -299,14 +308,22 @@ def exec_task(task, d): | |||
299 | except: | 308 | except: |
300 | logfile = None | 309 | logfile = None |
301 | msg = message | 310 | msg = message |
302 | bb.msg.note(1, bb.msg.domain.Build, "Task failed: %s" % message ) | 311 | if not quieterr: |
303 | failedevent = TaskFailed(msg, logfile, task, d) | 312 | bb.msg.error(bb.msg.domain.Build, "Task failed: %s" % message ) |
304 | event.fire(failedevent, d) | 313 | failedevent = TaskFailed(msg, logfile, task, d) |
305 | raise EventException("Function failed in task: %s" % message, failedevent) | 314 | event.fire(failedevent, d) |
306 | 315 | return 1 | |
307 | # make stamp, or cause event and raise exception | 316 | |
308 | if not data.getVarFlag(task, 'nostamp', d) and not data.getVarFlag(task, 'selfstamp', d): | 317 | except Exception: |
309 | make_stamp(task, d) | 318 | from traceback import format_exc |
319 | if not quieterr: | ||
320 | bb.msg.error(bb.msg.domain.Build, "Build of %s failed" % (task)) | ||
321 | bb.msg.error(bb.msg.domain.Build, format_exc()) | ||
322 | failedevent = TaskFailed("Task Failed", None, task, d) | ||
323 | event.fire(failedevent, d) | ||
324 | return 1 | ||
325 | |||
326 | return 0 | ||
310 | 327 | ||
311 | def extract_stamp(d, fn): | 328 | def extract_stamp(d, fn): |
312 | """ | 329 | """ |
@@ -380,6 +397,7 @@ def add_tasks(tasklist, d): | |||
380 | getTask('rdeptask') | 397 | getTask('rdeptask') |
381 | getTask('recrdeptask') | 398 | getTask('recrdeptask') |
382 | getTask('nostamp') | 399 | getTask('nostamp') |
400 | getTask('fakeroot') | ||
383 | task_deps['parents'][task] = [] | 401 | task_deps['parents'][task] = [] |
384 | for dep in flags['deps']: | 402 | for dep in flags['deps']: |
385 | dep = data.expand(dep, d) | 403 | dep = data.expand(dep, d) |