summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/build.py31
-rw-r--r--bitbake/lib/bb/progress.py16
2 files changed, 42 insertions, 5 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py
index a0a764a7cb..85ad8ea689 100644
--- a/bitbake/lib/bb/build.py
+++ b/bitbake/lib/bb/build.py
@@ -163,12 +163,35 @@ class LogTee(object):
163 163
164 def __repr__(self): 164 def __repr__(self):
165 return '<LogTee {0}>'.format(self.name) 165 return '<LogTee {0}>'.format(self.name)
166
166 def flush(self): 167 def flush(self):
167 self.outfile.flush() 168 self.outfile.flush()
168 169
170
171class StdoutNoopContextManager:
172 """
173 This class acts like sys.stdout, but adds noop __enter__ and __exit__ methods.
174 """
175 def __enter__(self):
176 return sys.stdout
177
178 def __exit__(self, *exc_info):
179 pass
180
181 def write(self, string):
182 return sys.stdout.write(string)
183
184 def flush(self):
185 sys.stdout.flush()
186
187 @property
188 def name(self):
189 return sys.stdout.name
190
191
169# 192#
170# pythonexception allows the python exceptions generated to be raised 193# pythonexception allows the python exceptions generated to be raised
171# as the real exceptions (not FuncFailed) and without a backtrace at the 194# as the real exceptions (not FuncFailed) and without a backtrace at the
172# origin of the failure. 195# origin of the failure.
173# 196#
174def exec_func(func, d, dirs = None, pythonexception=False): 197def exec_func(func, d, dirs = None, pythonexception=False):
@@ -375,9 +398,9 @@ exit $ret
375 cmd = [fakerootcmd, runfile] 398 cmd = [fakerootcmd, runfile]
376 399
377 if bb.msg.loggerDefaultVerbose: 400 if bb.msg.loggerDefaultVerbose:
378 logfile = LogTee(logger, sys.stdout) 401 logfile = LogTee(logger, StdoutNoopContextManager())
379 else: 402 else:
380 logfile = sys.stdout 403 logfile = StdoutNoopContextManager()
381 404
382 progress = d.getVarFlag(func, 'progress') 405 progress = d.getVarFlag(func, 'progress')
383 if progress: 406 if progress:
@@ -433,7 +456,7 @@ exit $ret
433 bb.debug(2, "Executing shell function %s" % func) 456 bb.debug(2, "Executing shell function %s" % func)
434 457
435 try: 458 try:
436 with open(os.devnull, 'r+') as stdin: 459 with open(os.devnull, 'r+') as stdin, logfile:
437 bb.process.run(cmd, shell=False, stdin=stdin, log=logfile, extrafiles=[(fifo,readfifo)]) 460 bb.process.run(cmd, shell=False, stdin=stdin, log=logfile, extrafiles=[(fifo,readfifo)])
438 except bb.process.CmdError: 461 except bb.process.CmdError:
439 logfn = d.getVar('BB_LOGFILE') 462 logfn = d.getVar('BB_LOGFILE')
diff --git a/bitbake/lib/bb/progress.py b/bitbake/lib/bb/progress.py
index e9b72e28b9..4022caa717 100644
--- a/bitbake/lib/bb/progress.py
+++ b/bitbake/lib/bb/progress.py
@@ -13,6 +13,7 @@ import time
13import inspect 13import inspect
14import bb.event 14import bb.event
15import bb.build 15import bb.build
16from bb.build import StdoutNoopContextManager
16 17
17class ProgressHandler(object): 18class ProgressHandler(object):
18 """ 19 """
@@ -27,7 +28,14 @@ class ProgressHandler(object):
27 if outfile: 28 if outfile:
28 self._outfile = outfile 29 self._outfile = outfile
29 else: 30 else:
30 self._outfile = sys.stdout 31 self._outfile = StdoutNoopContextManager()
32
33 def __enter__(self):
34 self._outfile.__enter__()
35 return self
36
37 def __exit__(self, *excinfo):
38 self._outfile.__exit__(*excinfo)
31 39
32 def _fire_progress(self, taskprogress, rate=None): 40 def _fire_progress(self, taskprogress, rate=None):
33 """Internal function to fire the progress event""" 41 """Internal function to fire the progress event"""
@@ -147,6 +155,12 @@ class MultiStageProgressReporter(object):
147 self._stage_total = None 155 self._stage_total = None
148 self._callers = [] 156 self._callers = []
149 157
158 def __enter__(self):
159 return self
160
161 def __exit__(self, *excinfo):
162 pass
163
150 def _fire_progress(self, taskprogress): 164 def _fire_progress(self, taskprogress):
151 bb.event.fire(bb.build.TaskProgress(taskprogress), self._data) 165 bb.event.fire(bb.build.TaskProgress(taskprogress), self._data)
152 166