]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Support building for python2 and python3 in parallel
authorMichael Schroeder <mls@suse.de>
Tue, 8 Nov 2016 12:38:14 +0000 (13:38 +0100)
committerMichael Schroeder <mls@suse.de>
Tue, 8 Nov 2016 12:39:03 +0000 (13:39 +0100)
Needs some hacking in the recipe file

bindings/CMakeLists.txt
bindings/python/CMakeLists.txt
bindings/python3/CMakeLists.txt [new file with mode: 0644]
package/libsolv.spec.in

index 34b07846dc45d3cb212ebe49a1d8a4623e22a7a1..737cee4279e15788fbdffc4a31ec8b77e2d2c208 100644 (file)
@@ -8,6 +8,9 @@ SET (SWIG_INPUT "${CMAKE_CURRENT_SOURCE_DIR}/solv.i")
 IF (ENABLE_PYTHON)
     ADD_SUBDIRECTORY (python)
 ENDIF (ENABLE_PYTHON)
+IF (ENABLE_PYTHON3)
+    ADD_SUBDIRECTORY (python3)
+ENDIF (ENABLE_PYTHON3)
 IF (ENABLE_PERL)
     ADD_SUBDIRECTORY (perl)
 ENDIF (ENABLE_PERL)
index 73f2dcac590aae09825f748f127ccdc15f141aa9..2612a8bdef0c81b539d098704150b4b6fdd2767a 100644 (file)
@@ -13,6 +13,7 @@ ENDIF (${PYTHON_VERSION_MAJOR} GREATER 2)
 
 MESSAGE (STATUS "Python executable: ${PYTHON_EXECUTABLE}")
 MESSAGE (STATUS "Python installation dir: ${PYTHON_INSTALL_DIR}")
+MESSAGE (STATUS "Python include path: ${PYTHON_INCLUDE_PATH}")
 
 ADD_CUSTOM_COMMAND (
     OUTPUT solv_python.c
diff --git a/bindings/python3/CMakeLists.txt b/bindings/python3/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a63753d
--- /dev/null
@@ -0,0 +1,22 @@
+EXECUTE_PROCESS(COMMAND ${PYTHON3_EXECUTABLE} -c "from sys import stdout; from distutils import sysconfig; stdout.write(sysconfig.get_python_lib(True))" OUTPUT_VARIABLE PYTHON3_INSTALL_DIR)
+
+MESSAGE (STATUS "Python3 executable: ${PYTHON3_EXECUTABLE}")
+MESSAGE (STATUS "Python3 installation dir: ${PYTHON3_INSTALL_DIR}")
+MESSAGE (STATUS "Python3 include path: ${PYTHON3_INCLUDE_DIR}")
+
+ADD_CUSTOM_COMMAND (
+    OUTPUT solv_python.c
+    COMMAND ${SWIG_EXECUTABLE} ${SWIG_FLAGS} -python -DPYTHON3=1 -I${CMAKE_SOURCE_DIR}/src -o solv_python.c ${CMAKE_SOURCE_DIR}/bindings/solv.i
+    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+    DEPENDS ${CMAKE_SOURCE_DIR}/bindings/solv.i
+)
+
+ADD_DEFINITIONS(-Wno-unused)
+INCLUDE_DIRECTORIES (${PYTHON3_INCLUDE_DIR})
+
+ADD_LIBRARY (bindings_python3 SHARED solv_python.c)
+SET_TARGET_PROPERTIES (bindings_python3 PROPERTIES PREFIX "" OUTPUT_NAME "_solv")
+TARGET_LINK_LIBRARIES (bindings_python3 libsolvext libsolv ${SYSTEM_LIBRARIES})
+
+INSTALL (TARGETS bindings_python3 LIBRARY DESTINATION ${PYTHON3_INSTALL_DIR})
+INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/solv.py DESTINATION ${PYTHON3_INSTALL_DIR})
index c2251ec988d417c62507d3b535a8d444e4ccb009..236ec37f4353ea37871bad8301479847315257b0 100644 (file)
@@ -26,6 +26,7 @@ BuildRoot:      %{_tmppath}/%{name}-%{version}-build
 %bcond_without disable_shared
 %bcond_without perl_binding
 %bcond_without python_binding
+%bcond_with    python3_binding
 %bcond_without ruby_binding
 %bcond_with zypp
 
@@ -74,6 +75,10 @@ BuildRequires:  swig
 BuildRequires:  python-devel
 BuildRequires:  swig
 %endif
+%if %{with python3_binding}
+%global python3_sitearch %(python3 -c "from distutils.sysconfig import get_python_lib; print get_python_lib(True);")
+BuildRequires:  python3-devel
+%endif
 
 Summary:        A new approach to package dependency solving
 License:        BSD-3-Clause
@@ -146,6 +151,13 @@ Group:          Development/Languages/Python
 %description -n python-solv
 Python bindings for sat solver.
 
+%package -n python3-solv
+Summary:        Python3 bindings for the libsolv library
+Group:          Development/Languages/Python
+
+%description -n python3-solv
+Python3 bindings for sat solver.
+
 %package -n perl-solv
 Requires:       perl = %{perl_version}
 Summary:        Perl bindings for the libsolv library
@@ -162,6 +174,7 @@ export CFLAGS="$RPM_OPT_FLAGS"
 export CXXFLAGS="$CFLAGS"
 
 CMAKE_FLAGS=
+PYTHON_CMAKE_FLAGS=
 %if 0%{?fedora_version} || 0%{?rhel_version} >= 600 || 0%{?centos_version} >= 600
 CMAKE_FLAGS="-DFEDORA=1"
 %endif
@@ -169,7 +182,13 @@ CMAKE_FLAGS="-DFEDORA=1"
 CMAKE_FLAGS="-DSUSE=1 -DENABLE_APPDATA=1 -DENABLE_COMPS=1"
 %endif
 
-cmake   $CMAKE_FLAGS \
+%if %{with python3_binding}
+for pyversion in 3 2 ; do
+test $pyversion == 2 && perl -i -p -e 's/(python)/${1}3/i' CMakeCache.txt
+PYTHON_CMAKE_FLAGS="-DPythonLibs_FIND_VERSION=$pyversion -DPythonLibs_FIND_VERSION_MAJOR=$pyversion"
+%endif
+
+cmake  $CMAKE_FLAGS $PYTHON_CMAKE_FLAGS \
        -DCMAKE_INSTALL_PREFIX=%{_prefix} \
        -DLIB=%{_lib} \
        -DCMAKE_VERBOSE_MAKEFILE=TRUE \
@@ -182,17 +201,25 @@ cmake   $CMAKE_FLAGS \
        %{?with_zypp:-DENABLE_SUSEREPO=1 -DENABLE_HELIXREPO=1} \
        -DUSE_VENDORDIRS=1 \
        -DCMAKE_SKIP_RPATH=1
+
+%if %{with python3_binding}
+done
+%endif
+
 make %{?jobs:-j %jobs}
 
 %install
 make DESTDIR=$RPM_BUILD_ROOT install
-%if %{with python_binding}
 %if 0%{?suse_version}
+%if %{with python_binding}
 pushd $RPM_BUILD_ROOT/%{python_sitearch}
 python %py_libdir/py_compile.py *.py
 python -O %py_libdir/py_compile.py *.py
 popd
 %endif
+%if %{with python3_binding}
+%py3_compile $RPM_BUILD_ROOT/%{python3_sitearch}
+%endif
 %endif
 %if %{with disable_shared}
 # we want to leave the .a file untouched
@@ -265,4 +292,10 @@ rm -rf "$RPM_BUILD_ROOT"
 %{python_sitearch}/*
 %endif
 
+%if %{with python3_binding}
+%files -n python3-solv
+%defattr(-,root,root)
+%{python3_sitearch}/*
+%endif
+
 %changelog