InfiniTime.git

ref: 0.12.0

src/libs/lvgl/scripts/lv_conf_checker.py


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3.6

'''
Generates a checker file for lv_conf.h from lv_conf_templ.h define all the not defined values
'''


import re

fin = open("../lv_conf_template.h", "r")
fout = open("../src/lv_conf_checker.h", "w")


fout.write(
'''/**
 * GENERATED FILE, DO NOT EDIT IT!
 * @file lv_conf_checker.h
 * Make sure all the defines of lv_conf.h have a default value
**/

#ifndef LV_CONF_CHECKER_H
#define LV_CONF_CHECKER_H
'''
)

started = 0

for i in fin.read().splitlines():
  if not started:
    if '#define LV_CONF_H' in i:
      started = 1
      continue
    else:
      continue

  if '/*--END OF LV_CONF_H--*/' in i: break

  r = re.search(r'^ *# *define ([^\s]+).*$', i)
  
  if r:
    line = re.sub('\(.*?\)', '', r[1], 1)    #remove parentheses from macros
    fout.write(
      f'#ifndef {line}\n'
      f'{i}\n'
      '#endif\n'
    )
  elif re.search('^ *typedef .*;.*$', i):
    continue   #ignore typedefs to avoide redeclaration
  else:
    fout.write(f'{i}\n')


fout.write(
'''
#endif  /*LV_CONF_CHECKER_H*/
'''
)

fin.close()
fout.close()