lv_conf_checker.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python3.6
  2. '''
  3. Generates a checker file for lv_conf.h from lv_conf_templ.h define all the not defined values
  4. '''
  5. import re
  6. fin = open("../lv_conf_template.h", "r")
  7. fout = open("../src/lv_conf_checker.h", "w")
  8. fout.write(
  9. '''/**
  10. * GENERATED FILE, DO NOT EDIT IT!
  11. * @file lv_conf_checker.h
  12. * Make sure all the defines of lv_conf.h have a default value
  13. **/
  14. #ifndef LV_CONF_CHECKER_H
  15. #define LV_CONF_CHECKER_H
  16. '''
  17. )
  18. started = 0
  19. for i in fin.read().splitlines():
  20. if not started:
  21. if '#define LV_CONF_H' in i:
  22. started = 1
  23. continue
  24. else:
  25. continue
  26. if '/*--END OF LV_CONF_H--*/' in i: break
  27. r = re.search(r'^ *# *define ([^\s]+).*$', i)
  28. if r:
  29. line = re.sub('\(.*?\)', '', r[1], 1) #remove parentheses from macros
  30. fout.write(
  31. f'#ifndef {line}\n'
  32. f'{i}\n'
  33. '#endif\n'
  34. )
  35. elif re.search('^ *typedef .*;.*$', i):
  36. continue #ignore typedefs to avoide redeclaration
  37. else:
  38. fout.write(f'{i}\n')
  39. fout.write(
  40. '''
  41. #endif /*LV_CONF_CHECKER_H*/
  42. '''
  43. )
  44. fin.close()
  45. fout.close()