check-config.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. # Copyright (c) 2016 Google, Inc
  3. # Written by Simon Glass <sjg@chromium.org>
  4. #
  5. # Check that the u-boot.cfg file provided does not introduce any new
  6. # ad-hoc CONFIG options
  7. #
  8. # You can generate the list of current ad-hoc CONFIG options (those which are
  9. # not in Kconfig) with this command:
  10. #
  11. # export LC_ALL=C LC_COLLATE=C
  12. # git grep CONFIG_ |tr ' \t' '\n\n' |sed -n 's/^\(CONFIG_[A-Z0-9_]*\).*/\1/p' \
  13. # |sort |uniq >scripts/config_whitelist.txt;
  14. # unset LC_ALL LC_COLLATE
  15. # Usage
  16. # check-config.sh <path to u-boot.cfg> <path to whitelist file> <source dir>
  17. #
  18. # For example:
  19. # scripts/check-config.sh b/chromebook_link/u-boot.cfg kconfig_whitelist.txt .
  20. path="$1"
  21. whitelist="$2"
  22. srctree="$3"
  23. # Temporary files
  24. configs="${path}.configs"
  25. suspects="${path}.suspects"
  26. ok="${path}.ok"
  27. new_adhoc="${path}.adhoc"
  28. export LC_ALL=C
  29. export LC_COLLATE=C
  30. cat ${path} |sed -n 's/^#define \(CONFIG_[A-Za-z0-9_]*\).*/\1/p' |sort |uniq \
  31. >${configs}
  32. comm -23 ${configs} ${whitelist} > ${suspects}
  33. cat `find ${srctree} -name "Kconfig*"` |sed -n \
  34. -e 's/^config *\([A-Za-z0-9_]*\).*$/CONFIG_\1/p' \
  35. -e 's/^menuconfig \([A-Za-z0-9_]*\).*$/CONFIG_\1/p' |sort |uniq > ${ok}
  36. comm -23 ${suspects} ${ok} >${new_adhoc}
  37. if [ -s ${new_adhoc} ]; then
  38. echo "Error: You must add new CONFIG options using Kconfig"
  39. echo "The following new ad-hoc CONFIG options were detected:"
  40. cat ${new_adhoc}
  41. echo
  42. echo "Please add these via Kconfig instead. Find a suitable Kconfig"
  43. echo "file and add a 'config' or 'menuconfig' option."
  44. # Don't delete the temporary files in case they are useful
  45. exit 1
  46. else
  47. rm ${suspects} ${ok} ${new_adhoc}
  48. fi