syms: Improve symbol processing

The export symbol regular expression processing is updated to make
several improvements:
  * The export expression (export_symbols_regex) now applies to both
    functions and global variables
  * A named capture group is used to match symbols. This allows the
    export expression to contain capture groups without disrupting the
    expression matching
This commit is contained in:
Joshua Watt 2017-07-26 20:33:24 -05:00 committed by ita1024
parent 24825b5575
commit 70e4c44080
1 changed files with 5 additions and 5 deletions

View File

@ -24,17 +24,17 @@ class gen_sym(Task):
obj = self.inputs[0]
kw = {}
if 'msvc' in (self.env.CC_NAME, self.env.CXX_NAME):
re_nm = re.compile(r'External\s+\|\s+_(' + self.generator.export_symbols_regex + r')\b')
re_nm = re.compile(r'External\s+\|\s+_(?P<symbol>' + self.generator.export_symbols_regex + r')\b')
cmd = (self.env.DUMPBIN or ['dumpbin']) + ['/symbols', obj.abspath()]
else:
if self.env.DEST_BINFMT == 'pe': #gcc uses nm, and has a preceding _ on windows
re_nm = re.compile(r'T\s+_(' + self.generator.export_symbols_regex + r')\b')
re_nm = re.compile(r'(T|D)\s+_(?P<symbol>' + self.generator.export_symbols_regex + r')\b')
elif self.env.DEST_BINFMT=='mac-o':
re_nm=re.compile(r'T\s+(_?'+self.generator.export_symbols_regex+r')\b')
re_nm=re.compile(r'(T|D)\s+(?P<symbol>_?'+self.generator.export_symbols_regex+r')\b')
else:
re_nm = re.compile(r'T\s+(' + self.generator.export_symbols_regex + r')\b')
re_nm = re.compile(r'(T|D)\s+(?P<symbol>' + self.generator.export_symbols_regex + r')\b')
cmd = (self.env.NM or ['nm']) + ['-g', obj.abspath()]
syms = re_nm.findall(self.generator.bld.cmd_and_log(cmd, quiet=STDOUT, **kw))
syms = [m.group('symbol') for m in re_nm.finditer(self.generator.bld.cmd_and_log(cmd, quiet=STDOUT, **kw))]
self.outputs[0].write('%r' % syms)
class compile_sym(Task):