check-config.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. # Use scripts/build-whitelist.sh to generate the list of current ad-hoc
  9. # CONFIG options (those which are not in Kconfig).
  10. # Usage
  11. # check-config.sh <path to u-boot.cfg> <path to whitelist file> <source dir>
  12. #
  13. # For example:
  14. # scripts/check-config.sh b/chromebook_link/u-boot.cfg kconfig_whitelist.txt .
  15. set -e
  16. set -u
  17. PROG_NAME="${0##*/}"
  18. usage() {
  19. echo "$PROG_NAME <path to u-boot.cfg> <path to whitelist file> <source dir>"
  20. exit 1
  21. }
  22. [ $# -ge 3 ] || usage
  23. path="$1"
  24. whitelist="$2"
  25. srctree="$3"
  26. # Temporary files
  27. configs="${path}.configs"
  28. suspects="${path}.suspects"
  29. ok="${path}.ok"
  30. new_adhoc="${path}.adhoc"
  31. export LC_ALL=C
  32. export LC_COLLATE=C
  33. cat ${path} |sed -n 's/^#define \(CONFIG_[A-Za-z0-9_]*\).*/\1/p' |sort |uniq \
  34. >${configs}
  35. comm -23 ${configs} ${whitelist} > ${suspects}
  36. cat `find ${srctree} -name "Kconfig*"` |sed -n \
  37. -e 's/^\s*config *\([A-Za-z0-9_]*\).*$/CONFIG_\1/p' \
  38. -e 's/^\s*menuconfig \([A-Za-z0-9_]*\).*$/CONFIG_\1/p' \
  39. |sort |uniq > ${ok}
  40. comm -23 ${suspects} ${ok} >${new_adhoc}
  41. if [ -s ${new_adhoc} ]; then
  42. echo >&2 "Error: You must add new CONFIG options using Kconfig"
  43. echo >&2 "The following new ad-hoc CONFIG options were detected:"
  44. cat >&2 ${new_adhoc}
  45. echo >&2
  46. echo >&2 "Please add these via Kconfig instead. Find a suitable Kconfig"
  47. echo >&2 "file and add a 'config' or 'menuconfig' option."
  48. # Don't delete the temporary files in case they are useful
  49. exit 1
  50. else
  51. rm ${suspects} ${ok} ${new_adhoc}
  52. fi