]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
misc-sanity-checks.sh: Some cleanups
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>
Wed, 24 Dec 2014 08:21:35 +0000 (17:21 +0900)
committerYAMAMOTO Takashi <yamamoto@valinux.co.jp>
Wed, 14 Jan 2015 03:52:06 +0000 (12:52 +0900)
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

index 49991457b7b88348fc8f4cc643b027311b73e305..8085b9c19d95d2cdb87ceaed0d7bab2a1e609d71 100644 (file)
 #    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
 }