summaryrefslogtreecommitdiff
path: root/bitbake/lib/bb
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
parent03679364a9e280af24ba7038dce54272eb33af83 (diff)
downloadopenembedded-core-25ac24e02e3e96945e8ac83e16fe27a6b24789b1.tar.gz
openembedded-core-25ac24e02e3e96945e8ac83e16fe27a6b24789b1.tar.bz2
openembedded-core-25ac24e02e3e96945e8ac83e16fe27a6b24789b1.tar.xz
openembedded-core-25ac24e02e3e96945e8ac83e16fe27a6b24789b1.zip
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')
-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 44ad3965a..e288e3561 100644
--- a/bitbake/lib/bb/build.py
+++ b/bitbake/lib/bb/build.py
@@ -119,7 +119,7 @@ class LogTee(object):
return '<LogTee {0}>'.format(self.name)
-def exec_func(func, d, dirs = None, logfile = NULL):
+def exec_func(func, d, dirs = None):
"""Execute an BB 'function'"""
body = data.getVar(func, d)
@@ -163,9 +163,9 @@ def exec_func(func, d, dirs = None, logfile = NULL):
with bb.utils.fileslocked(lockfiles):
if ispython:
- exec_func_python(func, d, runfile, logfile, cwd=adir)
+ exec_func_python(func, d, runfile, cwd=adir)
else:
- exec_func_shell(func, d, runfile, logfile, cwd=adir)
+ exec_func_shell(func, d, runfile, cwd=adir)
_functionfmt = """
def {function}(d):
@@ -174,7 +174,7 @@ def {function}(d):
{function}(d)
"""
logformatter = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
-def exec_func_python(func, d, runfile, logfile, cwd=None):
+def exec_func_python(func, d, runfile, cwd=None):
"""Execute a python BB 'function'"""
bbfile = d.getVar('FILE', True)
@@ -190,10 +190,6 @@ def exec_func_python(func, d, runfile, logfile, cwd=None):
if cwd:
os.chdir(cwd)
- handler = logging.StreamHandler(logfile)
- handler.setFormatter(logformatter)
- bblogger.addHandler(handler)
-
try:
comp = utils.better_compile(code, func, bbfile)
utils.better_exec(comp, {"d": d}, code, bbfile)
@@ -203,11 +199,10 @@ def exec_func_python(func, d, runfile, logfile, cwd=None):
raise FuncFailed(func, None)
finally:
- bblogger.removeHandler(handler)
if olddir:
os.chdir(olddir)
-def exec_func_shell(function, d, runfile, logfile, cwd=None):
+def exec_func_shell(function, d, runfile, cwd=None):
"""Execute a shell function from the metadata
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):
cmd = runfile
if logger.getEffectiveLevel() <= logging.DEBUG:
- logfile = LogTee(logger, logfile)
+ logfile = LogTee(logger, sys.stdout)
+ else:
+ logfile = None
try:
bb.process.run(cmd, env=env, cwd=cwd, shell=False, stdin=NULL,
log=logfile)
except bb.process.CmdError:
- raise FuncFailed(function, logfile.name)
+ logfn = d.getVar('BB_LOGFILE', True)
+ raise FuncFailed(function, logfn)
def _task_data(fn, task, d):
localdata = data.createCopy(d)
@@ -308,22 +306,31 @@ def _exec_task(fn, task, d, quieterr):
origstdout = bb.event.useStdout
bb.event.useStdout = True
+ # Ensure python logging goes to the logfile
+ handler = logging.StreamHandler(logfile)
+ handler.setFormatter(logformatter)
+ bblogger.addHandler(handler)
+
+ localdata.setVar('BB_LOGFILE', logfn)
+
event.fire(TaskStarted(task, localdata), localdata)
try:
for func in (prefuncs or '').split():
- exec_func(func, localdata, logfile=logfile)
- exec_func(task, localdata, logfile=logfile)
+ exec_func(func, localdata)
+ exec_func(task, localdata)
for func in (postfuncs or '').split():
- exec_func(func, localdata, logfile=logfile)
+ exec_func(func, localdata)
except FuncFailed as exc:
if not quieterr:
logger.error(str(exc))
- event.fire(TaskFailed(exc.name, exc.logfile, localdata), localdata)
+ event.fire(TaskFailed(exc.name, logfn, localdata), localdata)
return 1
finally:
sys.stdout.flush()
sys.stderr.flush()
+ bblogger.removeHandler(handler)
+
bb.event.useStdout = origstdout
# Restore the backup fds