xref: /aosp_15_r20/external/harfbuzz_ng/src/check-c-linkage-decls.py (revision 2d1272b857b1f7575e6e246373e1cb218663db8a)
1*2d1272b8SAndroid Build Coastguard Worker#!/usr/bin/env python3
2*2d1272b8SAndroid Build Coastguard Worker
3*2d1272b8SAndroid Build Coastguard Workerimport sys, os
4*2d1272b8SAndroid Build Coastguard Worker
5*2d1272b8SAndroid Build Coastguard Workersrcdir = os.getenv ('srcdir', os.path.dirname (__file__))
6*2d1272b8SAndroid Build Coastguard Workerbase_srcdir = os.getenv ('base_srcdir', srcdir)
7*2d1272b8SAndroid Build Coastguard Worker
8*2d1272b8SAndroid Build Coastguard Workeros.chdir (srcdir)
9*2d1272b8SAndroid Build Coastguard Worker
10*2d1272b8SAndroid Build Coastguard Workerdef removeprefix(s):
11*2d1272b8SAndroid Build Coastguard Worker	abs_path = os.path.join(base_srcdir, s)
12*2d1272b8SAndroid Build Coastguard Worker	return os.path.relpath(abs_path, srcdir)
13*2d1272b8SAndroid Build Coastguard Worker
14*2d1272b8SAndroid Build Coastguard Worker
15*2d1272b8SAndroid Build Coastguard WorkerHBHEADERS = [os.path.basename (x) for x in os.getenv ('HBHEADERS', '').split ()] or \
16*2d1272b8SAndroid Build Coastguard Worker	[x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith ('.h')]
17*2d1272b8SAndroid Build Coastguard WorkerHBHEADERS = [x for x in HBHEADERS if x.endswith ('.h')]
18*2d1272b8SAndroid Build Coastguard WorkerHBSOURCES = [
19*2d1272b8SAndroid Build Coastguard Worker    removeprefix(x) for x in os.getenv ('HBSOURCES', '').split ()
20*2d1272b8SAndroid Build Coastguard Worker] or [
21*2d1272b8SAndroid Build Coastguard Worker    x for x in os.listdir ('.') if x.startswith ('hb') and x.endswith (('.cc', '.hh'))
22*2d1272b8SAndroid Build Coastguard Worker]
23*2d1272b8SAndroid Build Coastguard Workerstat = 0
24*2d1272b8SAndroid Build Coastguard Worker
25*2d1272b8SAndroid Build Coastguard Workerfor x in HBHEADERS:
26*2d1272b8SAndroid Build Coastguard Worker	with open (x, 'r', encoding='utf-8') as f: content = f.read ()
27*2d1272b8SAndroid Build Coastguard Worker	if ('HB_BEGIN_DECLS' not in content) or ('HB_END_DECLS' not in content):
28*2d1272b8SAndroid Build Coastguard Worker		print ('Ouch, file %s does not have HB_BEGIN_DECLS / HB_END_DECLS, but it should' % x)
29*2d1272b8SAndroid Build Coastguard Worker		stat = 1
30*2d1272b8SAndroid Build Coastguard Worker
31*2d1272b8SAndroid Build Coastguard Workerfor x in HBSOURCES:
32*2d1272b8SAndroid Build Coastguard Worker	with open (x, 'r', encoding='utf-8') as f: content = f.read ()
33*2d1272b8SAndroid Build Coastguard Worker	if ('HB_BEGIN_DECLS' in content) or ('HB_END_DECLS' in content):
34*2d1272b8SAndroid Build Coastguard Worker		print ('Ouch, file %s has HB_BEGIN_DECLS / HB_END_DECLS, but it shouldn\'t' % x)
35*2d1272b8SAndroid Build Coastguard Worker		stat = 1
36*2d1272b8SAndroid Build Coastguard Worker
37*2d1272b8SAndroid Build Coastguard Workersys.exit (stat)
38