From ff274fc03abf5467bc6096c40802bfde379fdcd0 Mon Sep 17 00:00:00 2001
From: Igor Gnatenko <i.gnatenko.brain@gmail.com>
Date: Tue, 4 Aug 2015 12:36:06 +0300
Subject: [PATCH] Distribute testsolv in -tools subpackage and build python3
 bindings

Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
---
 ...HONLIBS_VERSION_STRING-on-the-FIND_PACKAG.patch |  28 ++++++
 libsolv.spec                                       | 111 ++++++++++++++++-----
 2 files changed, 115 insertions(+), 24 deletions(-)
 create mode 100644 0001-Specify-PYTHONLIBS_VERSION_STRING-on-the-FIND_PACKAG.patch

diff --git a/0001-Specify-PYTHONLIBS_VERSION_STRING-on-the-FIND_PACKAG.patch b/0001-Specify-PYTHONLIBS_VERSION_STRING-on-the-FIND_PACKAG.patch
new file mode 100644
index 0000000..c016a75
--- /dev/null
+++ b/0001-Specify-PYTHONLIBS_VERSION_STRING-on-the-FIND_PACKAG.patch
@@ -0,0 +1,28 @@
+From 204406df09b45e1316f02f1f629ef79574530b3d Mon Sep 17 00:00:00 2001
+From: Michael Schroeder <mls@suse.de>
+Date: Tue, 4 Aug 2015 14:30:04 +0200
+Subject: [PATCH] Specify PYTHONLIBS_VERSION_STRING on the FIND_PACKAGE call
+
+Otherwise the configure will fail for newer cmake versions, as
+they expect _MAJOR/_MINOR/_COUNT to be set as well.
+---
+ bindings/python/CMakeLists.txt | 3 +--
+ 1 file changed, 1 insertion(+), 2 deletions(-)
+
+diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt
+index 8b5c72c..22ddec3 100644
+--- a/bindings/python/CMakeLists.txt
++++ b/bindings/python/CMakeLists.txt
+@@ -1,8 +1,7 @@
+ #SET (PythonLibs_FIND_VERSION 3)
+ 
+ FIND_PACKAGE (PythonLibs)
+-SET (PythonInterp_FIND_VERSION ${PYTHONLIBS_VERSION_STRING})
+-FIND_PACKAGE (PythonInterp REQUIRED)
++FIND_PACKAGE (PythonInterp ${PYTHONLIBS_VERSION_STRING} REQUIRED)
+ EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "from sys import stdout; from distutils import sysconfig; stdout.write(sysconfig.get_python_lib(True))" OUTPUT_VARIABLE PYTHON_INSTALL_DIR)
+ 
+ IF (NOT DEFINED PYTHON_VERSION_MAJOR)
+-- 
+2.5.0
+
diff --git a/libsolv.spec b/libsolv.spec
index a655893..31e56d8 100644
--- a/libsolv.spec
+++ b/libsolv.spec
@@ -1,21 +1,50 @@
 %global gitrev 2db517f87a8c0364d28c0fa2590ba034e866a4b8
 %{!?ruby_vendorarch: %global ruby_vendorarch %(ruby -r rbconfig -e "puts RbConfig::CONFIG['vendorarchdir'].nil? ? RbConfig::CONFIG['sitearchdir'] : RbConfig::CONFIG['vendorarchdir']")}
 %filter_provides_in %{perl_vendorarch}/.*\.so$
-%filter_provides_in %{python_sitearch}/.*\.so$
+%filter_provides_in %{python2_sitearch}/.*\.so$
+%if %{?fedora}
+%bcond_without python3
+%filter_provides_in %{python3_sitearch}/.*\.so$
+%global _cmake_opts \\\
+            -DCMAKE_BUILD_TYPE=RelWithDebInfo \\\
+            -DENABLE_PERL=1 \\\
+            -DENABLE_PYTHON=1 \\\
+            -DENABLE_RUBY=1 \\\
+            -DUSE_VENDORDIRS=1 \\\
+            -DFEDORA=1 \\\
+            -DENABLE_DEBIAN=1 \\\
+            -DENABLE_ARCHREPO=1 \\\
+            -DENABLE_LZMA_COMPRESSION=1 \\\
+            -DMULTI_SEMANTICS=1 \\\
+            %{nil}
+%else
+%bcond_with python3
+%global _cmake_opts \\\
+            -DCMAKE_BUILD_TYPE=RelWithDebInfo \\\
+            -DFEDORA=1 \\\
+            -DENABLE_LZMA_COMPRESSION=1 \\\
+            %{nil}
+%endif
 %filter_provides_in %{ruby_vendorarch}/.*\.so$
 %filter_setup
 
 Name:		libsolv
 Version:	0.6.11
-Release:	2%{?dist}
+Release:	3%{?dist}
 License:	BSD
 Url:		https://github.com/openSUSE/libsolv
 Source:		https://github.com/openSUSE/libsolv/archive/%{gitrev}.tar.gz
 Patch0:		libsolv-rubyinclude.patch
+# https://github.com/openSUSE/libsolv/commit/204406df09b45e1316f02f1f629ef79574530b3d
+Patch1:		0001-Specify-PYTHONLIBS_VERSION_STRING-on-the-FIND_PACKAG.patch
 Group:		Development/Libraries
 Summary:	Package dependency solver
 BuildRequires:	cmake libdb-devel expat-devel rpm-devel zlib-devel
-BuildRequires:	swig perl perl-devel ruby ruby-devel python2-devel
+BuildRequires:	swig perl perl-devel ruby ruby-devel
+BuildRequires:	python2-devel
+%if %{with python3}
+BuildRequires:	python3-devel
+%endif
 BuildRequires:  xz-devel
 %description
 A free package dependency solver using a satisfiability algorithm. The
@@ -63,15 +92,28 @@ Requires:	libsolv%{?_isa} = %{version}-%{release}
 %description -n ruby-solv
 Ruby bindings for sat solver.
 
-%package -n python-solv
+%package -n python2-solv
 Summary:	Python bindings for the libsolv library
 Group:		Development/Languages
-Requires:	python
+Requires:	python2
 Requires:	libsolv%{?_isa} = %{version}-%{release}
+%{?python_provide:%python_provide python2-solv}
 
-%description -n python-solv
+%description -n python2-solv
 Python bindings for sat solver.
 
+%if %{with python3}
+%package -n python3-solv
+Summary:	Python 3 bindings for the libsolv library
+Group:		Development/Languages
+Requires:	python3
+Requires:	libsolv%{?_isa} = %{version}-%{release}
+%{?python_provide:%python_provide python3-solv}
+
+%description -n python3-solv
+Python 3 bindings for sat solver.
+%endif
+
 %package -n perl-solv
 Summary:	Perl bindings for the libsolv library
 Group:		Development/Languages
@@ -84,27 +126,37 @@ Perl bindings for sat solver.
 %prep
 %setup -q -n libsolv-%{gitrev}
 %patch0 -p1 -b .rubyinclude
+%patch1 -p1 -b .python3
 
-%check
-make ARGS="-V" test
+%if %{with python3}
+rm -rf %{py3dir}
+cp -a . %{py3dir}
+%endif
 
 %build
-%cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-       -DENABLE_PERL=1 \
-       -DENABLE_PYTHON=1 \
-       -DENABLE_RUBY=1 \
-       -DUSE_VENDORDIRS=1 \
-       -DFEDORA=1 \
-       -DENABLE_DEBIAN=1 \
-       -DENABLE_ARCHREPO=1 \
-       -DENABLE_LZMA_COMPRESSION=1 \
-       -DMULTI_SEMANTICS=1
-
-make %{?_smp_mflags}
+%cmake %_cmake_opts \
+        -DPythonLibs_FIND_VERSION=2 -DPythonLibs_FIND_VERSION_MAJOR=2
+%make_build
+
+%if %{with python3}
+pushd %{py3dir}/
+  %cmake %_cmake_opts \
+        -DPythonLibs_FIND_VERSION=3 -DPythonLibs_FIND_VERSION_MAJOR=3
+  %make_build
+popd
+%endif
 
 %install
-make DESTDIR=$RPM_BUILD_ROOT install
-rm $RPM_BUILD_ROOT/usr/bin/testsolv
+%make_install
+
+%if %{with python3}
+pushd %{py3dir}/
+  %make_install
+popd
+%endif
+
+%check
+make ARGS="-V" test
 
 %post -p /sbin/ldconfig
 
@@ -128,6 +180,7 @@ rm $RPM_BUILD_ROOT/usr/bin/testsolv
 %_bindir/rpmdb2solv
 %_bindir/rpmmd2solv
 %_bindir/rpms2solv
+%_bindir/testsolv
 %_bindir/updateinfoxml2solv
 
 %files devel
@@ -149,11 +202,21 @@ rm $RPM_BUILD_ROOT/usr/bin/testsolv
 %doc examples/rbsolv
 %{ruby_vendorarch}/*
 
-%files -n python-solv
+%files -n python2-solv
 %doc examples/pysolv
-%{python_sitearch}/*
+%{python2_sitearch}/*
+
+%if %{with python3}
+%files -n python3-solv
+%doc examples/pysolv
+%{python3_sitearch}/*
+%endif
 
 %changelog
+* Tue Aug 04 2015 Igor Gnatenko <i.gnatenko.brain@gmail.com> - 0.6.11-3
+- Distribute testsolv in -tools subpackage
+- Enable python3 bindings for fedora
+
 * Tue Aug 04 2015 Adam Williamson <awilliam@redhat.com> - 0.6.11-2
 - make bindings require the exact matching version of the lib (#1243737)
 
-- 
2.5.0

