From ed2ec2537f0851a4e57dddca480394aba2384a46 Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Thu, 7 Mar 2019 11:58:44 +0000 Subject: [PATCH] Ensure that files marked executable are #! scripts --- tools/check-typo | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tools/check-typo b/tools/check-typo index 5c411dfaf..6da3c3e6b 100755 --- a/tools/check-typo +++ b/tools/check-typo @@ -130,6 +130,25 @@ usage () { exit 2 } +check_script () { + if [ "$($OCAML_CT_CAT "$OCAML_CT_PREFIX$1" \ + | sed -ne '1s/^#!.*/#!/p')" != '#!' ] ; then + # These files are listed manually, rather than via gitattributes, + # because the list should never expand, and it should not be trivial to + # expand (the unix-execvpe test is an ultra-special-case!) + f=${1#./} + if [ "$f" != "boot/ocamlc" ] && [ "$f" != "boot/ocamllex" ] && \ + [ "$f" != "testsuite/tests/lib-unix/unix-execvpe/subdir/script2" ] ; then + echo "$1 shouldn't be executable; either:" + echo " - Add a #! line" + echo " - Run chmod -x $1 (on Unix)" + echo " - Run git update-index --chmod=-x $1 (on Windows)" + echo "You may wish to check your core.fileMode setting" + EXIT_CODE=1 + fi + fi +} + userrules='' while : ; do @@ -180,6 +199,15 @@ EXIT_CODE=0 *$f*) is_cmd_line=true;; *) is_cmd_line=false;; esac + if [ -z "$OCAML_CT_PREFIX" ] ; then + if [ -x "$f" ] ; then + check_script "$f" + fi + else + if git ls-files -s "$f" | grep -q "^100755" ; then + check_script "$f" + fi + fi if $path_in_index || $is_cmd_line; then :; else continue; fi attr_rules='' if $path_in_index; then