aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-08-26 15:26:43 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-08-26 15:26:43 +0000
commita3a0c7d4578da64b6377c9baccd3d92b5c26eda8 (patch)
tree2558f7208a8a55054d748a04de5c4e430a718263
parentd8e6d8e98b1316685f05c7cf5d3da604016459af (diff)
downloadpaludis-a3a0c7d4578da64b6377c9baccd3d92b5c26eda8.tar.gz
paludis-a3a0c7d4578da64b6377c9baccd3d92b5c26eda8.tar.xz
Use libxml2 directly rather than calling xmllint for QA checks
-rw-r--r--configure.ac3
-rw-r--r--paludis/qa/Makefile.am.m45
-rw-r--r--paludis/qa/metadata_check.cc52
-rw-r--r--src/qualudis/Makefile.am3
4 files changed, 49 insertions, 14 deletions
diff --git a/configure.ac b/configure.ac
index 5f93bbf..42bef8c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -377,6 +377,9 @@ if test x"$ENABLE_QA" = "xyes" ; then
else
AC_MSG_ERROR([pcre++ (http://www.daemon.de/PCRE) is required if --enable-qa is used])
fi
+ PKG_CHECK_MODULES(LIBXML2DEPS, [libxml-2.0 >= 2.6])
+ AC_SUBST(LIBXML2DEPS_CFLAGS)
+ AC_SUBST(LIBXML2DEPS_LIBS)
fi
AC_SUBST([ENABLE_QA])
AM_CONDITIONAL([ENABLE_QA], test "x$ENABLE_QA" = "xyes")
diff --git a/paludis/qa/Makefile.am.m4 b/paludis/qa/Makefile.am.m4
index 93219fe..fc73050 100644
--- a/paludis/qa/Makefile.am.m4
+++ b/paludis/qa/Makefile.am.m4
@@ -19,7 +19,8 @@ $1_TEST_LDADD = \
$(top_builddir)/paludis/libpaludis.la \
$(top_builddir)/paludis/util/libpaludisutil.la \
$(DYNAMIC_LD_LIBS) \
- $(PCREPLUSPLUS_LIBS)
+ $(PCREPLUSPLUS_LIBS) \
+ $(LIBXML2DEPS_LIBS)
$1_TEST_CXXFLAGS = -I$(top_srcdir)
')dnl
define(`addtestscript', `define(`testscriptlist', testscriptlist `$1_TEST_setup.sh $1_TEST_cleanup.sh')')dnl
@@ -50,7 +51,7 @@ include(`paludis/qa/files.m4')
if ENABLE_QA
-INCLUDES = $(PCREPLUSPLUS_CFLAGS)
+INCLUDES = $(PCREPLUSPLUS_CFLAGS) $(LIBXML2DEPS_CFLAGS)
libpaludisqa_la_SOURCES = filelist
libpaludisqa_la_LDFLAGS = -version-info @VERSION_LIB_CURRENT@:@VERSION_LIB_REVISION@:0
diff --git a/paludis/qa/metadata_check.cc b/paludis/qa/metadata_check.cc
index 2c8128c..266c3f8 100644
--- a/paludis/qa/metadata_check.cc
+++ b/paludis/qa/metadata_check.cc
@@ -22,10 +22,23 @@
#include <paludis/qa/metadata_check.hh>
#include <paludis/util/pstream.hh>
#include <paludis/util/system.hh>
+#include <paludis/util/log.hh>
+
+#include <libxml/tree.h>
+#include <libxml/parser.h>
+
+#if !defined(LIBXML_XPATH_ENABLED) || !defined(LIBXML_SAX1_ENABLED)
+# error "Need libxml2 built with SAX and XPath."
+#endif
using namespace paludis;
using namespace paludis::qa;
+namespace
+{
+
+}
+
MetadataCheck::MetadataCheck()
{
}
@@ -43,11 +56,16 @@ MetadataCheck::operator() (const FSEntry & f) const
{
FSEntry dtd(FSEntry(getenv_or_error("HOME")) / ".qualudis");
if (! dtd.exists())
- throw ConfigurationError("~/.qualudis/ does not exist, please create it");
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context, "Creating ~/.qualudis "
+ "with mode 0755");
+ if (! dtd.mkdir(0755))
+ throw ConfigurationError("~/.qualudis/ does not exist, please create it");
+ }
dtd /= "cache";
if (! dtd.exists())
- if (0 != dtd.mkdir(0755))
+ if (! dtd.mkdir(0755))
throw ConfigurationError("~/.qualudis/cache/ does not exist and cannot be created");
dtd /= "metadata.dtd";
@@ -68,15 +86,27 @@ MetadataCheck::operator() (const FSEntry & f) const
"' -- you should remove this file manually before continuing");
}
- PStream xmllint("xmllint --noout --nonet --dtdvalid '"
- + stringify(dtd) + "' '" + stringify(f) + "' 2>&1");
-
- std::string s;
- while (std::getline(xmllint, s))
- ;
-
- if (0 != xmllint.exit_status())
- result << Message(qal_major, "XML validation failed");
+ xmlParserCtxtPtr xml_parser_context(xmlNewParserCtxt());
+ xmlDtdPtr xml_dtd(xmlParseDTD(0, reinterpret_cast<const xmlChar *>(stringify(dtd).c_str())));
+ if (! xml_dtd)
+ result << Message(qal_major, "Unable to parse DTD '" + stringify(dtd) + "'");
+ else
+ {
+ xmlDocPtr xml_doc(xmlCtxtReadFile(xml_parser_context, stringify(f).c_str(), 0, XML_PARSE_DTDLOAD));
+ if (! xml_doc)
+ result << Message(qal_major, "Unable to parse '" + stringify(f) + "'");
+ else
+ {
+ xmlValidCtxtPtr xml_valid_context(xmlNewValidCtxt());
+ if (! xmlValidateDtd(xml_valid_context, xml_doc, xml_dtd))
+ result << Message(qal_major, "Validation of '" + stringify(f) + "' against '"
+ + stringify(dtd) + "' failed");
+ xmlFreeValidCtxt(xml_valid_context);
+ xmlFreeDoc(xml_doc);
+ }
+ xmlFreeDtd(xml_dtd);
+ }
+ xmlFreeParserCtxt(xml_parser_context);
}
return result;
diff --git a/src/qualudis/Makefile.am b/src/qualudis/Makefile.am
index d2d8415..a160edd 100644
--- a/src/qualudis/Makefile.am
+++ b/src/qualudis/Makefile.am
@@ -24,9 +24,10 @@ qualudis_LDADD = \
$(top_builddir)/paludis/util/libpaludisutil.la \
$(top_builddir)/src/libcolour.a \
$(PCREPLUSPLUS_LIBS) \
+ $(LIBXML2DEPS_LIBS) \
$(DYNAMIC_LD_LIBS)
-INCLUDES = $(PCREPLUSPLUS_CFLAGS)
+INCLUDES = $(PCREPLUSPLUS_CFLAGS) $(LIBXML2DEPS_CFLAGS)
TESTS_ENVIRONMENT = env \
TEST_SCRIPT_DIR="$(srcdir)/" \