From 616e75523b0b1bbe730631dba70224b55cfaaa57 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Fri, 20 Aug 2010 12:25:19 +0100 Subject: bitbake: Correctly route events from the worker to the server Signed-off-by: Richard Purdie --- bitbake/bin/bitbake-runtask | 17 ++++++++++++----- bitbake/lib/bb/build.py | 8 +++++++- bitbake/lib/bb/event.py | 1 + bitbake/lib/bb/msg.py | 4 +++- bitbake/lib/bb/runqueue.py | 2 +- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/bitbake/bin/bitbake-runtask b/bitbake/bin/bitbake-runtask index 417f3949c..dee25cdf2 100755 --- a/bitbake/bin/bitbake-runtask +++ b/bitbake/bin/bitbake-runtask @@ -31,19 +31,26 @@ warnings.simplefilter("ignore", DeprecationWarning) import bb.event -# Need to map our I/O correctly. Currently stdout is a pipe to -# the server expecting events. We save this and map stdout to stderr. +# Need to map our I/O correctly. stdout is a pipe to the server expecting +# events. We save this and then map stdout to stderr. eventfd = os.dup(sys.stdout.fileno()) bb.event.worker_pipe = os.fdopen(eventfd, 'w', 0) -# Replace those fds with our own + +# map stdout to stderr os.dup2(sys.stderr.fileno(), sys.stdout.fileno()) +# Replace those fds with our own +#logout = data.expand("${TMPDIR}/log/stdout.%s" % os.getpid(), self.cfgData, True) +#mkdirhier(os.path.dirname(logout)) +#newso = open("/tmp/stdout.%s" % os.getpid(), 'w') +#os.dup2(newso.fileno(), sys.stdout.fileno()) +#os.dup2(newso.fileno(), sys.stderr.fileno()) + # Save out the PID so that the event can include it the # events bb.event.worker_pid = os.getpid() -bb.event.usestdout = False - +bb.event.useStdout = False import bb.cooker diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py index 77af92abe..f49b2836b 100644 --- a/bitbake/lib/bb/build.py +++ b/bitbake/lib/bb/build.py @@ -152,6 +152,9 @@ def exec_func(func, d, dirs = None): os.dup2(so.fileno(), oso[1]) os.dup2(se.fileno(), ose[1]) + # Since we've remapped stdout and stderr, its safe for log messages to be printed there now + # exec_func can nest so we have to save state + origstdout = bb.event.useStdout bb.event.useStdout = True locks = [] @@ -179,7 +182,10 @@ def exec_func(func, d, dirs = None): for lock in locks: bb.utils.unlockfile(lock) - bb.event.useStdout = False + sys.stdout.flush() + sys.stderr.flush() + + bb.event.useStdout = origstdout # Restore the backup fds os.dup2(osi[0], osi[1]) diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py index f5ba6eab3..45458c2d6 100644 --- a/bitbake/lib/bb/event.py +++ b/bitbake/lib/bb/event.py @@ -110,6 +110,7 @@ def fire_from_worker(event, d): if not event.startswith("") or not event.endswith(""): print("Error, not an event %s" % event) return + #print "Got event %s" % event event = pickle.loads(event[7:-8]) fire_ui_handlers(event, d) diff --git a/bitbake/lib/bb/msg.py b/bitbake/lib/bb/msg.py index 5bb30e8dd..21692d930 100644 --- a/bitbake/lib/bb/msg.py +++ b/bitbake/lib/bb/msg.py @@ -133,7 +133,9 @@ def error(msgdomain, msg, fn = None): def fatal(msgdomain, msg, fn = None): bb.event.fire(MsgFatal(msg), None) - print('FATAL: %s' % (msg)) + + if bb.event.useStdout: + print('FATAL: %s' % (msg)) sys.exit(1) def plain(msg, fn = None): diff --git a/bitbake/lib/bb/runqueue.py b/bitbake/lib/bb/runqueue.py index 67f265bc8..ef5256f14 100644 --- a/bitbake/lib/bb/runqueue.py +++ b/bitbake/lib/bb/runqueue.py @@ -1467,5 +1467,5 @@ class runQueuePipe(): while self.read(): continue if len(self.queue) > 0: - print("Warning, worker left partial message") + print("Warning, worker left partial message: %s" % self.queue) self.fd.close() -- cgit v1.2.3