Imported Upstream version 3.4.0
[platform/upstream/harfbuzz.git] / src / check-includes.py
1 #!/usr/bin/env python3
2
3 import sys, os, re
4
5 os.chdir (os.getenv ('srcdir', os.path.dirname (__file__)))
6
7 HBHEADERS = [os.path.basename (x) for x in os.getenv ('HBHEADERS', '').split ()] or \
8         [x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith ('.h')]
9 HBSOURCES = [os.path.basename (x) for x in os.getenv ('HBSOURCES', '').split ()] or \
10         [x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith (('.cc', '.hh'))]
11
12 stat = 0
13
14 print ('Checking that public header files #include "hb-common.h" or "hb.h" first (or none)')
15 for x in HBHEADERS:
16         if x == 'hb.h' or x == 'hb-common.h': continue
17         with open (x, 'r', encoding='utf-8') as f: content = f.read ()
18         first = re.findall (r'#.*include.*', content)[0]
19         if first not in ['#include "hb.h"', '#include "hb-common.h"']:
20                 print ('failure on %s' % x)
21                 stat = 1
22
23 print ('Checking that source files #include a private header first (or none)')
24 for x in HBSOURCES:
25         with open (x, 'r', encoding='utf-8') as f: content = f.read ()
26         includes = re.findall (r'#.*include.*', content)
27         if includes:
28                 if not len (re.findall (r'"hb.*\.hh"', includes[0])):
29                         print ('failure on %s' % x)
30                         stat = 1
31
32 print ('Checking that there is no #include <hb-*.h>')
33 for x in HBHEADERS + HBSOURCES:
34         with open (x, 'r', encoding='utf-8') as f: content = f.read ()
35         if re.findall ('#.*include.*<.*hb', content):
36                 print ('failure on %s' % x)
37                 stat = 1
38
39 sys.exit (stat)