misc-sanity-checks.sh: Some cleanups

Some cleanups for commit 4fdda65a5b.

- 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
This commit is contained in:
YAMAMOTO Takashi 2014-12-24 17:21:35 +09:00
parent 2c94b10d74
commit a640318bda

View File

@ -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
}