From 45f3fa469627f006b2880547e427e0927a25eaa1 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 23 Mar 2014 07:34:18 +0000 Subject: [PATCH] simplified setup.py to always build the bindings using bjam --- ChangeLog | 1 + LICENSE | 2 +- bindings/python/Jamfile | 31 ++++++++++--- bindings/python/setup.py | 54 +++++++++++++++++++++++ bindings/python/setup.py.in | 86 ------------------------------------- configure.ac | 3 +- set_version.py | 2 + 7 files changed, 84 insertions(+), 95 deletions(-) create mode 100644 bindings/python/setup.py delete mode 100644 bindings/python/setup.py.in diff --git a/ChangeLog b/ChangeLog index f48c757b8..ec4a0a901 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * simplified building python bindings * make ignore_non_routers more forgiving in the case there are no UPnP devices at a known router. Should improve UPnP compatibility. * include reason in peer_blocked_alert diff --git a/LICENSE b/LICENSE index d52545910..2c361d159 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2003-2010, Arvid Norberg +Copyright (c) 2003-2014, Arvid Norberg All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/bindings/python/Jamfile b/bindings/python/Jamfile index d2a426f6f..d5a497c76 100755 --- a/bindings/python/Jamfile +++ b/bindings/python/Jamfile @@ -1,10 +1,14 @@ import python ; +import feature : feature ; use-project /torrent : ../.. ; lib boost_python : : darwin boost_python-mt $(boost-library-search-path) ; lib boost_python : : boost_python ; +feature visibility : default hidden : composite propagated link-incompatible ; +feature.compose hidden : -fvisibility=hidden -fvisibility-inlines-hidden ; + rule libtorrent_linking ( properties * ) { local result ; @@ -19,7 +23,12 @@ rule libtorrent_linking ( properties * ) || clang in $(properties) || clang-darwin in $(properties) { - result += -fvisibility=hidden ; + result += hidden ; + + if ( gcc in $(properties) ) + { + result += -Wl,-Bsymbolic ; + } } if source in $(properties) @@ -35,7 +44,7 @@ rule libtorrent_linking ( properties * ) if static in $(properties) { - result += /torrent//torrent/static ; + result += /torrent//torrent/static/static ; } else { @@ -45,14 +54,23 @@ rule libtorrent_linking ( properties * ) else { result += boost_python ; - result += /torrent//torrent/shared/shared ; + + if static in $(properties) + { + result += /torrent//torrent/static/static ; + } + else + { + result += /torrent//torrent/shared/shared ; + } } return $(result) ; } python-extension libtorrent - : src/module.cpp + : # sources + src/module.cpp src/big_number.cpp src/converters.cpp src/create_torrent.cpp @@ -73,9 +91,10 @@ python-extension libtorrent src/ip_filter.cpp src/magnet_uri.cpp src/error_code.cpp - : src + : # requirements + src @libtorrent_linking - : + : # default build static ; diff --git a/bindings/python/setup.py b/bindings/python/setup.py new file mode 100644 index 000000000..8f92c566f --- /dev/null +++ b/bindings/python/setup.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python + +from distutils import sysconfig +from distutils.core import setup, Extension +import os +import platform +import sys +import shutil +import multiprocessing + +if not '--help' in sys.argv \ + and not '--help-commands' in sys.argv: + + toolset = '' + file_ext = '.so' + + if platform.system() == 'Windows': + # msvc 9.0 (2008) is the official windows compiler for python 2.6 + # http://docs.python.org/whatsnew/2.6.html#build-and-c-api-changes + toolset = ' msvc-9.0' + file_ext = '.pyd' + + parallell_builds = ' -j%d' % multiprocessing.cpu_count() + + # build libtorrent using bjam and build the installer with distutils + + cmdline = 'bjam boost=source link=static geoip=static boost-link=static release optimization=space stage_module --abbreviate-paths' + toolset + parallell_builds + print cmdline + if os.system(cmdline) != 0: + print('build failed') + sys.exit(1) + + try: os.mkdir('build') + except: pass + try: shutil.rmtree('build/lib') + except: pass + try: os.mkdir('build/lib') + except: pass + try: os.mkdir('libtorrent') + except: pass + shutil.copyfile('libtorrent' + file_ext, 'build/lib/libtorrent' + file_ext) + +setup( name='python-libtorrent', + version='1.0.0', + author = 'Arvid Norberg', + author_email='arvid@rasterbar.com', + description = 'Python bindings for libtorrent-rasterbar', + long_description = 'Python bindings for libtorrent-rasterbar', + url = 'http://libtorrent.org', + platforms = [platform.system() + '-' + platform.machine()], + license = 'BSD', + packages = ['libtorrent'], +) + diff --git a/bindings/python/setup.py.in b/bindings/python/setup.py.in deleted file mode 100644 index e58045e3c..000000000 --- a/bindings/python/setup.py.in +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env python - -from distutils import sysconfig -from distutils.core import setup, Extension -import os -import platform -import sys - -if '@BOOST_PYTHON_LIB@' == '': - print('You need to pass --enable-python-binding to configure in order '), - print('to properly use this setup. There is no boost.python library configured now') - sys.exit(1) - -def parse_cmd(cmdline, prefix, keep_prefix = False): - ret = [] - for token in cmdline.split(): - if token[:len(prefix)] == prefix: - if keep_prefix: - ret.append(token) - else: - ret.append(token[len(prefix):]) - return ret - -def arch(): - if platform.system() != 'Darwin': return [] - a = os.uname()[4] - if a == 'Power Macintosh': a = 'ppc' - return ['-arch', a] - -if platform.system() == 'Windows': -# on windows, build using bjam and build an installer - import shutil - # msvc 9.0 (2008) is the official windows compiler for python 2.6 - # http://docs.python.org/whatsnew/2.6.html#build-and-c-api-changes - if os.system('bjam boost=source link=static geoip=static boost-link=static release msvc-9.0 optimization=space') != 0: - print('build failed') - sys.exit(1) - try: os.mkdir(r'build') - except: pass - try: os.mkdir(r'build\lib') - except: pass - try: os.mkdir(r'libtorrent') - except: pass - shutil.copyfile(r'bin\msvc-9.0\release\boost-source\geoip-static\link-static\optimization-space\threading-multi\libtorrent.pyd', r'.\build\lib\libtorrent.pyd') - setup( name='python-libtorrent', - version='@PACKAGE_VERSION@', - author = 'Arvid Norberg', - author_email='@PACKAGE_BUGREPORT@', - description = 'Python bindings for libtorrent-rasterbar', - long_description = 'Python bindings for libtorrent-rasterbar', - url = 'http://www.rasterbar.com/products/libtorrent/index.html', - platforms = 'Windows', - license = 'Boost Software License - Version 1.0 - August 17th, 2003', - packages = ['libtorrent'], - ) - sys.exit(0) - -config_vars = sysconfig.get_config_vars() -if "CFLAGS" in config_vars and "-Wstrict-prototypes" in config_vars["CFLAGS"]: - config_vars["CFLAGS"] = config_vars["CFLAGS"].replace("-Wstrict-prototypes", " ") -if "OPT" in config_vars and "-Wstrict-prototypes" in config_vars["OPT"]: - config_vars["OPT"] = config_vars["OPT"].replace("-Wstrict-prototypes", " ") - -source_list = os.listdir(os.path.join(os.path.dirname(__file__), "src")) -source_list = [os.path.join("src", s) for s in source_list if s.endswith(".cpp")] - -extra_cmd = '@COMPILETIME_OPTIONS@ @CPPFLAGS@ @LIBS@ @BOOST_SYSTEM_LIB@ @BOOST_PYTHON_LIB@ @PTHREAD_LIBS@ @OPENSSL_LIBS@ @OPENSSL_LDFLAGS@ @OPENSSL_INCLUDES@' - -setup( name='python-libtorrent', - version='@PACKAGE_VERSION@', - author = 'Arvid Norberg', - author_email='@PACKAGE_BUGREPORT@', - description = 'Python bindings for libtorrent-rasterbar', - long_description = 'Python bindings for libtorrent-rasterbar', - url = 'http://www.rasterbar.com/products/libtorrent/index.html', - platforms = 'any', - license = 'Boost Software License - Version 1.0 - August 17th, 2003', - ext_modules = [Extension('libtorrent', - sources = source_list, - language='c++', - include_dirs = ['@top_srcdir@/include'] + parse_cmd(extra_cmd, '-I'), - library_dirs = ['@top_builddir@/src/.libs'] + parse_cmd(extra_cmd, '-L'), - extra_link_args = '@LDFLAGS@'.split() + arch(), - extra_compile_args = parse_cmd(extra_cmd, '-D', True) + arch(), - libraries = ['torrent-rasterbar'] + parse_cmd(extra_cmd, '-l'))], -) diff --git a/configure.ac b/configure.ac index 4838de575..771aaeb84 100644 --- a/configure.ac +++ b/configure.ac @@ -173,7 +173,7 @@ AC_CHECK_FUNCS([clock_gettime], [], ) -dnl Pass some build options to setup.py and .pc file +dnl Pass some build options to .pc file COMPILETIME_OPTIONS="" @@ -687,7 +687,6 @@ AC_CONFIG_FILES( [tools/Makefile] [bindings/Makefile] [bindings/python/Makefile] - [bindings/python/setup.py] [libtorrent-rasterbar.pc] [libtorrent-rasterbar-cmake.pc] ) diff --git a/set_version.py b/set_version.py index bb06c676a..337e33048 100644 --- a/set_version.py +++ b/set_version.py @@ -25,6 +25,8 @@ def substitute_file(name): l = ':Version: %d.%d.%d\n' % (version[0], version[1], version[2]) elif 'VERSION = ' in l and name.endswith('Jamfile'): l = 'VERSION = %d.%d.%d ;\n' % (version[0], version[1], version[2]) + elif 'version=' in l and name.endswith('setup.py'): + l = "\tversion='%d.%d.%d'\n" % (version[0], version[1], version[2]) subst += l