On Wednesday 26 September 2007, Donnie Berkholz wrote:
> On 17:53 Wed 26 Sep     , Doug Goldstein wrote:
> > Mike Frysinger wrote:
> > > Donnie Berkholz wrote:
> > > also, ebuilds do change over time, so what line # may be correct one
> > > day may not be relevant the next ...
> >
> > True. I will concede this point. I could attempt to argue this is why
> > it's important to know the version and revision of the package you are
> > emerging. But the counter point is evident, times when the ebuild is
> > changed without a bump pose a problem.
> >
> > Which could bring up a point of would it be useful to see if we can
> > print out the actual line that caused the die. Now, I don't know if this
> > feasible or something the Portage devs want to do. But again, in the
> > effort to streamline this might be something to consider.
>
> The backtrace code is in ebuild.sh:dump_trace(). If you can find a way
> in bash to print the source line, that would be great. I took another
> glance through the bash man page and didn't see much from that end. But
> since we do have the source file and line number, we could just grab it
> with some hack like:
>
> sed -ne "${lineno}p" ${filename}
>
> Anyone got something better?

how about this:
+       eerror "The specific snippet of code:"
+       # This scans the file that called die and prints out the logic that
+       # ended in the call to die.  This really only handles lines that end
+       # with '|| die' and any preceding lines with line continuations (\).
+       # This tends to be the most common usage though, so let's do it.
+       # Due to the usage of appending to the hold space (even when empty),
+       # we always end up with the first line being a blank (thus the 2nd sed).
+       sed -n \
+               -e "# When we get to the line that failed, append it to the
+                   # hold space, move the hold space to the pattern space,
+                   # then print out the pattern space and quit immediately
+                   ${BASH_LINENO[0]}{H;g;p;q}" \
+               -e '# If this line ends with a line continuation, append it
+                   # to the hold space
+                   /\\$/H' \
+               -e '# If this line does not end with a line continuation,
+                   # erase the line and set the hold buffer to it (thus
+                   # erasing the hold buffer in the process)
+                   /[^\]$/{s:^.*$::;h}' \
+               ${BASH_SOURCE[1]} \
+               | sed -e '1d' \
+               | (OFS=${IFS} IFS=$'\n'; while read -r n ; do (IFS=${OFS}; 
eerror "  
${n}") ; done)
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to