[libvirt] [libvirt-python PATCH] setup: Make libvirt API XML path configurable

Adding a support for LIBVIRT_API_PATH evironment variable, which can control where the script should look for the 'libvirt-api.xml' file. This allows building libvirt-python against different libvirt than the one installed in the system. This may be used for example in autotest or by packagers without the need to install libvirt into the system. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- setup.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 17b4722..566c210 100755 --- a/setup.py +++ b/setup.py @@ -109,7 +109,17 @@ class my_build(build): """Check with pkg-config that libvirt is present and extract the API XML file paths we need from it""" - libvirt_api = get_pkgconfig_data(["--variable", "libvirt_api"], "libvirt") + libvirt_api = os.getenv("LIBVIRT_API_PATH") + + if libvirt_api: + if not libvirt_api.endswith("-api.xml"): + raise ValueError("Invalid path '%s' for API XML" % libvirt_api) + if not os.path.exists(libvirt_api): + raise ValueError("API XML '%s' does not exist, " + "have you built libvirt?" % libvirt_api) + else: + libvirt_api = get_pkgconfig_data(["--variable", "libvirt_api"], + "libvirt") offset = libvirt_api.index("-api.xml") libvirt_qemu_api = libvirt_api[0:offset] + "-qemu-api.xml" -- 1.8.4.3

On Tue, Nov 26, 2013 at 10:58:25AM +0100, Martin Kletzander wrote:
Adding a support for LIBVIRT_API_PATH evironment variable, which can control where the script should look for the 'libvirt-api.xml' file. This allows building libvirt-python against different libvirt than the one installed in the system. This may be used for example in autotest or by packagers without the need to install libvirt into the system.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- setup.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/setup.py b/setup.py index 17b4722..566c210 100755 --- a/setup.py +++ b/setup.py @@ -109,7 +109,17 @@ class my_build(build): """Check with pkg-config that libvirt is present and extract the API XML file paths we need from it"""
- libvirt_api = get_pkgconfig_data(["--variable", "libvirt_api"], "libvirt") + libvirt_api = os.getenv("LIBVIRT_API_PATH") + + if libvirt_api: + if not libvirt_api.endswith("-api.xml"): + raise ValueError("Invalid path '%s' for API XML" % libvirt_api) + if not os.path.exists(libvirt_api): + raise ValueError("API XML '%s' does not exist, " + "have you built libvirt?" % libvirt_api) + else: + libvirt_api = get_pkgconfig_data(["--variable", "libvirt_api"], + "libvirt")
offset = libvirt_api.index("-api.xml") libvirt_qemu_api = libvirt_api[0:offset] + "-qemu-api.xml"
NACK, setting pkg-config already takes care of this. See the build-many.sh scrpit attached to this mail which demonstrates use of PKG_CONFIG_PATH to build against every version of libvirt back to 0.9.11 https://www.redhat.com/archives/libvir-list/2013-November/msg00933.html Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Tue, Nov 26, 2013 at 10:14:36AM +0000, Daniel P. Berrange wrote:
On Tue, Nov 26, 2013 at 10:58:25AM +0100, Martin Kletzander wrote:
Adding a support for LIBVIRT_API_PATH evironment variable, which can control where the script should look for the 'libvirt-api.xml' file. This allows building libvirt-python against different libvirt than the one installed in the system. This may be used for example in autotest or by packagers without the need to install libvirt into the system.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- setup.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/setup.py b/setup.py index 17b4722..566c210 100755 --- a/setup.py +++ b/setup.py @@ -109,7 +109,17 @@ class my_build(build): """Check with pkg-config that libvirt is present and extract the API XML file paths we need from it"""
- libvirt_api = get_pkgconfig_data(["--variable", "libvirt_api"], "libvirt") + libvirt_api = os.getenv("LIBVIRT_API_PATH") + + if libvirt_api: + if not libvirt_api.endswith("-api.xml"): + raise ValueError("Invalid path '%s' for API XML" % libvirt_api) + if not os.path.exists(libvirt_api): + raise ValueError("API XML '%s' does not exist, " + "have you built libvirt?" % libvirt_api) + else: + libvirt_api = get_pkgconfig_data(["--variable", "libvirt_api"], + "libvirt")
offset = libvirt_api.index("-api.xml") libvirt_qemu_api = libvirt_api[0:offset] + "-qemu-api.xml"
NACK, setting pkg-config already takes care of this. See the build-many.sh scrpit attached to this mail which demonstrates use of PKG_CONFIG_PATH to build against every version of libvirt back to 0.9.11
This still means you have to configure libvirt with different prefix, install it and then you can use PKG_CONFIG_PATH. This variable (which is unused if unset) makes it easier to use in case you have it built with default prefix etc. It would help me a lot, but if everyone else is OK with installing libvirt in order to build python bindings just to test something, I'll keep this in my git. Martin

Revisiting an older thread On 11/26/2013 07:38 AM, Martin Kletzander wrote:
On Tue, Nov 26, 2013 at 10:14:36AM +0000, Daniel P. Berrange wrote:
On Tue, Nov 26, 2013 at 10:58:25AM +0100, Martin Kletzander wrote:
Adding a support for LIBVIRT_API_PATH evironment variable, which can control where the script should look for the 'libvirt-api.xml' file. This allows building libvirt-python against different libvirt than the one installed in the system. This may be used for example in autotest or by packagers without the need to install libvirt into the system.
- libvirt_api = get_pkgconfig_data(["--variable", "libvirt_api"], "libvirt") + libvirt_api = os.getenv("LIBVIRT_API_PATH") +
NACK, setting pkg-config already takes care of this. See the build-many.sh scrpit attached to this mail which demonstrates use of PKG_CONFIG_PATH to build against every version of libvirt back to 0.9.11
This still means you have to configure libvirt with different prefix, install it and then you can use PKG_CONFIG_PATH. This variable (which is unused if unset) makes it easier to use in case you have it built with default prefix etc. It would help me a lot, but if everyone else is OK with installing libvirt in order to build python bindings just to test something, I'll keep this in my git.
I'm still interested in the ability to test libvirt-python against an uninstalled libvirt tree. Should we revisit this patch, or something like it? -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Wed, Mar 12, 2014 at 11:15:43AM -0600, Eric Blake wrote:
Revisiting an older thread
On 11/26/2013 07:38 AM, Martin Kletzander wrote:
On Tue, Nov 26, 2013 at 10:14:36AM +0000, Daniel P. Berrange wrote:
On Tue, Nov 26, 2013 at 10:58:25AM +0100, Martin Kletzander wrote:
Adding a support for LIBVIRT_API_PATH evironment variable, which can control where the script should look for the 'libvirt-api.xml' file. This allows building libvirt-python against different libvirt than the one installed in the system. This may be used for example in autotest or by packagers without the need to install libvirt into the system.
- libvirt_api = get_pkgconfig_data(["--variable", "libvirt_api"], "libvirt") + libvirt_api = os.getenv("LIBVIRT_API_PATH") +
NACK, setting pkg-config already takes care of this. See the build-many.sh scrpit attached to this mail which demonstrates use of PKG_CONFIG_PATH to build against every version of libvirt back to 0.9.11
This still means you have to configure libvirt with different prefix, install it and then you can use PKG_CONFIG_PATH. This variable (which is unused if unset) makes it easier to use in case you have it built with default prefix etc. It would help me a lot, but if everyone else is OK with installing libvirt in order to build python bindings just to test something, I'll keep this in my git.
I'm still interested in the ability to test libvirt-python against an uninstalled libvirt tree. Should we revisit this patch, or something like it?
I'd be still happy to have this in, especially for us developers. It's useful when testing a libvirt-python patch against upstream libvirt which, in this case, doesn't have to be installed to make the bindings work. Martin

On 03/13/2014 12:03 AM, Martin Kletzander wrote:
On Wed, Mar 12, 2014 at 11:15:43AM -0600, Eric Blake wrote:
Revisiting an older thread
- libvirt_api = get_pkgconfig_data(["--variable", "libvirt_api"], "libvirt") + libvirt_api = os.getenv("LIBVIRT_API_PATH") +
NACK, setting pkg-config already takes care of this. See the build-many.sh scrpit attached to this mail which demonstrates use of PKG_CONFIG_PATH to build against every version of libvirt back to 0.9.11
Is there a way to point pkg-config at an in-tree uninstalled libvirt?
I'd be still happy to have this in, especially for us developers. It's useful when testing a libvirt-python patch against upstream libvirt which, in this case, doesn't have to be installed to make the bindings work.
I played more with it today, and it is not quite enough. LIBVIRT_API_PATH=/path/to/libvirt/src/libvirt-api.xml picks up the in-tree API additions, but still compiles against installed libvirt.h. Which means that if you have added a new API (such as my recent qemu monitor registration), the build correctly warned me if I didn't use LIBVIR_CHECK_VERSION(1,2,3) to protect things, but when I _do_ properly guard things, I'm not actually compile-testing the new code because the installed libvirt.h is from an older vintage. If we are going to do an override (whether by some pkg-config override or by your env-var proposal), then it needs to catch EVERYTHING from the uninstalled tree (both libvirt-api.xml AND libvirt.h). -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Fri, Mar 21, 2014 at 05:00:35PM -0600, Eric Blake wrote:
On 03/13/2014 12:03 AM, Martin Kletzander wrote:
On Wed, Mar 12, 2014 at 11:15:43AM -0600, Eric Blake wrote:
Revisiting an older thread
- libvirt_api = get_pkgconfig_data(["--variable", "libvirt_api"], "libvirt") + libvirt_api = os.getenv("LIBVIRT_API_PATH") +
NACK, setting pkg-config already takes care of this. See the build-many.sh scrpit attached to this mail which demonstrates use of PKG_CONFIG_PATH to build against every version of libvirt back to 0.9.11
Is there a way to point pkg-config at an in-tree uninstalled libvirt?
That's not going to do anything because the .pc file will still point to the install location. You could however create a completely separate libvirt.pc file just for in-tree usage that pointed to stuff in the $build_dir, and then set PKG_CONFNIG_PATH to point to the directory containing that .pc file instead of the real one. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 03/24/2014 03:49 AM, Daniel P. Berrange wrote:
NACK, setting pkg-config already takes care of this. See the build-many.sh scrpit attached to this mail which demonstrates use of PKG_CONFIG_PATH to build against every version of libvirt back to 0.9.11
Is there a way to point pkg-config at an in-tree uninstalled libvirt?
That's not going to do anything because the .pc file will still point to the install location. You could however create a completely separate libvirt.pc file just for in-tree usage that pointed to stuff in the $build_dir, and then set PKG_CONFNIG_PATH to point to the directory containing that .pc file instead of the real one.
Interesting idea; I'll play with it, and if I get it working for my setup, I'll post a patch to the README that demonstrates a sample .pc file for others to tweak. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (3)
-
Daniel P. Berrange
-
Eric Blake
-
Martin Kletzander