[m-rev.] for review: filter gcc output

Peter Wang novalazy at gmail.com
Mon Jul 12 14:59:14 AEST 2010


On 2010-07-12, Julien Fischer <juliensf at csse.unimelb.edu.au> wrote:
> 
> On Sat, 10 Jul 2010, Julien Fischer wrote:
> >
> >I have committed the following change to this.
> >
> 
> And the following as well.

Found another problem (committed).


Branches: main, 10.04

In mgnuc, use a temporary file to hold gcc error messages before filtering with
mfiltercc, instead trying to do it directly in a pipeline.

The major problem is that the exit status of mgnuc would be that of the second
command in the pipeline (mfiltercc), and not the important command (gcc).
Fixing it without using temporary files requires horrible shell code.

scripts/mgnuc.in:
        As above.  Filtering is disabled if mktemp is not detected at configure
        time.

        Note: the deleted shell command was incorrect as fd 3 was not
        redirected back to standard output, hence if gcc wrote anything to its
        standard output (it doesn't) then it would have been lost.

diff --git a/scripts/mgnuc.in b/scripts/mgnuc.in
index 6b98e0e..3228059 100644
--- a/scripts/mgnuc.in
+++ b/scripts/mgnuc.in
@@ -27,6 +27,8 @@ CFLAGS_FOR_THREADS="@CFLAGS_FOR_THREADS@"
 CFLAGS_FOR_NO_STRICT_ALIASING="@CFLAGS_FOR_NO_STRICT_ALIASING@"
 AS="@AS@"
 BYTES_PER_WORD="@BYTES_PER_WORD@"
+MKTEMP=@MKTEMP@
+TMPDIR=${TMPDIR=/tmp}
 
 case "$CC" in
     *gcc*)
@@ -642,7 +644,7 @@ FILTERCC=""
 case $asm_labels in true)
     # Check if mfiltercc is available as we may be bootstrapping with
     # an older compiler which did not have it.
-    if mfiltercc=`which mfiltercc`
+    if test -n "$MKTEMP" && mfiltercc=`which mfiltercc`
     then
         FILTERCC=$mfiltercc
     fi
@@ -687,18 +689,24 @@ ALL_CC_OPTS="$MERC_ALL_C_INCL_DIRS\
     $FN_ALIGN_OPTS\
     $INVISIBLE_OPTS"
 
-case $verbose in true)
-    echo $CC $ALL_CC_OPTS "$@" $OVERRIDE_OPTS $ALL_LOCAL_C_INCL_DIRS;;
+case $# in
+    0)  set $CC $ALL_CC_OPTS $OVERRIDE_OPTS ;;
+    *)  set $CC $ALL_CC_OPTS "$@" $OVERRIDE_OPTS $ALL_LOCAL_C_INCL_DIRS ;;
 esac
 
-# 3>&- closes fd 3 on both sides of the pipeline
-case $#,$FILTERCC in
-    0,)  exec $CC $ALL_CC_OPTS $OVERRIDE_OPTS ;;
-    0,*) exec 3>&1
-         exec $CC $ALL_CC_OPTS $OVERRIDE_OPTS \
-            2>&1 >&3 3>&- | $FILTERCC >&2 3>&- ;;
-    *,)  exec $CC $ALL_CC_OPTS "$@" $OVERRIDE_OPTS $ALL_LOCAL_C_INCL_DIRS ;;
-    *,*) exec 3>&1
-         exec $CC $ALL_CC_OPTS "$@" $OVERRIDE_OPTS $ALL_LOCAL_C_INCL_DIRS \
-            2>&1 >&3 3>&- | $FILTERCC >&2 3>&- ;;
+case $verbose in true)
+    echo "$@"
 esac
+
+if test -z "$FILTERCC"
+then
+    exec "$@"
+fi
+
+# mktemp should give its own error message.
+tmp=`$MKTEMP $TMPDIR/mgnuc.XXXXXX` || exit 1
+trap 'status=$?; rm -f $tmp; exit $status' 0 1 2 3 13 15
+"$@" 2> $tmp
+status=$?
+"$FILTERCC" < $tmp >&2
+exit $status

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list