Make the build wrapper less fragile

This script was failing for certain paths (dots, whitespace), and using
sed to replace parts of the command line was overkill. Do less mangling,
and quote command line args.

Fixes 01org/hyperscan#51
This commit is contained in:
Matthew Barr 2017-04-18 11:48:17 +10:00
parent d809e73d45
commit 0626a30a6a

View File

@ -8,21 +8,18 @@ cleanup () {
PREFIX=$1 PREFIX=$1
KEEPSYMS_IN=$2 KEEPSYMS_IN=$2
shift 2 shift 2
BUILD=$@ # $@ contains the actual build command
OUT=$(echo $BUILD | sed 's/.* -o \(.*\.o\).*/\1/') OUT=$(echo "$@" | sed 's/.* -o \(.*\.o\).*/\1/')
trap cleanup INT QUIT EXIT trap cleanup INT QUIT EXIT
SYMSFILE=$(mktemp --tmpdir ${PREFIX}_rename.syms.XXXXX) SYMSFILE=$(mktemp --tmpdir ${PREFIX}_rename.syms.XXXXX)
KEEPSYMS=$(mktemp --tmpdir keep.syms.XXXXX) KEEPSYMS=$(mktemp --tmpdir keep.syms.XXXXX)
# grab the command without the target obj or src file flags # find the libc used by gcc
# we don't just call gcc directly as there may be flags modifying the arch LIBC_SO=$("$@" --print-file-name=libc.so.6)
CC_CMD=$(echo $BUILD | sed 's/ -o .*\.o//;s/ -c //;s/ .[^ ]*\.c//;')
# find me a libc
LIBC_SO=$(${CC_CMD} --print-file-name=libc.so.6)
cp ${KEEPSYMS_IN} ${KEEPSYMS} cp ${KEEPSYMS_IN} ${KEEPSYMS}
# get all symbols from libc and turn them into patterns # get all symbols from libc and turn them into patterns
nm -f p -g -D ${LIBC_SO} | sed -s 's/\([^ ]*\).*/^\1$/' >> ${KEEPSYMS} nm -f p -g -D ${LIBC_SO} | sed -s 's/\([^ ]*\).*/^\1$/' >> ${KEEPSYMS}
# build the object # build the object
${BUILD} "$@"
# rename the symbols in the object # rename the symbols in the object
nm -f p -g ${OUT} | cut -f1 -d' ' | grep -v -f ${KEEPSYMS} | sed -e "s/\(.*\)/\1\ ${PREFIX}_\1/" >> ${SYMSFILE} nm -f p -g ${OUT} | cut -f1 -d' ' | grep -v -f ${KEEPSYMS} | sed -e "s/\(.*\)/\1\ ${PREFIX}_\1/" >> ${SYMSFILE}
if test -s ${SYMSFILE} if test -s ${SYMSFILE}