Fix shellcheck warnings

This commit is contained in:
practicalswift 2018-04-03 22:23:57 +02:00 committed by Christian Decker
parent 5a267eb831
commit b95d3b8f54
3 changed files with 25 additions and 24 deletions

View File

@ -2,11 +2,12 @@
if [ $# -eq 0 ]; then
# With no args, read stdin to scrape compiler output.
set -- $(while read LINE; do
# shellcheck disable=SC2046
set -- $(while read -r LINE; do
case "$LINE" in
*undefined\ reference\ to*)
LINE=${LINE#*undefined reference to \`}
echo ${LINE%\'*}
echo "${LINE%\'*}"
;;
*)
continue
@ -17,7 +18,7 @@ fi
for SYMBOL; do
# If there are multiple declarations, pick first (eg. common/memleak.h
# has notleak_ as a declaration, and then an inline).
WHERE=$(grep -nH "^[a-zA-Z0-9_ (),]* [*]*$SYMBOL(" */*.h | head -n1)
WHERE=$(grep -nH "^[a-zA-Z0-9_ (),]* [*]*$SYMBOL(" ./*/*.h | head -n1)
if [ x"$WHERE" != x ]; then
STUB='\n{ fprintf(stderr, "'$SYMBOL' called!\\n"); abort(); }'
else
@ -29,8 +30,8 @@ for SYMBOL; do
FILE=${WHERE%%:*}
FILE_AND_LINE=${WHERE%:*}
LINE=${FILE_AND_LINE#*:}
END=$(tail -n +$LINE < $FILE | grep -n ';$');
END=$(tail -n "+${LINE}" < "$FILE" | grep -n ';$');
NUM=${END%%:*}
tail -n +$LINE < $FILE | head -n $NUM | sed 's/^extern *//' | sed 's/PRINTF_FMT([^)]*)//' | sed 's/NORETURN//g' | sed 's/,/ UNNEEDED,/g' | sed 's/\([a-z0-9A-Z*_]* [a-z0-9A-Z*_]*\));/\1 UNNEEDED);/' | sed "s/;\$/$STUB/" | sed 's/\s*$//'
tail -n "+${LINE}" < "$FILE" | head -n "$NUM" | sed 's/^extern *//' | sed 's/PRINTF_FMT([^)]*)//' | sed 's/NORETURN//g' | sed 's/,/ UNNEEDED,/g' | sed 's/\([a-z0-9A-Z*_]* [a-z0-9A-Z*_]*\));/\1 UNNEEDED);/' | sed "s/;\$/$STUB/" | sed 's/\s*$//'
done

View File

@ -2,6 +2,6 @@
from=${1}
to=${2}
common=`printf '%s\n%s' "${from}" "${to}" | sed 'N;s/\(.*\).*\n\1.*$/\1/' | sed 's@/[^/]*$@/@'`
prefix=`printf '%s\n' ${from#$common} | sed 's@[^/][^/]*@..@g'`
common=$(printf '%s\n%s' "${from}" "${to}" | sed 'N;s/\(.*\).*\n\1.*$/\1/' | sed 's@/[^/]*$@/@')
prefix=$(printf '%s\n' "${from#$common}" | sed 's@[^/][^/]*@..@g')
printf '%s\n' "$prefix/${to#$common}"

View File

@ -6,34 +6,34 @@
set -e
FILE="$1"
BASE=/tmp/mocktmp.$$.`echo $@ | tr / _`
trap "mv $BASE.old $FILE; rm -f $BASE.*" EXIT
BASE=/tmp/mocktmp.$$.$(echo "$@" | tr / _)
trap 'mv $BASE.old $FILE; rm -f $BASE.*' EXIT
START=`fgrep -n '/* AUTOGENERATED MOCKS START */' $FILE | cut -d: -f1`
END=`fgrep -n '/* AUTOGENERATED MOCKS END */' $FILE | cut -d: -f1`
START=$(fgrep -n '/* AUTOGENERATED MOCKS START */' "$FILE" | cut -d: -f1)
END=$(fgrep -n '/* AUTOGENERATED MOCKS END */' "$FILE" | cut -d: -f1)
if [ -n "$START" ]; then
mv $FILE $BASE.old
echo $FILE:
head -n $START $BASE.old > $FILE
tail -n +$END $BASE.old >> $FILE
mv "$FILE" "${BASE}.old"
echo "${FILE}:"
head -n "$START" "${BASE}.old" > "$FILE"
tail -n +"$END" "${BASE}.old" >> "$FILE"
# Try to make binary.
if ! make `echo $FILE | sed 's/.c$//'` 2> $BASE.err >/dev/null; then
tools/mockup.sh < $BASE.err >> $BASE.stubs
if ! make "${FILE/%.c/}" 2> "${BASE}.err" >/dev/null; then
tools/mockup.sh < "${BASE}.err" >> "${BASE}.stubs"
# If there are no link errors, maybe compile fail for other reason?
if ! fgrep -q 'Generated stub for' $BASE.stubs; then
cat $BASE.err
if ! fgrep -q 'Generated stub for' "${BASE}.stubs"; then
cat "${BASE}.err"
exit 1
fi
sed -n 's,.*Generated stub for \(.*\) .*,\t\1,p' < $BASE.stubs
head -n $START $BASE.old > $FILE
cat $BASE.stubs >> $FILE
tail -n +$END $BASE.old >> $FILE
sed -n 's,.*Generated stub for \(.*\) .*,\t\1,p' < "${BASE}.stubs"
head -n "$START" "${BASE}.old" > "$FILE"
cat "${BASE}.stubs" >> "$FILE"
tail -n +"$END" "${BASE}.old" >> "$FILE"
else
echo "...build succeeded without stubs"
fi
fi
# All good.
rm -f $BASE.*
rm -f "$BASE".*
trap "" EXIT