From b95d3b8f5420596e4e52e4dbf94ddb4aa64b6c65 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Tue, 3 Apr 2018 22:23:57 +0200 Subject: [PATCH] Fix shellcheck warnings --- tools/mockup.sh | 11 ++++++----- tools/rel.sh | 4 ++-- tools/update-mocks.sh | 34 +++++++++++++++++----------------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/tools/mockup.sh b/tools/mockup.sh index 9a9a49f26..0acd84fa8 100755 --- a/tools/mockup.sh +++ b/tools/mockup.sh @@ -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 diff --git a/tools/rel.sh b/tools/rel.sh index 466b1f485..3f85f6648 100755 --- a/tools/rel.sh +++ b/tools/rel.sh @@ -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}" diff --git a/tools/update-mocks.sh b/tools/update-mocks.sh index 4802f9147..b9200b779 100755 --- a/tools/update-mocks.sh +++ b/tools/update-mocks.sh @@ -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