summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/build.py
diff options
context:
space:
mode:
authorChris Laplante <chris.laplante@agilent.com>2019-06-07 14:24:03 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-06-11 13:27:19 +0100
commit768746959089f8fa0e6e73f3917abebfae22d652 (patch)
tree725e6adda21da39972116010f8a4e4fe0dc3cc39 /bitbake/lib/bb/build.py
parent575ea5532f80883f8ee20dd1e78f699e8dccafc5 (diff)
downloadpoky-768746959089f8fa0e6e73f3917abebfae22d652.tar.gz
bitbake: build/progress: use context managers for progress handlers
It seems context management support was half-implemented, but never finished. For example, LogTee has __enter__ and __exit__ but they haven't been exercised until now. (Bitbake rev: bf522ad3e0c52cdb69b406226840d870ff4f2766) Signed-off-by: Chris Laplante <chris.laplante@agilent.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/build.py')
-rw-r--r--bitbake/lib/bb/build.py31
1 files changed, 27 insertions, 4 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')