]> xenbits.xensource.com Git - libvirt.git/commitdiff
hvsupport: use a regex instead of XML::XPath
authorJán Tomko <jtomko@redhat.com>
Tue, 28 Jun 2016 11:28:48 +0000 (13:28 +0200)
committerJán Tomko <jtomko@redhat.com>
Tue, 19 Jul 2016 16:42:44 +0000 (18:42 +0200)
When generating the hvsupport.html.in file, we parse the -api.xml
files generated by apibuild.py to know in which HTML file the API
function is.

Doing an XPath query for every single 'function' element in the
file is inefficient.

Since the XML file is generated by another of our build scripts
(apibuild.py, using Python's standard 'output.write' XML library),
just find the function name->file mapping by a regex upfront.

Also add a note about this next to the line that generates it
in apibuild.py and do not check if XML::XPath is installed in
bootstrap since we no longer use it.

bootstrap.conf
docs/apibuild.py
docs/hvsupport.pl

index edea8c33b157dd9d73e59ac0bb94c794c6217688..0bfa7941f6fea4052e1d3efbdbdc5e282450ecd3 100644 (file)
@@ -209,7 +209,6 @@ gzip       -
 libtool    -
 patch      -
 perl       5.5
-perl::XML::XPath -
 pkg-config -
 rpcgen     -
 tar        -
index f5216ea930e5e268e48917f834d989d6bbfeb302..8728b270ba620d54746d52797d0b3e6d140e704d 100755 (executable)
@@ -2267,6 +2267,7 @@ class docBuilder:
         if name == debugsym and not quiet:
             print "=>", id
 
+        # NB: this is consumed by a regex in 'getAPIFilenames' in hvsupport.pl
         output.write("    <%s name='%s' file='%s' module='%s'>\n" % (id.type,
                      name, self.modulename_file(id.header),
                      self.modulename_file(id.module)))
index 7a6f1acdb445e84f64d9a85388b0e12316c1587f..7dd7c3f64c63b0a7c11b204b37dd215ce3e5769d 100755 (executable)
@@ -4,8 +4,6 @@ use strict;
 use warnings;
 
 use File::Find;
-use XML::XPath;
-use XML::XPath::XMLParser;
 
 die "syntax: $0 SRCDIR\n" unless int(@ARGV) == 1;
 
@@ -45,6 +43,32 @@ find({
         }
     }, no_chdir => 1}, $srcdir);
 
+# Map API functions to the header and documentation files they're in
+# so that we can generate proper hyperlinks to their documentation.
+#
+# The function names are grep'd from the XML output of apibuild.py.
+sub getAPIFilenames {
+    my $filename = shift;
+
+    my %files;
+    my $line;
+
+    open FILE, "<", $filename or die "cannot read $filename: $!";
+
+    while (defined($line = <FILE>)) {
+        if ($line =~ /function name='([^']+)' file='([^']+)'/) {
+            $files{$1} = $2;
+        }
+    }
+
+    close FILE;
+
+    if (keys %files == 0) {
+        die "No functions found in $filename. Has the apibuild.py output changed?";
+    }
+    return \%files;
+}
+
 sub parseSymsFile {
     my $apisref = shift;
     my $prefix = shift;
@@ -55,7 +79,7 @@ sub parseSymsFile {
     my $vers;
     my $prevvers;
 
-    my $apixpath = XML::XPath->new(filename => $xmlfilename);
+    my $filenames = getAPIFilenames($xmlfilename);
 
     open FILE, "<$filename"
         or die "cannot read $filename: $!";
@@ -83,10 +107,9 @@ sub parseSymsFile {
             $prevvers = $vers;
             $vers = undef;
         } elsif ($line =~ /\s*(\w+)\s*;\s*$/) {
-            my $file = $apixpath->find("/api/symbols/function[\@name='$1']/\@file");
             $$apisref{$1} = {};
             $$apisref{$1}->{vers} = $vers;
-            $$apisref{$1}->{file} = $file;
+            $$apisref{$1}->{file} = $$filenames{$1};
         } else {
             die "unexpected data $line\n";
         }