1 # functions for handling ABI checking of libraries
3 import Options, Utils, os, Logs, samba_utils, sys, Task, fnmatch, re
4 from TaskGen import feature, before, after
6 def normalise_signature(sig):
7 '''normalise a signature from gdb'''
9 sig = re.sub('^\$[0-9]+\s=\s\{*', '', sig)
10 sig = re.sub('\}(\s0x[0-9a-f]+\s<\w+>)?$', '', sig)
11 sig = re.sub('0x[0-9a-f]+', '0xXXXX', sig)
14 def normalise_varargs(sig):
15 '''cope with older versions of gdb'''
16 sig = re.sub(',\s\.\.\.', '', sig)
19 def parse_sigs(sigs, abi_match):
20 '''parse ABI signatures file'''
21 abi_match = samba_utils.TO_LIST(abi_match)
31 if fnmatch.fnmatch(sa[0], p):
36 ret[sa[0]] = normalise_signature(sa[1])
39 def save_sigs(sig_file, parsed_sigs):
40 '''save ABI signatures to a file'''
42 for s in sorted(parsed_sigs.keys()):
43 sigs += '%s: %s\n' % (s, parsed_sigs[s])
44 return samba_utils.save_file(sig_file, sigs, create_dir=True)
47 def abi_check_task(self):
48 '''check if the ABI has changed'''
49 abi_gen = self.ABI_GEN
51 libpath = self.inputs[0].abspath(self.env)
52 libname = os.path.basename(libpath)
54 sigs = Utils.cmd_output([abi_gen, libpath])
55 parsed_sigs = parse_sigs(sigs, self.ABI_MATCH)
57 sig_file = self.ABI_FILE
59 old_sigs = samba_utils.load_file(sig_file)
60 if old_sigs is None or Options.options.ABI_UPDATE:
61 if not save_sigs(sig_file, parsed_sigs):
62 raise Utils.WafError('Failed to save ABI file "%s"' % sig_file)
63 Logs.warn('Generated ABI signatures %s' % sig_file)
66 parsed_old_sigs = parse_sigs(old_sigs, self.ABI_MATCH)
70 for s in parsed_old_sigs:
71 if not s in parsed_sigs:
72 Logs.error('%s: symbol %s has been removed - please update major version\n\tsignature: %s' % (
73 libname, s, parsed_old_sigs[s]))
75 elif normalise_varargs(parsed_old_sigs[s]) != normalise_varargs(parsed_sigs[s]):
76 Logs.error('%s: symbol %s has changed - please update major version\n\told_signature: %s\n\tnew_signature: %s' % (
77 libname, s, parsed_old_sigs[s], parsed_sigs[s]))
81 if not s in parsed_old_sigs:
82 Logs.error('%s: symbol %s has been added - please mark it _PRIVATE_ or update minor version\n\tsignature: %s' % (
83 libname, s, parsed_sigs[s]))
87 raise Utils.WafError('ABI for %s has changed - please fix library version then build with --abi-update\nSee http://wiki.samba.org/index.php/Waf#ABI_Checking for more information' % libname)
90 t = Task.task_type_from_func('abi_check', abi_check_task, color='BLUE', ext_in='.bin')
96 '''check that ABI matches saved signatures'''
98 if not env.ABI_CHECK or self.abi_file is None:
101 # if the platform doesn't support -fvisibility=hidden then the ABI
102 # checks become fairly meaningless
103 if not env.HAVE_VISIBILITY_ATTR:
106 topsrc = self.bld.srcnode.abspath()
107 abi_gen = os.path.join(topsrc, 'buildtools/scripts/abi_gen.sh')
109 tsk = self.create_task('abi_check', self.link_task.outputs[0])
110 tsk.ABI_FILE = self.abi_file
111 tsk.ABI_MATCH = self.abi_match
112 tsk.ABI_GEN = abi_gen