1#!/usr/bin/env python3 2 3import sys, os, re 4 5os.chdir (os.getenv ('srcdir', os.path.dirname (__file__))) 6 7HBHEADERS = [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')] 9HBSOURCES = [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 12stat = 0 13 14print ('Checking that public header files #include "hb-common.h" or "hb.h" first (or none)') 15for 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 23print ('Checking that source files #include a private header first (or none)') 24for 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 32print ('Checking that there is no #include <hb-*.h>') 33for 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 39sys.exit (stat) 40