check-names.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/sh
  2. #
  3. # This file is part of mbed TLS (https://tls.mbed.org)
  4. #
  5. # Copyright (c) 2015-2016, ARM Limited, All Rights Reserved
  6. #
  7. # Purpose
  8. #
  9. # This script confirms that the naming of all symbols and identifiers in mbed
  10. # TLS are consistent with the house style and are also self-consistent.
  11. #
  12. set -eu
  13. if grep --version|head -n1|grep GNU >/dev/null; then :; else
  14. echo "This script requires GNU grep."
  15. exit 1
  16. fi
  17. printf "Analysing source code...\n"
  18. tests/scripts/list-macros.sh
  19. tests/scripts/list-enum-consts.pl
  20. tests/scripts/list-identifiers.sh
  21. tests/scripts/list-symbols.sh
  22. FAIL=0
  23. printf "\nExported symbols declared in header: "
  24. UNDECLARED=$( diff exported-symbols identifiers | sed -n -e 's/^< //p' )
  25. if [ "x$UNDECLARED" = "x" ]; then
  26. echo "PASS"
  27. else
  28. echo "FAIL"
  29. echo "$UNDECLARED"
  30. FAIL=1
  31. fi
  32. diff macros identifiers | sed -n -e 's/< //p' > actual-macros
  33. for THING in actual-macros enum-consts; do
  34. printf "Names of $THING: "
  35. test -r $THING
  36. BAD=$( grep -v '^MBEDTLS_[0-9A-Z_]*[0-9A-Z]$\|^YOTTA_[0-9A-Z_]*[0-9A-Z]$' $THING || true )
  37. if [ "x$BAD" = "x" ]; then
  38. echo "PASS"
  39. else
  40. echo "FAIL"
  41. echo "$BAD"
  42. FAIL=1
  43. fi
  44. done
  45. for THING in identifiers; do
  46. printf "Names of $THING: "
  47. test -r $THING
  48. BAD=$( grep -v '^mbedtls_[0-9a-z_]*[0-9a-z]$' $THING || true )
  49. if [ "x$BAD" = "x" ]; then
  50. echo "PASS"
  51. else
  52. echo "FAIL"
  53. echo "$BAD"
  54. FAIL=1
  55. fi
  56. done
  57. printf "Likely typos: "
  58. sort -u actual-macros enum-consts > _caps
  59. HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h' )
  60. NL='
  61. '
  62. sed -n 's/MBED..._[A-Z0-9_]*/\'"$NL"'&\'"$NL"/gp \
  63. $HEADERS library/*.c \
  64. | grep MBEDTLS | sort -u > _MBEDTLS_XXX
  65. TYPOS=$( diff _caps _MBEDTLS_XXX | sed -n 's/^> //p' \
  66. | egrep -v 'XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$' || true )
  67. rm _MBEDTLS_XXX _caps
  68. if [ "x$TYPOS" = "x" ]; then
  69. echo "PASS"
  70. else
  71. echo "FAIL"
  72. echo "$TYPOS"
  73. FAIL=1
  74. fi
  75. printf "\nOverall: "
  76. if [ "$FAIL" -eq 0 ]; then
  77. rm macros actual-macros enum-consts identifiers exported-symbols
  78. echo "PASSED"
  79. exit 0
  80. else
  81. echo "FAILED"
  82. exit 1
  83. fi