Skip to content

Commit

Permalink
Fix shellcheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
practicalswift authored and cdecker committed Apr 4, 2018
1 parent 5a267eb commit b95d3b8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
11 changes: 6 additions & 5 deletions tools/mockup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions tools/rel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
34 changes: 17 additions & 17 deletions tools/update-mocks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b95d3b8

Please sign in to comment.