From 210874d297147db24637e8b7751c2f0f9b98657d Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Wed, 4 Oct 2017 20:41:21 +0200 Subject: [PATCH] Fix #2053 --- playground/syms/wscript | 7 +++++++ waflib/extras/syms.py | 41 ++++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/playground/syms/wscript b/playground/syms/wscript index bc40f712..ef10aa50 100644 --- a/playground/syms/wscript +++ b/playground/syms/wscript @@ -9,3 +9,10 @@ def configure(ctx): def build(ctx): ctx(features='c cshlib syms', source='a.c b.c', export_symbols_regex='mylib_.*', target='testlib') ctx(features='c cprogram', source='main.c', target='app', use='testlib') + + # multiple shared libraries sharing the same file + ctx(features='c syms', source='a.c b.c', export_symbols_regex='mylib_.*', use='cshlib', + target='obj_example', sym_file='obj_example.def') + ctx(features='c cshlib syms', source=[], export_symbols_regex='mylib_.*', target='lib1', sym_file='obj_example.def') + ctx(features='c cshlib syms', source=[], export_symbols_regex='mylib_.*', target='lib2', sym_file='obj_example.def') + diff --git a/waflib/extras/syms.py b/waflib/extras/syms.py index 3f8158c5..dfa00593 100644 --- a/waflib/extras/syms.py +++ b/waflib/extras/syms.py @@ -2,7 +2,7 @@ # encoding: utf-8 """ -this tool supports the export_symbols_regex to export the symbols in a shared library. +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. to use the tool, do something like: @@ -12,7 +12,6 @@ def build(ctx): only the symbols starting with 'mylib_' will be exported. """ -import os import re from waflib.Context import STDOUT from waflib.Task import Task @@ -60,22 +59,26 @@ class compile_sym(Task): @feature('syms') @after_method('process_source', 'process_use', 'apply_link', 'process_uselib_local', 'propagate_uselib_vars') 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] + def_node = self.path.find_or_declare(getattr(self, 'sym_file', self.target + '.def')) + compiled_tasks = getattr(self, 'compiled_tasks', None) + if compiled_tasks: + ins = [x.outputs[0] for x in compiled_tasks] + self.gen_sym_tasks = [self.create_task('gen_sym', x, x.change_ext('.%d.sym' % self.idx)) for x in ins] + self.create_task('compile_sym', [x.outputs[0] for x in self.gen_sym_tasks], def_node) - tsk = self.create_task('compile_sym', - [x.outputs[0] for x in self.gen_sym_tasks], - 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]) - if 'msvc' in (self.env.CC_NAME, self.env.CXX_NAME): - self.link_task.env.append_value('LINKFLAGS', ['/def:' + tsk.outputs[0].bldpath()]) - elif self.env.DEST_BINFMT == 'pe': #gcc on windows takes *.def as an additional input - self.link_task.inputs.append(tsk.outputs[0]) - elif self.env.DEST_BINFMT == 'elf': - self.link_task.env.append_value('LINKFLAGS', ['-Wl,-version-script', '-Wl,' + tsk.outputs[0].bldpath()]) - elif self.env.DEST_BINFMT=='mac-o': - self.link_task.env.append_value('LINKFLAGS',['-Wl,-exported_symbols_list,'+tsk.outputs[0].bldpath()]) - else: - raise WafError('NotImplemented') + link_task = getattr(self, 'link_task', None) + if link_task: + self.link_task.dep_nodes.append(def_node) + + if 'msvc' in (self.env.CC_NAME, self.env.CXX_NAME): + self.link_task.env.append_value('LINKFLAGS', ['/def:' + def_node.bldpath()]) + elif self.env.DEST_BINFMT == 'pe': + # gcc on windows takes *.def as an additional input + self.link_task.inputs.append(def_node) + elif self.env.DEST_BINFMT == 'elf': + self.link_task.env.append_value('LINKFLAGS', ['-Wl,-version-script', '-Wl,' + def_node.bldpath()]) + elif self.env.DEST_BINFMT=='mac-o': + self.link_task.env.append_value('LINKFLAGS',['-Wl,-exported_symbols_list,' + def_node.bldpath()]) + else: + raise WafError('NotImplemented')