[Pkg-libvirt-maintainers] Bug#628828: [PATCH] Build Python-bindings for all Python versions

Philipp Hahn hahn at univention.de
Wed Aug 10 10:48:04 UTC 2011


Hello Guido,

In reference to our talk at DebConf11, here's a patch to build the Python 
bindings of libvirt for all versions of Python. This might also fix this bug.

The idea of this patch is to
1. switch to an out-of-tree build, since I have to play some symlink-tricks to 
create the python/ directory for each Python version
2. configure and build it once for the default Python version
3. build and install just the python/ directory for all Python versions

The patch to debina/control will probably not apply to Debians current 
version, so just so following change:
 sed -e '/Build-Depends:/s/python-dev/python-all-dev/' \
 -e '/XS-Python-Version:/s/current/all/' debian/control

diff -ur a/debian/control b/debian/control
--- a/debian/control	2010-03-23 12:26:14.000000000 +0100
+++ b/debian/control	2010-03-23 12:27:56.000000000 +0100
@@ -3,13 +3,13 @@
 Priority: optional
 Maintainer: Debian Libvirt Maintainers 
<pkg-libvirt-maintainers at lists.alioth.debian.org>
 Uploaders: Guido Günther <agx at sigxcpu.org>, Laurent Léonard 
<laurent at open-minds.org>
-Build-Depends: cdbs (>= 0.4.43), debhelper (>= 7), libxml2-dev, 
libncurses5-dev, libreadline-dev, zlib1g-dev, libgnutls-dev, python-dev (>= 
2.3.5-11), python-central (>= 0.5.6),
+Build-Depends: cdbs (>= 0.4.43), debhelper (>= 7), libxml2-dev, 
libncurses5-dev, libreadline-dev, zlib1g-dev, libgnutls-dev, python-all-dev 
(>= 2.3.5-11), python-central (>= 0.5.6),
  libavahi-client-dev, libsasl2-dev, xen-3.4 [i386 amd64], lvm2, qemu [amd64 
i386 powerpc sparc], open-iscsi, libparted1.8-dev (>= 1.8), libdevmapper-dev, 
uuid-dev,
  libpciaccess-dev,
  module-init-tools,
  dpkg-dev (<< 1.15.3) | dpkg-dev (>> 1.15.3),
  libnl-dev
-XS-Python-Version: current
+XS-Python-Version: all
 Build-Conflicts: dpkg-dev (= 1.15.3)
 Vcs-Git: git://git.debian.org/git/pkg-libvirt/libvirt.git
 Vcs-Browser: http://git.debian.org/?p=pkg-libvirt/libvirt.git
diff -ur a/debian/rules b/debian/rules
--- a/debian/rules	2011-01-24 10:59:18.235952511 +0100
+++ b/debian/rules	2011-01-24 11:01:29.947448727 +0100
@@ -21,6 +21,7 @@
 include /usr/share/cdbs/1/class/autotools.mk
 include /usr/share/cdbs/1/class/python-distutils.mk
 
+DEB_BUILDDIR := $(CURDIR)/debian/build
 DEB_CONFIGURE_EXTRA_FLAGS :=     \
 	--disable-rpath          \
 	--with-qemu              \
@@ -43,18 +44,59 @@
 	--without-capng		 \
 	--without-macvtap		 \
 	--enable-debug		 \
+	--srcdir=$(CURDIR)       \
 	$(BUILD_XEN)		 \
 	$(BUILD_VBOX)		 \
 	$(BUILD_LXC)
 
 DEB_COMPRESS_EXCLUDE = .o event-test hellolibvirt info1 suspend
 DEB_PYTHON_SETUP_CMD = /dev/null
+DEB_PYTHON_MODULE_PACKAGE = python-libvirt
 DEB_DH_MAKESHLIBS_ARGS_libvirt0 += -V 'libvirt0 (>= 0.5.0)'
 DEB_DH_INSTALLINIT_ARGS = --no-restart-on-upgrade -- defaults 28 72
 DEB_DH_INSTALLLOGROTATE_ARGS = --name=libvirtd
 
 EXAMPLES_DIR = 
$(CURDIR)/debian/libvirt-doc/usr/share/doc/libvirt-doc/examples/
 
+# <<< Python rules <<<
+-include /usr/share/python/python.mk
+ifeq (,$(py_sitename))
+  py_libdir_sh = $$(_py_=$(strip $(1)); python$${_py_\#python*} -c 'from 
distutils import sysconfig; print(sysconfig.get_python_lib())')
+endif
+
+PY_DIR := $(DEB_BUILDDIR)/python
+PYDEFAULTVER := $(shell pyversions --version --default)
+PYVERSIONS := $(shell pyversions --version --installed)
+
+otherpy = \
+	set -e; for v in $(PYVERSIONS); do \
+		$(RM) $(PY_DIR); \
+		ln -sf $(PY_DIR)$$v $(PY_DIR); \
+		$(MAKE) \
+			-C $(PY_DIR) \
+			pyexecdir=$(call py_libdir_sh, $$v) \
+			PYTHON=python$$v \
+			PYTHON_VERSION=$$v \
+			PYTHON_INCLUDES=-I/usr/include/python$$v \
+			$1; \
+		$(RM) $(PY_DIR); \
+	done; \
+	ln -sf $(PY_DIR)$(PYDEFAULTVER) $(PY_DIR)
+
+configure/python-libvirt::
+	set -e; for v in $(PYVERSIONS); do \
+		cp -la $(PY_DIR) $(PY_DIR)$$v; \
+	done
+	$(RM) -r $(PY_DIR)
+	ln -sf $(PY_DIR)$(PYDEFAULTVER) $(PY_DIR)
+
+build/python-libvirt::
+	$(call otherpy, all)
+
+install/python-libvirt::
+	$(call otherpy, install DESTDIR=$(CURDIR)/debian/tmp)
+# >>> Python rules >>>
+
 binary-install/libvirt-bin::
 	cp $(CURDIR)/tools/libvirt-guests.init.sh 
$(CURDIR)/debian/libvirt-bin.libvirt-guests.init
 	cp $(CURDIR)/tools/libvirt-guests.sysconf 
$(CURDIR)/debian/libvirt-bin.libvirt-guests.default
@@ -70,3 +112,5 @@
 clean::
 	rm -f $(CURDIR)/debian/libvirt-bin.libvirt-guests.init
 	rm -f $(CURDIR)/debian/libvirt-bin.libvirt-guests.default
+	$(RM) -r $(DEB_BUILDDIR)
+# vim:set ft=make ts=4 sw=4:

Sincerely
Philipp
-- 
Philipp Hahn           Open Source Software Engineer      hahn at univention.de
Univention GmbH        Linux for Your Business        fon: +49 421 22 232- 0
Mary-Somerville-Str.1  D-28359 Bremen                 fax: +49 421 22 232-99
                                                   http://www.univention.de/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.alioth.debian.org/pipermail/pkg-libvirt-maintainers/attachments/20110810/4616851c/attachment-0001.pgp>


More information about the Pkg-libvirt-maintainers mailing list