diff mbox

[RFC] ct-ng build debugging

Message ID 20120928163547.GB17447@sig21.net
State Superseded
Headers show

Commit Message

Johannes Stezenbach Sept. 28, 2012, 4:35 p.m. UTC
Hi,

I hacked up the patch below which drops into a shell prompt
when the ct-ng build breaks, with the environment properly set up.
It allows one to check what went wrong and possibly hot-fix it.
Of course a real patch should use a developer config option, but I'm
out of time atm and can't finish it.  If you find it
useful it would be nice if someone could pick it up
and polish it for inclusion.

(The "backtrace" change at the top is actually a seperate
bugfix for when things go wrong early in crosstool-NG.sh
before CT_BUILD_DIR is set.)

Signed-off-by: Johannes Stezenbach <js@sig21.net>

PS: I'm not good at writing bash scripts, maybe there's
a better way to do it.  It's also not much tested but
it worked for re-running make and changing the gcc command
to look at the cpp output from the glibc breakage I just reported.



--
For unsubscribe information see http://sourceware.org/lists.html#faq

Comments

Yann E. MORIN Oct. 2, 2012, 9:17 p.m. UTC | #1
Johannes, All,

On Friday 28 September 2012 18:35:47 Johannes Stezenbach wrote:
> I hacked up the patch below which drops into a shell prompt
> when the ct-ng build breaks, with the environment properly set up.
> It allows one to check what went wrong and possibly hot-fix it.
> Of course a real patch should use a developer config option, but I'm
> out of time atm and can't finish it.  If you find it
> useful it would be nice if someone could pick it up
> and polish it for inclusion.

That a very interesting feature. Getting a shell with the current
environment already set is a pretty neat idea.

I've just skimmed over the patch, and basically I like the exit trick.
I think this behavior should be conditional, and the build should abort
by default, unless the user explicitly asked for the new behavior.

Also, we should use ${bash} to call the shell, because some folks may use
a specific bash (eg. the *BSD guys).

I'll give it a spin shortly, and see how we can adapt your patch.

> (The "backtrace" change at the top is actually a seperate
> bugfix for when things go wrong early in crosstool-NG.sh
> before CT_BUILD_DIR is set.)

Yep, that sounds reasonable, too, but that should be a separate patch.
Do you want to re-submit just that one, please?

> Signed-off-by: Johannes Stezenbach <js@sig21.net>
> 
> PS: I'm not good at writing bash scripts, maybe there's
> a better way to do it.

Well, basically, it's good.

Thank you.

Regards,
Yann E. MORIN.
diff mbox

Patch

diff -r 43ace4bb005e scripts/functions
--- a/scripts/functions	Wed Sep 26 16:37:31 2012 +0200
+++ b/scripts/functions	Fri Sep 28 18:15:49 2012 +0200
@@ -11,8 +11,8 @@ 
 
     # To avoid printing the backtace for each sub-shell
     # up to the top-level, just remember we've dumped it
-    if [ ! -f "${CT_BUILD_DIR}/backtrace" ]; then
-        touch "${CT_BUILD_DIR}/backtrace"
+    if [ ! -f "${CT_WORK_DIR}/backtrace" ]; then
+        touch "${CT_WORK_DIR}/backtrace"
 
         # Print steps backtrace
         step_depth=${CT_STEP_COUNT}
@@ -50,7 +50,7 @@ 
 
         CT_DoLog ERROR ""
         CT_DoEnd ERROR
-        rm -f "${CT_BUILD_DIR}/backtrace"
+        rm -f "${CT_WORK_DIR}/backtrace"
     fi
     exit $ret
 }
@@ -157,6 +157,7 @@ 
 # Usage: CT_DoExecLog <level> [VAR=val...] <command> [parameters...]
 CT_DoExecLog() {
     local level="$1"
+    local result
     shift
     (
     for i in "$@"; do
@@ -168,8 +169,41 @@ 
             *)      break;;
         esac
     done
-    CT_DoLog DEBUG "==> Executing: ${tmp_log}"
-    "${@}" 2>&1 |CT_DoLog "${level}"
+    trap ERR
+    while true; do
+        CT_DoLog DEBUG "==> Executing: ${tmp_log}"
+        "${@}" 2>&1 |CT_DoLog "${level}"
+        result=$?
+        if [ $result -eq 0 ]; then
+            break
+        fi
+        (
+            exec >&6
+            echo "command error $result:"
+            echo "$@"
+            echo "please fix it up and finish by exiting the shell"
+            while true; do
+                bash --rcfile <(echo "PS1='ct-ng:\w> '") -i
+                result=$?
+                case $result in
+                    1)  result=0; break;;
+                    2)  break;;
+                    3)  break;;
+                    *)  echo "please exit with one of these values:"
+                        echo "1  fixed, continue with next build command"
+                        echo "2  repeat this build command"
+                        echo "3  abort build"
+                        ;;
+                esac
+            done
+            exit $result
+        )
+        result=$?
+        if [ $result -ne 2 ]; then
+            break
+        fi
+    done
+    exit $result
     )
     # Catch failure of the sub-shell
     [ $? -eq 0 ]