From bdf607ea5f218b1aa60dff9abc94b68e1a934368 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 5 Aug 2014 02:21:29 +0200 Subject: build: list exported symbols explicitly Instead of using a regex to match names to be exported from the libmpv dynamic shared library, use a libmpv.def file, which lists all exported functions explicitly. This reduces the platform specifics in syms.py. I'm not sure if the separate compile_sym task is still needed (it could probably be collapsed, which would concentrate the platform specifics into one place). --- waftools/syms.py | 48 ++++++++---------------------------------------- 1 file changed, 8 insertions(+), 40 deletions(-) (limited to 'waftools') diff --git a/waftools/syms.py b/waftools/syms.py index 520ae70a88..ff53078260 100644 --- a/waftools/syms.py +++ b/waftools/syms.py @@ -1,56 +1,27 @@ #! /usr/bin/env python # encoding: utf-8 -# Source: waflib/extras/syms.py from waf git 610d0d59f (New BSD License) +# Original source: waflib/extras/syms.py from waf git 610d0d59f (New BSD License) """ -this tool supports the export_symbols_regex to export the symbols in a shared library. -by default, all symbols are exported by gcc, and nothing by msvc. +set the list of symbols exported from a dynamic library to use the tool, do something like: def build(ctx): - ctx(features='c cshlib syms', source='a.c b.c', export_symbols_regex='mylib_.*', target='testlib') + ctx(features='c cshlib syms', source='a.c b.c', export_symbols_def='syms.def', target='testlib') -only the symbols starting with 'mylib_' will be exported. +only the symbols listed in the file syms.def will be exported. """ -import os -import re from waflib.Context import STDOUT from waflib.Task import Task from waflib.Errors import WafError from waflib.TaskGen import feature, after_method -class gen_sym(Task): - def run(self): - 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') - cmd = [self.env.DUMPBIN or 'dumpbin', '/symbols', obj.abspath()] - - # Dumpbin requires custom environment sniffed out by msvc.py earlier - if self.env['PATH']: - env = dict(self.env.env or os.environ) - env.update(PATH = os.pathsep.join(self.env['PATH'])) - kw['env'] = env - - else: - if self.env.DEST_BINFMT in ('mac-o',): #gcc uses nm, and has a preceding _ on osx - re_nm = re.compile(r'T\s+_(' + self.generator.export_symbols_regex + r')\b') - else: - re_nm = re.compile(r'T\s+(' + 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)) - self.outputs[0].write('%r' % syms) - class compile_sym(Task): def run(self): - syms = {} - for x in self.inputs: - slist = eval(x.read()) - for s in slist: - syms[s] = 1 - lsyms = list(syms.keys()) + lsyms = [] + for line in self.inputs[0].read().split(): + lsyms.append(line.strip()) lsyms.sort() if self.env.DEST_BINFMT == 'pe': self.outputs[0].write('EXPORTS\n' + '\n'.join(lsyms)) @@ -64,11 +35,8 @@ class compile_sym(Task): @feature('syms') @after_method('process_source', 'process_use', 'apply_link', 'process_uselib_local') def do_the_symbol_stuff(self): - ins = [x.outputs[0] for x in self.compiled_tasks] - self.gen_sym_tasks = [self.create_task('gen_sym', x, x.change_ext('.%d.sym' % self.idx)) for x in ins] - tsk = self.create_task('compile_sym', - [x.outputs[0] for x in self.gen_sym_tasks], + [self.path.find_node(self.export_symbols_def)], self.path.find_or_declare(getattr(self, 'sym_filename', self.target + '.def'))) self.link_task.set_run_after(tsk) self.link_task.dep_nodes.append(tsk.outputs[0]) -- cgit v1.2.3