diff options
Diffstat (limited to 'bitbake/lib/bb/build.py')
-rw-r--r-- | bitbake/lib/bb/build.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py index 5a1727116a..44d08f5c55 100644 --- a/bitbake/lib/bb/build.py +++ b/bitbake/lib/bb/build.py | |||
@@ -25,6 +25,7 @@ import bb | |||
25 | import bb.msg | 25 | import bb.msg |
26 | import bb.process | 26 | import bb.process |
27 | import bb.progress | 27 | import bb.progress |
28 | from io import StringIO | ||
28 | from bb import data, event, utils | 29 | from bb import data, event, utils |
29 | 30 | ||
30 | bblogger = logging.getLogger('BitBake') | 31 | bblogger = logging.getLogger('BitBake') |
@@ -177,7 +178,9 @@ class StdoutNoopContextManager: | |||
177 | 178 | ||
178 | @property | 179 | @property |
179 | def name(self): | 180 | def name(self): |
180 | return sys.stdout.name | 181 | if "name" in dir(sys.stdout): |
182 | return sys.stdout.name | ||
183 | return "<mem>" | ||
181 | 184 | ||
182 | 185 | ||
183 | def exec_func(func, d, dirs = None): | 186 | def exec_func(func, d, dirs = None): |
@@ -296,9 +299,21 @@ def exec_func_python(func, d, runfile, cwd=None): | |||
296 | lineno = int(d.getVarFlag(func, "lineno", False)) | 299 | lineno = int(d.getVarFlag(func, "lineno", False)) |
297 | bb.methodpool.insert_method(func, text, fn, lineno - 1) | 300 | bb.methodpool.insert_method(func, text, fn, lineno - 1) |
298 | 301 | ||
302 | if verboseStdoutLogging: | ||
303 | sys.stdout.flush() | ||
304 | sys.stderr.flush() | ||
305 | currout = sys.stdout | ||
306 | currerr = sys.stderr | ||
307 | sys.stderr = sys.stdout = execio = StringIO() | ||
299 | comp = utils.better_compile(code, func, "exec_func_python() autogenerated") | 308 | comp = utils.better_compile(code, func, "exec_func_python() autogenerated") |
300 | utils.better_exec(comp, {"d": d}, code, "exec_func_python() autogenerated") | 309 | utils.better_exec(comp, {"d": d}, code, "exec_func_python() autogenerated") |
301 | finally: | 310 | finally: |
311 | if verboseStdoutLogging: | ||
312 | execio.flush() | ||
313 | logger.plain("%s" % execio.getvalue()) | ||
314 | sys.stdout = currout | ||
315 | sys.stderr = currerr | ||
316 | execio.close() | ||
302 | # We want any stdout/stderr to be printed before any other log messages to make debugging | 317 | # We want any stdout/stderr to be printed before any other log messages to make debugging |
303 | # more accurate. In some cases we seem to lose stdout/stderr entirely in logging tests without this. | 318 | # more accurate. In some cases we seem to lose stdout/stderr entirely in logging tests without this. |
304 | sys.stdout.flush() | 319 | sys.stdout.flush() |
@@ -441,7 +456,11 @@ exit $ret | |||
441 | if fakerootcmd: | 456 | if fakerootcmd: |
442 | cmd = [fakerootcmd, runfile] | 457 | cmd = [fakerootcmd, runfile] |
443 | 458 | ||
444 | if verboseStdoutLogging: | 459 | # We only want to output to logger via LogTee if stdout is sys.__stdout__ (which will either |
460 | # be real stdout or subprocess PIPE or similar). In other cases we are being run "recursively", | ||
461 | # ie. inside another function, in which case stdout is already being captured so we don't | ||
462 | # want to Tee here as output would be printed twice, and out of order. | ||
463 | if verboseStdoutLogging and sys.stdout == sys.__stdout__: | ||
445 | logfile = LogTee(logger, StdoutNoopContextManager()) | 464 | logfile = LogTee(logger, StdoutNoopContextManager()) |
446 | else: | 465 | else: |
447 | logfile = StdoutNoopContextManager() | 466 | logfile = StdoutNoopContextManager() |