Build python3 library in addition to python library

This commit is contained in:
Andrey Bondrov 2015-10-20 17:22:21 +10:00
parent db227c8708
commit 5b6cf304dd
4 changed files with 232 additions and 9 deletions

View file

@ -0,0 +1,62 @@
--- boost_1_55_0/tools/build/v2/tools/python.jam 2013-05-21 06:14:18.000000000 +0200
+++ boost_1_55_0/tools/build/v2/tools/python.jam 2014-05-29 19:09:12.115413877 +0200
@@ -94,7 +94,7 @@ feature.feature pythonpath : : free opti
# using python : 2.3 : /usr/local/bin/python ;
#
rule init ( version ? : cmd-or-prefix ? : includes * : libraries ?
- : condition * : extension-suffix ? )
+ : condition * : extension-suffix ? : abi-letters ? )
{
project.push-current $(.project) ;
@@ -107,7 +107,7 @@ rule init ( version ? : cmd-or-prefix ?
}
}
- configure $(version) : $(cmd-or-prefix) : $(includes) : $(libraries) : $(condition) : $(extension-suffix) ;
+ configure $(version) : $(cmd-or-prefix) : $(includes) : $(libraries) : $(condition) : $(extension-suffix) : $(abi-letters) ;
project.pop-current ;
}
@@ -653,7 +653,7 @@ local rule system-library-dependencies (
# Declare a target to represent Python's library.
#
-local rule declare-libpython-target ( version ? : requirements * )
+local rule declare-libpython-target ( version ? : requirements * : abi-letters ? )
{
# Compute the representation of Python version in the name of Python's
# library file.
@@ -677,13 +677,13 @@ local rule declare-libpython-target ( ve
}
# Declare it.
- lib python.lib : : <name>python$(lib-version) $(requirements) ;
+ lib python.lib : : <name>python$(lib-version)$(abi-letters) $(requirements) ;
}
# Implementation of init.
local rule configure ( version ? : cmd-or-prefix ? : includes * : libraries ? :
- condition * : extension-suffix ? )
+ condition * : extension-suffix ? : abi-letters ? )
{
local prefix ;
local exec-prefix ;
@@ -699,6 +699,7 @@ local rule configure ( version ? : cmd-o
extension-suffix ?= _d ;
}
extension-suffix ?= "" ;
+ abi-letters ?= "" ;
# Normalize and dissect any version number.
local major-minor ;
@@ -922,7 +923,7 @@ local rule configure ( version ? : cmd-o
}
else
{
- declare-libpython-target $(version) : $(target-requirements) ;
+ declare-libpython-target $(version) : $(target-requirements) : $(abi-letters) ;
# This is an evil hack. On, Windows, when Python is embedded, nothing
# seems to set up sys.path to include Python's standard library

View file

@ -0,0 +1,13 @@
Index: boost/tools/build/v2/tools/python.jam
===================================================================
--- boost/tools/build/v2/tools/python.jam (revision 50406)
+++ boost/tools/build/v2/tools/python.jam (working copy)
@@ -994,7 +994,7 @@
else
{
alias python_for_extensions
- :
+ : python
: $(target-requirements)
:
: $(usage-requirements)

View file

@ -0,0 +1,98 @@
diff -up boost_1_55_0/libs/python/test/exec.cpp\~ boost_1_55_0/libs/python/test/exec.cpp
--- boost_1_55_0/libs/python/test/exec.cpp~ 2010-07-05 00:38:38.000000000 +0200
+++ boost_1_55_0/libs/python/test/exec.cpp 2015-01-09 21:31:12.903218280 +0100
@@ -56,6 +56,20 @@ void eval_test()
BOOST_TEST(value == "ABCDEFG");
}
+struct PyCtx
+{
+ PyCtx() {
+ Py_Initialize();
+ }
+
+ ~PyCtx() {
+ // N.B. certain problems may arise when Py_Finalize is called when
+ // using Boost.Python. However in this test suite it all seems to
+ // work fine.
+ Py_Finalize();
+ }
+};
+
void exec_test()
{
// Register the module with the interpreter
@@ -68,6 +82,8 @@ void exec_test()
) == -1)
throw std::runtime_error("Failed to add embedded_hello to the interpreter's "
"builtin modules");
+
+ PyCtx ctx;
// Retrieve the main module
python::object main = python::import("__main__");
@@ -148,41 +164,43 @@ void check_pyerr(bool pyerr_expected=fal
}
}
+template <class Cb>
+bool
+run_and_handle_exception(Cb cb, bool pyerr_expected = false)
+{
+ PyCtx ctx;
+ if (python::handle_exception(cb)) {
+ check_pyerr(pyerr_expected);
+ return true;
+ } else {
+ return false;
+ }
+}
+
int main(int argc, char **argv)
{
BOOST_TEST(argc == 2 || argc == 3);
std::string script = argv[1];
- // Initialize the interpreter
- Py_Initialize();
- if (python::handle_exception(eval_test)) {
- check_pyerr();
- }
- else if(python::handle_exception(exec_test)) {
- check_pyerr();
- }
- else if (python::handle_exception(boost::bind(exec_file_test, script))) {
+ // N.B. exec_test mustn't be called through run_and_handle_exception
+ // as it needs to handles the python context by itself.
+ if (run_and_handle_exception(eval_test)
+ || python::handle_exception(exec_test))
check_pyerr();
- }
-
- if (python::handle_exception(exec_test_error))
- {
- check_pyerr(/*pyerr_expected*/ true);
- }
else
- {
+ run_and_handle_exception(boost::bind(exec_file_test, script));
+
+ if (!run_and_handle_exception(exec_test_error, true))
BOOST_ERROR("Python exception expected, but not seen.");
- }
if (argc > 2) {
+ PyCtx ctx;
// The main purpose is to test compilation. Since this test generates
// a file and I (rwgk) am uncertain about the side-effects, run it only
// if explicitly requested.
exercise_embedding_html();
}
- // Boost.Python doesn't support Py_Finalize yet.
- // Py_Finalize();
return boost::report_errors();
}
Diff finished. Fri Jan 9 21:31:13 2015

View file

@ -20,6 +20,7 @@
%define libprgexecmonitor %mklibname boost_prg_exec_monitor %{version}
%define libprogramoptions %mklibname boost_program_options %{version}
%define libpython %mklibname boost_python %{version}
%define libpython3 %mklibname boost_python3_ %{version}
%define librandom %mklibname boost_random %{version}
%define libregex %mklibname boost_regex %{version}
%define libserialization %mklibname boost_serialization %{version}
@ -33,6 +34,7 @@
%define devname %mklibname boost -d
%define sdevname %mklibname boost -d -s
%define devpython3 %mklibname boost_python3 -d
%ifarch aarch64
%bcond_with context
@ -48,12 +50,16 @@
Summary: Portable C++ libraries
Name: boost
Version: 1.55.0
Release: 7
Release: 8
License: Boost
Group: Development/C++
Url: http://boost.org/
Source0: http://download.sourceforge.net/boost/boost_%{packver}.tar.bz2
Source100: %{name}.rpmlintrc
# https://bugzilla.redhat.com/show_bug.cgi?id=1102667
Patch0: boost-1.55.0-python-abi_letters.patch
Patch1: boost-1.55.0-python-libpython_dep.patch
Patch2: boost-1.55.0-python-test-PyImport_AppendInittab.patch
# https://svn.boost.org/trac/boost/ticket/6150
Patch4: boost-1.50.0-fix-non-utf8-files.patch
# Add a manual page for the sole executable, namely bjam, based on the
@ -77,6 +83,7 @@ BuildRequires: bzip2-devel
BuildRequires: pkgconfig(expat)
BuildRequires: pkgconfig(icu-uc)
BuildRequires: pkgconfig(python)
BuildRequires: pkgconfig(python3)
BuildRequires: pkgconfig(zlib)
%description
@ -484,6 +491,24 @@ running programs dynamically linked against Boost python.
#----------------------------------------------------------------------------
%package -n %{libpython3}
Summary: Boost python3 shared library
Group: System/Libraries
# no one should require this, but provided anyway for maximum compatibility:
Provides: boost = %{EVRD}
%description -n %{libpython3}
Boost is a collection of free peer-reviewed portable C++ source
libraries. The emphasis is on libraries which work well with the C++
Standard Library. This package contains the shared library needed for
running programs dynamically linked against Boost python.
%files -n %{libpython3}
%doc LICENSE_1_0.txt
%{_libdir}/libboost_python3.so.%{version}
#----------------------------------------------------------------------------
%package -n %{librandom}
Summary: Boost random shared library
Group: System/Libraries
@ -707,14 +732,15 @@ Standard Library. This package contains headers and shared library
symlinks needed for Boost development.
%files -n %{devname}
%{_libdir}/libboost_*.so
%{_includedir}/boost
%{_libdir}/libboost_*.so
%exclude %{_libdir}/libboost_python3.so
#----------------------------------------------------------------------------
%package -n %{devname}-doc
Summary: The libraries and headers needed for Boost development
Group: Development/C++
Summary: Documentation for Boost
Group: Documentation
BuildArch: noarch
%description -n %{devname}-doc
@ -745,8 +771,29 @@ needed for Boost development.
#----------------------------------------------------------------------------
%package -n %{devpython3}
Summary: The libraries and headers needed for Boost Python 3 development
Group: Development/C++
Requires: %{libpython3} = %{EVRD}
Requires: %{devname} = %{EVRD}
Provides: %{name}-python3-devel = %{EVRD}
%description -n %{devpython3}
Boost is a collection of free peer-reviewed portable C++ source
libraries. The emphasis is on libraries which work well with the C++
Standard Library. This package contains headers and shared library
symlinks needed for Boost development.
%files -n %{devpython3}
%{_libdir}/libboost_python3.so
#----------------------------------------------------------------------------
%prep
%setup -q -n boost_%{packver}
%setup -qn boost_%{packver}
%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch4 -p1
%patch5 -p1
%patch7 -p2
@ -767,17 +814,19 @@ find libs -type f \( -name "*.?pp" ! -path "*test*" ! -path "*src*" ! -path "*to
%build
%define gcc_ver %(rpm -q --queryformat="%%{VERSION}" gcc)
cat > ./tools/build/v2/user-config.jam << EOF
using gcc : %{gcc_ver} : gcc : <cflags>"%{optflags} -I%{_includedir}/python%{py_ver}" <cxxflags>"%{optflags} -I%{_includedir}/python%{py_ver}" <linkflags>"%{ldflags}" ;
using python : %{py_ver} : %{_bindir}/python%{py_ver} : %{_includedir}/python%{py_ver} : %{_libdir} ;
using gcc : %{gcc_ver} : gcc : <cflags>"%{optflags}" <cxxflags>"%{optflags}" <linkflags>"%{ldflags}" ;
using python : %{py3_ver} : %{_bindir}/python%{py3_ver} : %{_includedir}/python%{py3_ver}m : %{_libdir} : : : ;
using python : %{py_ver} : %{_bindir}/python%{py_ver} : %{_includedir}/python%{py_ver} : %{_libdir} : : : ;
EOF
./bootstrap.sh --with-toolset=gcc --with-icu --prefix=%{_prefix} --libdir=%{_libdir}
./bootstrap.sh --with-toolset=gcc --with-icu --prefix=%{_prefix} --libdir=%{_libdir} --with-python=%{py_ver}
./b2 -d+2 -q %{?_smp_mflags} --without-mpi \
--prefix=%{_prefix} --libdir=%{_libdir} \
%if !%{with context}
--without-context --without-coroutine \
%endif
linkflags="%{ldflags} -lpython%{py_ver} -lstdc++ -lm" \
linkflags="%{ldflags} -lstdc++ -lm" \
-sHAVE_ICU=1 \
python=%{py_ver} \
link=shared threading=multi debug-symbols=off --layout=system
# Taken from the Fedora .src.rpm.
@ -792,6 +841,7 @@ echo ============================= build Boost.Build ==================
--without-context --without-coroutine \
%endif
link=shared \
python=%{py_ver} \
install
echo ============================= install Boost.Build ==================