check-executable.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. # This script finds executable files in the repository, excluding some directories,
  3. # then prints the list of all files which are not in executable-list.txt.
  4. # Returns with error if this list is non-empty.
  5. cd $IDF_PATH
  6. tmp_list=$(mktemp)
  7. out_list=$(mktemp)
  8. # build exclude pattern like '-o -path ./components/component/submodule' for each submodule
  9. submodule_excludes=$(git config --file .gitmodules --get-regexp path | awk '{ print "-o -path ./" $2 }')
  10. # figure out which flag to use when searching for executable files
  11. if [ "$(uname -s)" == "Darwin" ]; then
  12. perm_flag="-perm +111"
  13. else
  14. perm_flag="-executable"
  15. fi
  16. find . -type d \( \
  17. -path ./.git \
  18. -o -name build \
  19. -o -name builds \
  20. $submodule_excludes \
  21. \) -prune -o -type f $perm_flag -print \
  22. | sed "s|^\./||" > $tmp_list
  23. # this looks for lines present in tmp_list but not in executable-list.txt
  24. comm -13 <(cat tools/ci/executable-list.txt | sed -n "/^#/!p" | sort) <(sort $tmp_list) > $out_list
  25. ret=0
  26. if [ -s $out_list ]; then
  27. ret=1
  28. echo "Error: the following file(s) have executable flag set:"
  29. echo ""
  30. cat $out_list
  31. echo ""
  32. echo "If any files need to be executable (usually, scripts), add them to tools/ci/executable-list.txt"
  33. echo "Make the rest of the files non-executable using 'chmod -x <filename>'."
  34. echo "On Windows, use 'git update-index --chmod=-x filename' instead."
  35. echo ""
  36. fi
  37. rm $tmp_list
  38. rm $out_list
  39. exit $ret