Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Require libxml2.
libxml2 is very commonly available on Linux distros and has also been
ported (and is widely available) on Mac OS X and Windows.  Therefore
simply require libxml2, and remove a lot of conditional code.
  • Loading branch information
rwmjones committed Apr 16, 2013
1 parent 349300a commit 2f0a4d7
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 121 deletions.
4 changes: 2 additions & 2 deletions README
Expand Up @@ -98,6 +98,8 @@ The full requirements are described below.
+--------------+-------------+---+-----------------------------------------+
| genisoimage | | R | mkisofs may work. |
+--------------+-------------+---+-----------------------------------------+
| libxml2 | | R | Popular XML library. |
+--------------+-------------+---+-----------------------------------------+
| po4a | |R/O| Required if compiling from git. |
| | | | Optional if compiling from tarball. |
| | | | For localizing man pages. |
Expand All @@ -109,8 +111,6 @@ The full requirements are described below.
| libvirt | | O | >= 0.10.2 is needed if you want to use |
| | | | libvirt to manage transient VMs. |
+--------------+-------------+---+-----------------------------------------+
| libxml2 | | O | Popular XML library. |
+--------------+-------------+---+-----------------------------------------+
| xmllint | | O | Part of libxml2. Used for tests only. |
+--------------+-------------+---+-----------------------------------------+
| libconfig | | O | Used to parse libguestfs's own config |
Expand Down
4 changes: 2 additions & 2 deletions align/scan.c
Expand Up @@ -219,14 +219,14 @@ main (int argc, char *argv[])
* below.
*/
if (drvs == NULL) {
#if defined(HAVE_LIBVIRT) && defined(HAVE_LIBXML2)
#if defined(HAVE_LIBVIRT)
get_all_libvirt_domains (libvirt_uri);
r = start_threads (max_threads, g, scan_work);
free_domains ();
if (r == -1)
exit (EXIT_FAILURE);
#else
fprintf (stderr, _("%s: compiled without support for libvirt and/or libxml2.\n"),
fprintf (stderr, _("%s: compiled without support for libvirt.\n"),
program_name);
exit (EXIT_FAILURE);
#endif
Expand Down
18 changes: 6 additions & 12 deletions configure.ac
Expand Up @@ -850,18 +850,12 @@ AM_CONDITIONAL([HAVE_LIBVIRT],[test "x$LIBVIRT_LIBS" != "x"])
libvirt_ro_uri='qemu+unix:///system?socket=/var/run/libvirt/libvirt-sock-ro'
AC_SUBST([libvirt_ro_uri])

dnl libxml2 (highly recommended)
PKG_CHECK_MODULES([LIBXML2], [libxml-2.0],[
AC_SUBST([LIBXML2_CFLAGS])
AC_SUBST([LIBXML2_LIBS])
AC_DEFINE([HAVE_LIBXML2],[1],[libxml2 found at compile time.])
old_LIBS="$LIBS"
LIBS="$LIBS $LIBXML2_LIBS"
AC_CHECK_FUNCS([xmlBufferDetach])
LIBS="$old_LIBS"
],
[AC_MSG_WARN([libxml2 not found, some core features will be disabled])])
AM_CONDITIONAL([HAVE_LIBXML2],[test "x$LIBXML2_LIBS" != "x"])
dnl libxml2 (required)
PKG_CHECK_MODULES([LIBXML2], [libxml-2.0])
old_LIBS="$LIBS"
LIBS="$LIBS $LIBXML2_LIBS"
AC_CHECK_FUNCS([xmlBufferDetach])
LIBS="$old_LIBS"

dnl libconfig (highly recommended)
PKG_CHECK_MODULES([LIBCONFIG], [libconfig],[
Expand Down
4 changes: 0 additions & 4 deletions df/main.c
Expand Up @@ -30,9 +30,7 @@
#include <assert.h>
#include <libintl.h>

#ifdef HAVE_LIBXML2
#include <libxml/uri.h>
#endif

#ifdef HAVE_LIBVIRT
#include <libvirt/libvirt.h>
Expand Down Expand Up @@ -336,7 +334,6 @@ single_drive_display_name (struct drv *drvs)
exit (EXIT_FAILURE);
}
break;
#ifdef HAVE_LIBXML2
case drv_uri: {
char *p;

Expand All @@ -361,7 +358,6 @@ single_drive_display_name (struct drv *drvs)
}
break;
}
#endif /* HAVE_LIBXML2 */
case drv_d:
name = strdup (drvs->d.guest);
if (name == NULL) {
Expand Down
20 changes: 0 additions & 20 deletions fish/options.c
Expand Up @@ -26,9 +26,7 @@
#include <libintl.h>
#include <getopt.h>

#ifdef HAVE_LIBXML2
#include <libxml/uri.h>
#endif

#include "c-ctype.h"

Expand Down Expand Up @@ -94,8 +92,6 @@ is_uri (const char *arg)
return 1;
}

#ifdef HAVE_LIBXML2

static void
parse_uri (const char *arg, const char *format, struct drv *drv)
{
Expand Down Expand Up @@ -155,18 +151,6 @@ make_server (xmlURIPtr uri)
return ret;
}

#else /* !HAVE_LIBXML2 */

static void
parse_uri (const char *arg, const char *format, struct drv *drv)
{
fprintf (stderr, _("%s: compiled without support for libxml2, so '-a URI' is not allowed\n"),
program_name);
exit (EXIT_FAILURE);
}

#endif /* !HAVE_LIBXML2 */

char
add_drives (struct drv *drv, char next_drive)
{
Expand Down Expand Up @@ -211,7 +195,6 @@ add_drives (struct drv *drv, char next_drive)
next_drive++;
break;

#ifdef HAVE_LIBXML2
case drv_uri:
ad_optargs.bitmask = 0;
if (read_only) {
Expand Down Expand Up @@ -245,7 +228,6 @@ add_drives (struct drv *drv, char next_drive)
drv->nr_drives = 1;
next_drive++;
break;
#endif /* HAVE_LIBXML2 */

case drv_d:
r = add_libvirt_drives (drv->d.guest);
Expand Down Expand Up @@ -351,11 +333,9 @@ free_drives (struct drv *drv)
case drv_a:
/* a.filename and a.format are optargs, don't free them */
break;
#ifdef HAVE_LIBXML2
case drv_uri:
xmlFreeURI (drv->uri.uri);
break;
#endif /* HAVE_LIBXML2 */
case drv_d:
/* d.filename is optarg, don't free it */
break;
Expand Down
6 changes: 0 additions & 6 deletions fish/options.h
Expand Up @@ -21,9 +21,7 @@

#include <getopt.h>

#ifdef HAVE_LIBXML2
#include <libxml/uri.h>
#endif

#include "guestfs-internal-frontend.h"

Expand Down Expand Up @@ -54,9 +52,7 @@ struct drv {

enum {
drv_a, /* -a option (without URI) */
#ifdef HAVE_LIBXML2
drv_uri, /* -a option (with URI) */
#endif
drv_d, /* -d option */
#if COMPILING_GUESTFISH
drv_N, /* -N option (guestfish only) */
Expand All @@ -67,12 +63,10 @@ struct drv {
char *filename; /* disk filename */
const char *format; /* format (NULL == autodetect) */
} a;
#ifdef HAVE_LIBXML2
struct {
xmlURIPtr uri; /* URI */
const char *format; /* format (NULL == autodetect) */
} uri;
#endif
struct {
char *guest; /* guest name */
} d;
Expand Down
4 changes: 0 additions & 4 deletions inspector/Makefile.am
Expand Up @@ -47,8 +47,6 @@ dist_doc_DATA = \
virt-inspector.rng \
$(EXAMPLE_XML)

if HAVE_LIBXML2

bin_PROGRAMS = virt-inspector

SHARED_SOURCE_FILES = \
Expand Down Expand Up @@ -112,8 +110,6 @@ check-valgrind-local-guests:
$(top_builddir)/run --test @VG@ ./virt-inspector -c "$(libvirt_ro_uri)" -d "$$g" || exit $$?; \
done

endif

# These rules require virt-inspector so there is no good time that we
# can run them. Instead you can run them by hand.

Expand Down
2 changes: 0 additions & 2 deletions src/alloc.c
Expand Up @@ -23,11 +23,9 @@
#include <unistd.h>
#include <string.h>

#ifdef HAVE_LIBXML2
#include <libxml/tree.h>
#include <libxml/xpath.h>
#include <libxml/xmlwriter.h>
#endif

#include "guestfs.h"
#include "guestfs-internal.h"
Expand Down
22 changes: 0 additions & 22 deletions src/cleanup.c
Expand Up @@ -23,11 +23,9 @@
#include <unistd.h>
#include <string.h>

#ifdef HAVE_LIBXML2
#include <libxml/tree.h>
#include <libxml/xpath.h>
#include <libxml/xmlwriter.h>
#endif

#include "hash.h"

Expand Down Expand Up @@ -73,64 +71,44 @@ guestfs___cleanup_unlink_free (void *ptr)
void
guestfs___cleanup_xmlBufferFree (void *ptr)
{
#ifdef HAVE_LIBXML2
xmlBufferPtr xb = * (xmlBufferPtr *) ptr;

if (xb)
xmlBufferFree (xb);
#else
abort ();
#endif
}

void
guestfs___cleanup_xmlFreeDoc (void *ptr)
{
#ifdef HAVE_LIBXML2
xmlDocPtr doc = * (xmlDocPtr *) ptr;

if (doc)
xmlFreeDoc (doc);
#else
abort ();
#endif
}

void
guestfs___cleanup_xmlFreeTextWriter (void *ptr)
{
#ifdef HAVE_LIBXML2
xmlTextWriterPtr xo = * (xmlTextWriterPtr *) ptr;

if (xo)
xmlFreeTextWriter (xo);
#else
abort ();
#endif
}

void
guestfs___cleanup_xmlXPathFreeContext (void *ptr)
{
#ifdef HAVE_LIBXML2
xmlXPathContextPtr ctx = * (xmlXPathContextPtr *) ptr;

if (ctx)
xmlXPathFreeContext (ctx);
#else
abort ();
#endif
}

void
guestfs___cleanup_xmlXPathFreeObject (void *ptr)
{
#ifdef HAVE_LIBXML2
xmlXPathObjectPtr obj = * (xmlXPathObjectPtr *) ptr;

if (obj)
xmlXPathFreeObject (obj);
#else
abort ();
#endif
}
6 changes: 2 additions & 4 deletions src/guestfs-internal-frontend.h
Expand Up @@ -111,11 +111,9 @@ extern void guestfs___cleanup_xmlXPathFreeObject (void *ptr);
*/
#include "guestfs-internal-frontend-cleanups.h"

#if defined(HAVE_LIBVIRT) && defined(HAVE_LIBXML2)
#if defined(HAVE_LIBVIRT)

#ifdef HAVE_LIBVIRT
#include <libvirt/libvirt.h>
#endif

/* This was proposed as an external API, but there's a problem: the
* generator is unable to bind a virDomainPtr in any language other
Expand All @@ -138,7 +136,7 @@ struct guestfs___add_libvirt_dom_argv {

extern GUESTFS_DLL_PUBLIC int guestfs___add_libvirt_dom (guestfs_h *g, virDomainPtr dom, const struct guestfs___add_libvirt_dom_argv *optargs);

#endif /* HAVE_LIBVIRT && HAVE_LIBXML2 */
#endif /* HAVE_LIBVIRT */

/* Current program name. Note <errno.h> must be included in all files
* that want to use 'program_name'.
Expand Down
11 changes: 3 additions & 8 deletions src/handle.c
Expand Up @@ -28,10 +28,8 @@
#include <libvirt/libvirt.h>
#endif

#ifdef HAVE_LIBXML2
#include <libxml/parser.h>
#include <libxml/xmlversion.h>
#endif

#include "glthread/lock.h"
#include "ignore-value.h"
Expand Down Expand Up @@ -61,19 +59,16 @@ static void init_libguestfs (void) __attribute__((constructor));
static void
init_libguestfs (void)
{
#if defined(HAVE_LIBVIRT) || defined(HAVE_LIBXML2)
gl_lock_lock (init_lock);
#endif

#ifdef HAVE_LIBVIRT
virInitialize ();
#endif
#ifdef HAVE_LIBXML2

xmlInitParser ();
LIBXML_TEST_VERSION;
#endif
#if defined(HAVE_LIBVIRT) || defined(HAVE_LIBXML2)

gl_lock_unlock (init_lock);
#endif
}

guestfs_h *
Expand Down
11 changes: 4 additions & 7 deletions src/launch-libvirt.c
Expand Up @@ -36,14 +36,12 @@
#include <libvirt/virterror.h>
#endif

#ifdef HAVE_LIBXML2
#include <libxml/xmlIO.h>
#include <libxml/xmlwriter.h>
#include <libxml/xpath.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlsave.h>
#endif

#if HAVE_LIBSELINUX
#include <selinux/selinux.h>
Expand Down Expand Up @@ -73,8 +71,7 @@
MIN_LIBVIRT_MICRO)

#if defined(HAVE_LIBVIRT) && \
LIBVIR_VERSION_NUMBER >= MIN_LIBVIRT_VERSION && \
defined(HAVE_LIBXML2)
LIBVIR_VERSION_NUMBER >= MIN_LIBVIRT_VERSION

#ifndef HAVE_XMLBUFFERDETACH
/* Added in libxml2 2.8.0. This is mostly a copy of the function from
Expand Down Expand Up @@ -1810,12 +1807,12 @@ struct backend_ops backend_ops_libvirt = {
.hot_remove_drive = hot_remove_drive_libvirt,
};

#else /* no libvirt or libxml2 at compile time */
#else /* no libvirt at compile time */

#define NOT_IMPL(r) \
error (g, _("libvirt backend is not available because " \
"this version of libguestfs was compiled " \
"without libvirt or libvirt < %d.%d.%d or without libxml2"), \
"without libvirt or libvirt < %d.%d.%d"), \
MIN_LIBVIRT_MAJOR, MIN_LIBVIRT_MINOR, MIN_LIBVIRT_MICRO); \
return r

Expand Down Expand Up @@ -1843,7 +1840,7 @@ struct backend_ops backend_ops_libvirt = {
.max_disks = max_disks_libvirt,
};

#endif /* no libvirt or libxml2 at compile time */
#endif /* no libvirt at compile time */

int
guestfs__internal_set_libvirt_selinux_label (guestfs_h *g, const char *label,
Expand Down

0 comments on commit 2f0a4d7

Please sign in to comment.