Openembedded Bitbake Development
 help / color / mirror / Atom feed
* [PATCH 0/1] build.py: Emit meaningful errors when exiting automatically
@ 2012-10-10 22:11 Peter Seebach
  2012-10-10 22:11 ` [PATCH 1/1] build.py: Provide useful diagnostics when exiting Peter Seebach
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Seebach @ 2012-10-10 22:11 UTC (permalink / raw)
  To: bitbake-devel

The behavior of "set -e" has flaws, the biggest of which is that
the exit is silent. Add an exit handler to run.* scripts so that the
failure will be diagnosed meaningfully.

The following changes since commit 90fd57ee3cb2856c10bda1f5af4879d2b7cf2668:
  Cristiana Voicu (1):
        hob/imageconfigurationpage: a 'hob-image' appears listed in the base image combo box

are available in the git repository at:

  git://git.yoctoproject.org/poky-contrib seebs/errors
  http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=seebs/errors

Peter Seebach (1):
  build.py: Provide useful diagnostics when exiting.

 lib/bb/build.py |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)




^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 1/1] build.py: Provide useful diagnostics when exiting.
  2012-10-10 22:11 [PATCH 0/1] build.py: Emit meaningful errors when exiting automatically Peter Seebach
@ 2012-10-10 22:11 ` Peter Seebach
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Seebach @ 2012-10-10 22:11 UTC (permalink / raw)
  To: bitbake-devel

Running scripts with 'set -e' produces silent failures with no
diagnostic. Add an exit handler which produces diagnostics, including
details of what was running if the shell seems to be bash.

Signed-off-by: Peter Seebach <peter.seebach@windriver.com>
---
 lib/bb/build.py |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/lib/bb/build.py b/lib/bb/build.py
index 85af42c..f65c415 100644
--- a/lib/bb/build.py
+++ b/lib/bb/build.py
@@ -249,7 +249,23 @@ def exec_func_shell(func, d, runfile, cwd=None):
     d.delVarFlag('PWD', 'export')
 
     with open(runfile, 'w') as script:
-        script.write('#!/bin/sh -e\n')
+        script.write('''#!/bin/sh\n
+# Emit a useful diagnostic if something fails:
+bb_exit_handler() {
+    ret=$?
+    case $ret in
+    0)  ;;
+    *)  case $BASH_VERSION in
+        "")   echo "WARNING: exit code $ret from a shell command.";;
+        *)    echo "WARNING: ${BASH_SOURCE[0]}:${BASH_LINENO[0]} exit $ret from
+  \"$BASH_COMMAND\"";;
+        esac
+        exit $ret
+    esac
+}
+trap 'bb_exit_handler' 0
+set -e
+''')
         data.emit_func(func, script, d)
 
         if bb.msg.loggerVerboseLogs:
@@ -257,6 +273,12 @@ def exec_func_shell(func, d, runfile, cwd=None):
         if cwd:
             script.write("cd %s\n" % cwd)
         script.write("%s\n" % func)
+        script.write('''
+# cleanup
+ret=$?
+trap '' 0
+exit $?
+''')
 
     os.chmod(runfile, 0775)
 
-- 
1.7.0.4




^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-10-10 22:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-10 22:11 [PATCH 0/1] build.py: Emit meaningful errors when exiting automatically Peter Seebach
2012-10-10 22:11 ` [PATCH 1/1] build.py: Provide useful diagnostics when exiting Peter Seebach

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox