more robust flags parsing in python bindings

The flags supplied by libraries cannot be relied upon to be sane so
they all must be run through a parser to make sure search paths are
specified in the correct order.
This commit is contained in:
Steven Siloti 2016-02-15 15:16:09 -08:00
parent d6d0480313
commit df368c2d15
3 changed files with 31 additions and 16 deletions

View File

@ -1 +1 @@
@COMPILETIME_OPTIONS@ @CPPFLAGS@ @LIBS@ @BOOST_CPPFLAGS@ @BOOST_SYSTEM_LIB@ @BOOST_PYTHON_LIB@ @PTHREAD_LIBS@ @OPENSSL_LIBS@ @OPENSSL_LDFLAGS@ @OPENSSL_INCLUDES@ -I@top_srcdir@/include
-I@top_srcdir@/include @COMPILETIME_OPTIONS@ @CPPFLAGS@ @BOOST_CPPFLAGS@ @OPENSSL_INCLUDES@

View File

@ -1 +1 @@
-L@top_builddir@/src/.libs @BOOST_LDFLAGS@ @LDFLAGS@
-L@top_builddir@/src/.libs @LDFLAGS@ @LIBS@ @BOOST_LDFLAGS@ @BOOST_SYSTEM_LIB@ @BOOST_PYTHON_LIB@ @PTHREAD_LIBS@ @OPENSSL_LIBS@ @OPENSSL_LDFLAGS@

View File

@ -9,14 +9,25 @@ import shutil
import multiprocessing
import subprocess
def parse_cmd(cmdline, prefix, keep_prefix = False):
class flags_parser:
def __init__(self):
self.include_dirs = []
self.library_dirs = []
self.libraries = []
def parse(self, args):
"""Parse out the -I -L -l directives and return a list of all other arguments"""
ret = []
for token in cmdline.split():
if token[:len(prefix)] == prefix:
if keep_prefix:
ret.append(token)
for token in args.split():
prefix = token[:2]
if prefix == '-I':
self.include_dirs.append(token[2:])
elif prefix == '-L':
self.library_dirs.append(token[2:])
elif prefix == '-l':
self.libraries.append(token[2:])
else:
ret.append(token[len(prefix):])
ret.append(token)
return ret
def arch():
@ -98,15 +109,19 @@ else:
source_list = [os.path.abspath(os.path.join(os.path.dirname(__file__), "src", s)) for s in source_list if s.endswith(".cpp")]
if extra_cmd:
flags = flags_parser()
# ldflags must be parsed first to ensure the correct library search path order
extra_link = flags.parse(ldflags)
extra_compile = flags.parse(extra_cmd)
ext = [Extension('libtorrent',
sources = source_list,
language='c++',
include_dirs = parse_cmd(extra_cmd, '-I'),
library_dirs = parse_cmd(extra_cmd, '-L'),
extra_link_args = ldflags.split() + arch(),
extra_compile_args = parse_cmd(extra_cmd, '-D', True) + arch() \
+ target_specific(),
libraries = ['torrent-rasterbar'] + parse_cmd(extra_cmd, '-l'))]
include_dirs = flags.include_dirs,
library_dirs = flags.library_dirs,
extra_link_args = extra_link + arch(),
extra_compile_args = extra_compile + arch() + target_specific(),
libraries = ['torrent-rasterbar'] + flags.libraries)]
setup(name = 'python-libtorrent',
version = '1.1.0',