blob: 35ae6bef62539aa68a86ce7295494c5a507b091f [file] [log] [blame]
Ebrahim Byagowi7250ade2020-05-29 12:34:30 +04301#!/usr/bin/env python3
2
3import sys, os, re
4
Xavier Claessens4266f4e2022-06-03 12:06:56 -04005srcdir = os.getenv ('srcdir', os.path.dirname (__file__))
6base_srcdir = os.getenv ('base_srcdir', srcdir)
Ebrahim Byagowi7250ade2020-05-29 12:34:30 +04307
Xavier Claessens4266f4e2022-06-03 12:06:56 -04008os.chdir (srcdir)
9
10def removeprefix(s):
11 abs_path = os.path.join(base_srcdir, s)
12 return os.path.relpath(abs_path, srcdir)
Garret Riegerf577d022022-01-20 14:39:48 -080013
14
Ebrahim Byagowia07672d2020-07-04 14:12:55 +043015HBHEADERS = [os.path.basename (x) for x in os.getenv ('HBHEADERS', '').split ()] or \
Ebrahim Byagowi7250ade2020-05-29 12:34:30 +043016 [x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith ('.h')]
Garret Riegerf577d022022-01-20 14:39:48 -080017HBSOURCES = [
Xavier Claessens4266f4e2022-06-03 12:06:56 -040018 removeprefix(x) for x in os.getenv ('HBSOURCES', '').split ()
Garret Riegerf577d022022-01-20 14:39:48 -080019] or [
20 x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith (('.cc', '.hh'))
21]
22
Ebrahim Byagowi7250ade2020-05-29 12:34:30 +043023
24stat = 0
25
26for x in HBHEADERS + HBSOURCES:
27 if not x.endswith ('h') or x == 'hb-gobject-structs.h': continue
Garret Riegerf577d022022-01-20 14:39:48 -080028 tag = x.upper ().replace ('.', '_').replace ('-', '_').replace(os.path.sep, '_').replace('/', '_')
Ebrahim Byagowi7250ade2020-05-29 12:34:30 +043029 with open (x, 'r', encoding='utf-8') as f: content = f.read ()
30 if len (re.findall (tag + r'\b', content)) != 3:
Garret Riegerf577d022022-01-20 14:39:48 -080031 print ('Ouch, header file %s does not have correct preprocessor guards. Expected: %s' % (x, tag))
Ebrahim Byagowi7250ade2020-05-29 12:34:30 +043032 stat = 1
33
34sys.exit (stat)