check-executable.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env 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. # Also checks if executable-list.txt is sorted and has no duplicates.
  6. set -o errexit # Exit if command failed.
  7. set -o pipefail # Exit if pipe failed.
  8. set -o nounset # Exit if variable not set.
  9. cd $IDF_PATH
  10. in_list=tools/ci/executable-list.txt
  11. tmp_list=$(mktemp)
  12. out_list=$(mktemp)
  13. # build exclude pattern like '-o -path ./components/component/submodule' for each submodule
  14. submodule_excludes=$(git config --file .gitmodules --get-regexp path | awk '{ print "-o -path ./" $2 }')
  15. # figure out which flag to use when searching for executable files
  16. if [ "$(uname -s)" == "Darwin" ]; then
  17. perm_flag="-perm +111"
  18. else
  19. perm_flag="-executable"
  20. fi
  21. find . -type d \( \
  22. -path ./.git \
  23. -o -name build \
  24. -o -name builds \
  25. $submodule_excludes \
  26. \) -prune -o -type f $perm_flag -print \
  27. | sed "s|^\./||" > $tmp_list
  28. # this looks for lines present in tmp_list but not in executable-list.txt
  29. comm -13 <(cat $in_list | sed -n "/^#/!p" | sort) <(sort $tmp_list) > $out_list
  30. ret=0
  31. if [ -s $out_list ]; then
  32. ret=1
  33. echo "Error: the following file(s) have executable flag set:"
  34. echo ""
  35. cat $out_list
  36. echo ""
  37. echo "If any files need to be executable (usually, scripts), add them to tools/ci/executable-list.txt"
  38. echo "Make the rest of the files non-executable using 'chmod -x <filename>'."
  39. echo "On Windows, use 'git update-index --chmod=-x filename' instead."
  40. echo ""
  41. fi
  42. if ! diff <(cat $in_list | sed -n "/^#/!p" | sort | uniq) $in_list; then
  43. echo "$in_list is not sorted or has duplicate entries"
  44. ret=2
  45. fi
  46. for filename in $(cat $in_list | sed -n "/^#/!p"); do
  47. if [ ! -f "$filename" ]; then
  48. echo "Warning: file '$filename' is present in '$in_list', but does not exist"
  49. fi
  50. done
  51. rm $tmp_list
  52. rm $out_list
  53. exit $ret