check_api_violation.sh 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env bash
  2. set -uo pipefail
  3. # ESP-IDF should only use the ROM API that has a prefix "esp_rom_"
  4. cd ${IDF_PATH} # git ls-files operates on working directory only, make sure we're at the top directory
  5. deprecated_rom_apis=$(cat ${IDF_PATH}/components/esp_rom/esp32/ld/esp32.rom.api.ld | grep "esp_rom_" | cut -d "=" -f 2 | cut -d " " -f 2)
  6. files_to_search=$(git ls-files --full-name '*.c' ':!:components/esp_rom/')
  7. count=0
  8. for api in $deprecated_rom_apis; do
  9. found_files=$(grep -E "\W+"$api"\W+" $files_to_search)
  10. if [ -n "$found_files" ]; then
  11. echo $found_files
  12. ((count++))
  13. fi
  14. done
  15. if [ $count -gt 0 ]; then
  16. echo "ROM APIs used in ESP-IDF should have an esp_rom_ prefix"
  17. echo "Please try to use the APIs listed in esp_rom/include/esp_rom_xxx.h"
  18. exit 1
  19. fi
  20. # ESP-IDF `hal` component shouldn't call "assert()" directlly
  21. files_to_search=$(git ls-files --full-name 'components/hal/*')
  22. found_libc_assert=$(grep -E '\W+assert\(' $files_to_search)
  23. if [ -n "$found_libc_assert" ]; then
  24. echo "hal assert violation"
  25. echo $found_libc_assert
  26. echo "Please use HAL_ASSERT() instead of assert() in hal component"
  27. fi