summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/build.py
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@linux.intel.com>2011-01-05 00:54:16 +0000
committerRichard Purdie <rpurdie@linux.intel.com>2011-01-05 00:58:24 +0000
commit25ac24e02e3e96945e8ac83e16fe27a6b24789b1 (patch)
tree9a6b3ed525dcbe8ae94ce4248acbde8380cbad76 /bitbake/lib/bb/build.py
parent03679364a9e280af24ba7038dce54272eb33af83 (diff)
downloadpoky-25ac24e02e3e96945e8ac83e16fe27a6b24789b1.tar.gz
bitbake: build.py logging updates
python tasks calling shell functions using exec_func() would show the log file as /dev/null. It makes most sense for all the task logging to be setup centrally by exec_task(), at least with the current code base in Poky. This commit will need discussion in relation to upstream bitbake and the IO redirection could be better handled using a context manager (although task contexts shouldn't ever nest). Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb/build.py')
-rw-r--r--bitbake/lib/bb/build.py39
1 files changed, 23 insertions, 16 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py
index 44ad3965a2..e288e35613 100644
--- a/bitbake/lib/bb/build.py
+++ b/bitbake/lib/bb/build.py
@@ -119,7 +119,7 @@ class LogTee(object):
119 return '<LogTee {0}>'.format(self.name) 119 return '<LogTee {0}>'.format(self.name)
120 120
121 121
122def exec_func(func, d, dirs = None, logfile = NULL): 122def exec_func(func, d, dirs = None):
123 """Execute an BB 'function'""" 123 """Execute an BB 'function'"""
124 124
125 body = data.getVar(func, d) 125 body = data.getVar(func, d)
@@ -163,9 +163,9 @@ def exec_func(func, d, dirs = None, logfile = NULL):
163 163
164 with bb.utils.fileslocked(lockfiles): 164 with bb.utils.fileslocked(lockfiles):
165 if ispython: 165 if ispython:
166 exec_func_python(func, d, runfile, logfile, cwd=adir) 166 exec_func_python(func, d, runfile, cwd=adir)
167 else: 167 else:
168 exec_func_shell(func, d, runfile, logfile, cwd=adir) 168 exec_func_shell(func, d, runfile, cwd=adir)
169 169
170_functionfmt = """ 170_functionfmt = """
171def {function}(d): 171def {function}(d):
@@ -174,7 +174,7 @@ def {function}(d):
174{function}(d) 174{function}(d)
175""" 175"""
176logformatter = bb.msg.BBLogFormatter("%(levelname)s: %(message)s") 176logformatter = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
177def exec_func_python(func, d, runfile, logfile, cwd=None): 177def exec_func_python(func, d, runfile, cwd=None):
178 """Execute a python BB 'function'""" 178 """Execute a python BB 'function'"""
179 179
180 bbfile = d.getVar('FILE', True) 180 bbfile = d.getVar('FILE', True)
@@ -190,10 +190,6 @@ def exec_func_python(func, d, runfile, logfile, cwd=None):
190 if cwd: 190 if cwd:
191 os.chdir(cwd) 191 os.chdir(cwd)
192 192
193 handler = logging.StreamHandler(logfile)
194 handler.setFormatter(logformatter)
195 bblogger.addHandler(handler)
196
197 try: 193 try:
198 comp = utils.better_compile(code, func, bbfile) 194 comp = utils.better_compile(code, func, bbfile)
199 utils.better_exec(comp, {"d": d}, code, bbfile) 195 utils.better_exec(comp, {"d": d}, code, bbfile)
@@ -203,11 +199,10 @@ def exec_func_python(func, d, runfile, logfile, cwd=None):
203 199
204 raise FuncFailed(func, None) 200 raise FuncFailed(func, None)
205 finally: 201 finally:
206 bblogger.removeHandler(handler)
207 if olddir: 202 if olddir:
208 os.chdir(olddir) 203 os.chdir(olddir)
209 204
210def exec_func_shell(function, d, runfile, logfile, cwd=None): 205def exec_func_shell(function, d, runfile, cwd=None):
211 """Execute a shell function from the metadata 206 """Execute a shell function from the metadata
212 207
213 Note on directory behavior. The 'dirs' varflag should contain a list 208 Note on directory behavior. The 'dirs' varflag should contain a list
@@ -235,13 +230,16 @@ def exec_func_shell(function, d, runfile, logfile, cwd=None):
235 cmd = runfile 230 cmd = runfile
236 231
237 if logger.getEffectiveLevel() <= logging.DEBUG: 232 if logger.getEffectiveLevel() <= logging.DEBUG:
238 logfile = LogTee(logger, logfile) 233 logfile = LogTee(logger, sys.stdout)
234 else:
235 logfile = None
239 236
240 try: 237 try:
241 bb.process.run(cmd, env=env, cwd=cwd, shell=False, stdin=NULL, 238 bb.process.run(cmd, env=env, cwd=cwd, shell=False, stdin=NULL,
242 log=logfile) 239 log=logfile)
243 except bb.process.CmdError: 240 except bb.process.CmdError:
244 raise FuncFailed(function, logfile.name) 241 logfn = d.getVar('BB_LOGFILE', True)
242 raise FuncFailed(function, logfn)
245 243
246def _task_data(fn, task, d): 244def _task_data(fn, task, d):
247 localdata = data.createCopy(d) 245 localdata = data.createCopy(d)
@@ -308,22 +306,31 @@ def _exec_task(fn, task, d, quieterr):
308 origstdout = bb.event.useStdout 306 origstdout = bb.event.useStdout
309 bb.event.useStdout = True 307 bb.event.useStdout = True
310 308
309 # Ensure python logging goes to the logfile
310 handler = logging.StreamHandler(logfile)
311 handler.setFormatter(logformatter)
312 bblogger.addHandler(handler)
313
314 localdata.setVar('BB_LOGFILE', logfn)
315
311 event.fire(TaskStarted(task, localdata), localdata) 316 event.fire(TaskStarted(task, localdata), localdata)
312 try: 317 try:
313 for func in (prefuncs or '').split(): 318 for func in (prefuncs or '').split():
314 exec_func(func, localdata, logfile=logfile) 319 exec_func(func, localdata)
315 exec_func(task, localdata, logfile=logfile) 320 exec_func(task, localdata)
316 for func in (postfuncs or '').split(): 321 for func in (postfuncs or '').split():
317 exec_func(func, localdata, logfile=logfile) 322 exec_func(func, localdata)
318 except FuncFailed as exc: 323 except FuncFailed as exc:
319 if not quieterr: 324 if not quieterr:
320 logger.error(str(exc)) 325 logger.error(str(exc))
321 event.fire(TaskFailed(exc.name, exc.logfile, localdata), localdata) 326 event.fire(TaskFailed(exc.name, logfn, localdata), localdata)
322 return 1 327 return 1
323 finally: 328 finally:
324 sys.stdout.flush() 329 sys.stdout.flush()
325 sys.stderr.flush() 330 sys.stderr.flush()
326 331
332 bblogger.removeHandler(handler)
333
327 bb.event.useStdout = origstdout 334 bb.event.useStdout = origstdout
328 335
329 # Restore the backup fds 336 # Restore the backup fds