From a640318bda7e94278434bafba75d39052ef217ab Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 24 Dec 2014 17:21:35 +0900 Subject: [PATCH] misc-sanity-checks.sh: Some cleanups Some cleanups for commit 4fdda65a5b9f379af997e1e971865ccfa7a93156. - Don't assume the path of mktemp command. It's /usr/bin/mktemp for some platforms. eg. NetBSD. Also, always provide a template as it's necessary for some platforms, eg. OS X. This snippet was taken from the example in NetBSD's mktemp(1). - Move a comment to the appropriate place. - Improve a regex to ignore more comments. - As the pattern for find -path is not a regex, no escape is necessary for period. Closes-Bug: #1405584 Change-Id: Ia8358f0f7ebe9bc445ce5aa3c4f340546f37db05 --- tools/misc-sanity-checks.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tools/misc-sanity-checks.sh b/tools/misc-sanity-checks.sh index 49991457b..8085b9c19 100644 --- a/tools/misc-sanity-checks.sh +++ b/tools/misc-sanity-checks.sh @@ -16,21 +16,23 @@ # License for the specific language governing permissions and limitations # under the License. -# The purpose of this script is to avoid casual introduction of more -# bash dependency. Please consider alternatives before commiting code -# which uses bash specific features. - -export TMPDIR=`/bin/mktemp -d` +TMPDIR=`mktemp -d /tmp/${0##*/}.XXXXXX` || exit 1 +export TMPDIR trap "rm -rf $TMPDIR" EXIT FAILURES=$TMPDIR/failures check_opinionated_shell () { + # The purpose of this function is to avoid casual introduction of more + # bash dependency. Please consider alternatives before commiting code + # which uses bash specific features. + # Check that shell scripts are not bash opinionated (ignore comments though) # If you cannot avoid the use of bash, please change the EXPECTED var below. - OBSERVED=$(grep -E '^([^#]|#!).*bash' tox.ini tools/* | wc -l) - EXPECTED=5 + OBSERVED=$(grep -E '^([[:space:]]*[^#[:space:]]|#!).*bash' \ + tox.ini tools/* | wc -l) + EXPECTED=3 if [ ${EXPECTED} -ne ${OBSERVED} ]; then echo "Bash usage has been detected!" >>$FAILURES fi @@ -40,7 +42,7 @@ check_opinionated_shell () { check_no_symlinks_allowed () { # Symlinks break the package build process, so ensure that they # do not slip in, except hidden symlinks. - if [ $(find . -type l ! -path '*/\.*' | wc -l) -ge 1 ]; then + if [ $(find . -type l ! -path '*/.*' | wc -l) -ge 1 ]; then echo "Symlinks are not allowed!" >>$FAILURES fi } -- 2.45.2