[general] bash script to filter compiler output
Hi all Postings here often comment on the amount of compiler output generated when using Boost libraries. I found the following script quite useful when trying to track down both bad practice and real errors in my own code. It works something like this: $ callfilter -6 make This script filters the compiler output based on the options -0 thru -7. Option -- has no effect and is provided for typing convenience. Options -5 and -6 are typically the most useful. Some comments at the start of the script provide more information. I find g++ -Weffc++ often rather helpful, but its use definitely requires some form of output screening. Here is the usage message for this script: usage: callfilter [-01234567] <call> modified call with output filtering callfilter -- <call> straight call (provided for convenience) callfilter --help|-h display usage message and quit purpose: append selected filters to build calls to suppress Boost library output additive: 0 2>&1 1 | grep -v 'boost::' | grep -v 'std::tr1::' 2 | grep -v '/include/boost-1_34_1/' | grep -v '/include/c++/4.1.2/tr1/' 4 | grep -v 'instantiated from' examples: $ callfilter -- make $ callfilter -7 g++ -Wall -Weffc++ usingboost.cc -o usingboost If anyone has improvements, let me know. I will endeavor to incorporate these and then repost in a couple of weeks. cheers Robbie Morrison --- [from IMAP client] #! /bin/bash # Copyright: (c) 2007 Robbie Morrison. All rights reserved. # License: Unrestricted reuse in any form, for any purpose. # Version: $Id: callfilter,v 1.7 2007/10/19 11:26:41 robbie Exp $ # Purpose: take a command-line build call and append some # selected 'grep' filters to reduce the amount of output # displayed. A build call could be just 'make' or perhaps # g++ with a string of arguments. The individual filters # are intended to suppress the screenfulls of warnings # generated by Boost library headers, while leaving the # compiler messages that relate more directly to your code. # The ability to mix different combinations of filters is # often useful. The UNIX 'grep' utility does the filtering # and -v is the 'invert-match' option. This script can be # particularly valuable in combination with the '-Weffc++' # option for g++. In fact, the script was developed # because of a comment suggesting such an approach on the # g++ manpage. # # See also: for a more sophisticated approach, # refer to: http://www.bdsoft.com/tools/stlfilt.html # define some suitable filters -- please modify to suit your needs FILTER_0="2>&1" # useful when capturing output FILTER_1="| grep -v 'boost::' | grep -v 'std::tr1::'" FILTER_2="| grep -v '/include/boost-1_34_1/' | grep -v '/include/c++/4.1.2/tr1/'" FILTER_4="| grep -v 'instantiated from'" # preamble SCRIPT=$(basename "$0") # for console reporting # script exit codes E_SUCCESS=0 E_USAGE=2 E_NO_GREP=3 # functions function display_help # using simple echo statements { echo echo " usage: $SCRIPT [-01234567] <call> modified call with output filtering" echo " $SCRIPT -- <call> straight call (provided for convenience)" echo " $SCRIPT --help|-h display usage message and quit" echo " purpose: append selected filters to build calls to suppress Boost library output" echo " additive: 0 $FILTER_0" echo " 1 $FILTER_1" echo " 2 $FILTER_2" echo " 4 $FILTER_4" echo " examples: \$ $SCRIPT -- make" echo " \$ $SCRIPT -7 g++ -Wall -Weffc++ usingboost.cc -o usingboost" echo } function make_filter # with conventional rather than bitwise arithmetic { local base=4 # option range is from 0 to (2 ** base - 1) local num=${opt#-} # strip leading - while [ $base -gt 0 ] do if [ $num -ge $base ] then let "num = num % base" # remainder operator case "$base" in 1) filter="$FILTER_1 $filter" ;; 2) filter="$FILTER_2 $filter" ;; 4) filter="$FILTER_4 $filter" ;; esac fi let "base = base / 2" # divide by two done filter="$FILTER_0 $filter" } # process our part of the command-line case "$1" in --help|--hel|--he|--h|-help|-hel|-he|-h|-\?) display_help exit $E_SUCCESS ;; -[0-7]) opt="$1" shift make_filter ;; --) shift ;; "") echo "$SCRIPT: try --help for usage" exit $E_USAGE ;; esac # confirm that grep is present on the system if [ ! $(which grep) ] then echo "$SCRIPT: required utility not found: grep" echo "$SCRIPT: unable to continue" exit $E_NO_GREP fi # active code echo "$SCRIPT: call : $*" echo "$SCRIPT: filter : $filter" eval "$* $filter" # actual call # housekeeping exit $E_SUCCESS # end of file
on Fri Oct 19 2007, Robbie Morrison
If anyone has improvements, let me know. I will endeavor to incorporate these and then repost in a couple of weeks.
See http://www.bdsoft.com/tools/stlfilt.html -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
participants (2)
-
David Abrahams
-
Robbie Morrison