[gtk-doc] index.sgml: stop generating index.sgml files



commit 3a3d70d24217c2ea7197d50363ea82908e3d5473
Author: Stefan Sauer <ensonic users sf net>
Date:   Wed Jun 17 22:53:43 2015 +0200

    index.sgml: stop generating index.sgml files
    
    Use the data from devhelp2 files. Saves diskspace and makes the html phase about 10% faster.
    Fixes #742404

 devhelp2.xsd                    |    7 ++++
 devhelp2.xsl                    |    8 ++++-
 gtk-doc.xsl                     |   48 +-------------------------
 gtkdoc-fixxref.in               |   55 ++++++++++++++++++++++-------
 gtkdoc-rebase.in                |   72 ++++++++++++++++++++++++++++++++++----
 tests/fail/docs/tester-docs.xml |    2 -
 tests/sanity.sh                 |   22 ------------
 7 files changed, 121 insertions(+), 93 deletions(-)
---
diff --git a/devhelp2.xsd b/devhelp2.xsd
index b90d2ad..fc001a1 100644
--- a/devhelp2.xsd
+++ b/devhelp2.xsd
@@ -204,6 +204,13 @@ xsltproc -o devhelp2.xsd.html $HOME/download/xs3p-1.1.3/xs3p.xsl devhelp2.xsd
           </xsd:documentation>
         </xsd:annotation>
       </xsd:attribute>
+      <xsd:attribute name="online" type="xsd:string">
+        <xsd:annotation>
+          <xsd:documentation>
+            URL for the online version of the docs.
+          </xsd:documentation>
+        </xsd:annotation>
+      </xsd:attribute>
     </xsd:complexType>
   </xsd:element>
 </xsd:schema>
diff --git a/devhelp2.xsl b/devhelp2.xsl
index c832034..db7e2a0 100644
--- a/devhelp2.xsl
+++ b/devhelp2.xsl
@@ -43,14 +43,20 @@
                              select="articleinfo|bookinfo"/>
       </xsl:if>
     </xsl:variable>
+    <xsl:variable name="online">
+      <xsl:value-of select="/book/bookinfo/releaseinfo/ulink[ role='online-location']/@url"/>
+    </xsl:variable>
     <xsl:variable name="toc.nodes" select="part|reference|preface|chapter|
                                            appendix|article|bibliography|
                                            glossary|index|refentry|
                                            bridgehead|sect1"/>
 
     <book title="{$title}" link="{$link}" author="{$author}" name="{$gtkdoc.bookname}" version="2" 
language="c">
+      <xsl:if test="$online != ''">
+        <xsl:attribute name="online"><xsl:value-of select="$online"/></xsl:attribute>
+      </xsl:if>
       <xsl:if test="$toc.nodes">
-        <chapters>
+        <chapters>                                    
           <xsl:apply-templates select="$toc.nodes"
                                mode="generate.devhelp2.toc.mode"/>
         </chapters>
diff --git a/gtk-doc.xsl b/gtk-doc.xsl
index f0b6f9d..d7d69ab 100644
--- a/gtk-doc.xsl
+++ b/gtk-doc.xsl
@@ -315,56 +315,10 @@ Get a newer version at http://docbook.sourceforge.net/projects/xsl/
     </xsl:if>
     <xsl:apply-imports/>
 
-    <!-- generate the index.sgml href index -->
-    <xsl:call-template name="generate.index"/>
     <!-- generate $book.devhelp2 -->
     <xsl:call-template name="generate.devhelp2"/>
   </xsl:template>
 
-  <xsl:template name="generate.index">
-    <xsl:call-template name="write.text.chunk">
-      <xsl:with-param name="filename" select="'index.sgml'"/>
-      <xsl:with-param name="content">
-        <xsl:apply-templates select="/book/bookinfo/releaseinfo/ulink"
-                             mode="generate.index.mode"/>
-        <!-- check all anchor and refentry elements -->
-       <!--
-           The obvious way to write this is //anchor|//refentry|etc...
-           The obvious way is slow because it causes multiple traversals
-           in libxslt. This take about half the time.
-       -->
-       <xsl:apply-templates select="//*[name()='anchor' or name()='refentry' or name()='refsect1' or
-                                        name() = 'refsect2' or name()='refsynopsisdiv' or
-                                        name()='varlistentry' or name()='para']"
-                             mode="generate.index.mode"/>
-      </xsl:with-param>
-      <xsl:with-param name="default.encoding" select="'UTF-8'"/>
-      <xsl:with-param name="chunker.output.indent" select="'no'"/>
-    </xsl:call-template>
-  </xsl:template>
-
-  <xsl:template match="*" mode="generate.index.mode">
-    <xsl:if test="not(@href) and count(@id) > 0">
-      <xsl:text>&lt;ANCHOR id=&quot;</xsl:text>
-      <xsl:value-of select="@id"/>
-      <xsl:text>&quot; href=&quot;</xsl:text>
-        <xsl:if test="$gtkdoc.bookname">
-          <xsl:value-of select="$gtkdoc.bookname"/>
-          <xsl:text>/</xsl:text>
-        </xsl:if>
-        <xsl:call-template name="href.target"/>
-        <xsl:text>&quot;&gt;&#10;</xsl:text>
-    </xsl:if>
-  </xsl:template>
-
-  <xsl:template match="/book/bookinfo/releaseinfo/ulink" mode="generate.index.mode">
-    <xsl:if test="@role='online-location'">
-      <xsl:text>&lt;ONLINE href=&quot;</xsl:text>
-      <xsl:value-of select="@url"/>
-      <xsl:text>&quot;&gt;&#10;</xsl:text>
-    </xsl:if>
-  </xsl:template>
-
   <!-- ========================================================= -->
   <!-- template to output gtkdoclink elements for the unknown targets -->
 
@@ -867,7 +821,7 @@ Get a newer version at http://docbook.sourceforge.net/projects/xsl/
         <a>
           <xsl:attribute name="href">
             <xsl:text>http://foldoc.org/</xsl:text>
-               <xsl:value-of select="$acronym"/>
+                 <xsl:value-of select="$acronym"/>
           </xsl:attribute>
           <xsl:call-template name="inline.charseq"/>
         </a>
diff --git a/gtkdoc-fixxref.in b/gtkdoc-fixxref.in
index 9831687..ed7dc3c 100755
--- a/gtkdoc-fixxref.in
+++ b/gtkdoc-fixxref.in
@@ -200,11 +200,27 @@ sub ScanIndices {
             next;
         } elsif (-d "$scan_dir/$file") {
             push (@subdirs, $file);
-        } elsif ($file eq "index.sgml") {
-            &ScanIndex ("$scan_dir/$file", $use_absolute_links);
+            next;
+        }
+        if ($file =~ m/\.devhelp2$/) {
+            # if devhelp-file is good don't read index.sgml
+            &ReadDevhelp ("$scan_dir/$file", $use_absolute_links);
+        }
+        elsif ($file eq "index.sgml.gz") {
+            # debian/ubuntu started to compress this as index.sgml.gz :/
+            print <<EOF;
+Please fix https://bugs.launchpad.net/ubuntu/+source/gtk-doc/+bug/77138 . For now run:
+gunzip $file
+EOF
+        }
+        elsif ($file =~ m/\.devhelp2.gz$/) {
+            # debian/ubuntu started to compress this as *devhelp2.gz :/
+            print <<EOF;
+Please fix https://bugs.launchpad.net/ubuntu/+source/gtk-doc/+bug/1466210 . For now run:
+gunzip $file
+EOF
         }
-        # ubuntu started to compress this as index.sgml.gz :/
-        # https://bugs.launchpad.net/ubuntu/+source/gtk-doc/+bug/77138
+        # we could consider supporting: use IO::Zlib;
     }
     closedir (HTMLDIR);
 
@@ -216,31 +232,38 @@ sub ScanIndices {
 }
 
 
-sub ScanIndex {
+sub ReadDevhelp {
     my ($file, $use_absolute_links) = @_;
 
-    # Determine the absolute directory, to be added to links in index.sgml
+    # Determine the absolute directory, to be added to links in $file
     # if we need to use an absolute link.
-    # $file will be something like /opt/gnome/share/gtk-doc/html/gtk/index.sgml
-    # We want the part up to 'html' since the links in index.sgml include
+    # $file will be something like /prefix/gnome/share/gtk-doc/html/gtk/$file
+    # We want the part up to 'html/.*' since the links in $file include
     # the rest.
     my $dir = "../";
     if ($use_absolute_links) {
         # For uninstalled index.sgml files we'd need to map the path to where it
         # will be installed to
         if ($file !~ /\.\//) {
-          $file =~ /(.*\/)(.*?)\/index\.sgml/;
-          $dir = $1;
+            $file =~ /(.*\/)(.*?)\/.*?\.devhelp2/;
+            $dir = "$1$2";
+        }
+    } else {
+        if ($file =~ /(.*\/)(.*?)\/.*?\.devhelp2/) {
+            $dir .= "$2/";
+        } else {
+            $dir = "";
         }
     }
+
     @TRACE@("Scanning index file=$file, absolute=$use_absolute_links, dir=$dir");
 
     open (INDEXFILE, $file)
         || die "Can't open $file: $!";
     while (<INDEXFILE>) {
-        if (m/^<ANCHOR\s+id\s*=\s*"([^"]*)"\s+href\s*=\s*"([^"]*)"\s*>/) {
-            @TRACE@("Found id: $1 href: $2");
-            $Links{$1} = "$dir$2";
+        if (m/ link="([^#]*)#([^"]*)"/) {
+            @TRACE@("Found id: $2 href: $1#$2");
+            $Links{$2} = "$dir$1#$2";
         }
     }
     close (INDEXFILE);
@@ -369,6 +392,12 @@ sub MakeXRef {
         my $tid = $id;
         $tid =~ s/s$//g;
         $href = $Links{$tid};
+        if (!$href && defined $Links{"$tid-struct"}) {
+            $href = $Links{"$tid-struct"};
+        }
+    }
+    if (!$href && defined $Links{"$id-struct"}) {
+        $href = $Links{"$id-struct"};
     }
 
     if ($href) {
diff --git a/gtkdoc-rebase.in b/gtkdoc-rebase.in
index 202a348..abade25 100644
--- a/gtkdoc-rebase.in
+++ b/gtkdoc-rebase.in
@@ -155,21 +155,50 @@ sub ScanDirectory {
     }
 
     my $file;
+    my $onlinedir;
+    my $have_index = 0;
     foreach $file (readdir(HTMLDIR)) {
         if ($file eq '.' or $file eq '..') {
             next;
         }
         elsif (-d "$dir/$file") {
             push @subdirs, $file;
+            next;
+        }
+        if ($file =~ m/\.devhelp2$/) {
+            print "Reading index from $file\n" if $VERBOSE;
+            my $o = &ReadDevhelp($dir, $file);
+            # Prefer this location over possibly stale index.sgml
+            if ($o) {
+                $onlinedir = $o;
+            }
+            $have_index = 1;
         }
-        elsif ($file eq "index.sgml") {
-            &AddMap($dir);
+        if (!$onlinedir and ($file eq "index.sgml")) {
+            print "Reading index from index.sgml\n" if $VERBOSE;
+            $onlinedir = &ReadIndex($dir, $file);
+            $have_index = 1;
         }
         elsif ($file eq "index.sgml.gz") {
-            print "Please fix https://bugs.launchpad.net/ubuntu/+source/gtk-doc/+bug/77138\n";;
+            # debian/ubuntu started to compress this as index.sgml.gz :/
+            print <<EOF;
+Please fix https://bugs.launchpad.net/ubuntu/+source/gtk-doc/+bug/77138 . For now run:
+gunzip $file
+EOF
+        }
+        elsif ($file =~ m/\.devhelp2.gz$/) {
+            # debian/ubuntu started to compress this as *devhelp2.gz :/
+            print <<EOF;
+Please fix https://bugs.launchpad.net/ubuntu/+source/gtk-doc/+bug/1466210 . For now run:
+gunzip $file
+EOF
         }
+        # we could consider supporting: use IO::Zlib;
     }
     closedir (HTMLDIR);
+    if ($have_index) {
+        &AddMap($dir, $onlinedir);
+    }
 
     # Now recursively scan the subdirectories.
     my $d;
@@ -179,12 +208,30 @@ sub ScanDirectory {
 }
 
 
-sub AddMap {
-    my ($dir) = @_;
-    my $file = "$dir/index.sgml";
-    my ($onlinedir, $package);
+sub ReadDevhelp {
+    my ($dir, $file) = @_;
+    my $onlinedir;
+
+    open(INDEXFILE, "$dir/$file") || die "Can't open $dir/$file: $!";
+    while (<INDEXFILE>) {
+        # online must come before chapter/functions
+        last if m/<(chapters|functions)/;
+        if (m/ online="([^"]*)"/) {
+            $onlinedir = $1;
+            # Remove trailing non-directory component.
+            $onlinedir =~ s#(.*/).*#$1#;
+        }
+    }
+    close (INDEXFILE);
+    return $onlinedir;
+}
 
-    open(INDEXFILE, $file) || die "Can't open $file: $!";
+
+sub ReadIndex {
+    my ($dir, $file) = @_;
+    my $onlinedir;
+
+    open(INDEXFILE, "$dir/$file") || die "Can't open $dir/$file: $!";
     while (<INDEXFILE>) {
         # ONLINE must come before any ANCHORs
         last if m/^<ANCHOR/;
@@ -195,6 +242,13 @@ sub AddMap {
         }
     }
     close (INDEXFILE);
+    return $onlinedir;
+}
+
+
+sub AddMap {
+    my ($dir, $onlinedir) = @_;
+    my $package;
 
     $dir =~ s#/?$#/#;
     ($package = $dir) =~ s#.*/([^/]+)/#$1#;
@@ -205,6 +259,8 @@ sub AddMap {
         print "On-line location of $package: $onlinedir\n" if $VERBOSE;
         $OnlineMap{ $package } = $onlinedir;
         $RevMap{ $onlinedir } = $package;
+    } else {
+        print "No On-line location for $package found\n" if $VERBOSE;
     }
     print "Local location of $package: $dir\n" if $VERBOSE;
     $LocalMap{ $package } = $dir;
diff --git a/tests/fail/docs/tester-docs.xml b/tests/fail/docs/tester-docs.xml
index d7ceb6c..f8b4bbc 100644
--- a/tests/fail/docs/tester-docs.xml
+++ b/tests/fail/docs/tester-docs.xml
@@ -9,8 +9,6 @@
     <title>tester Reference Manual</title>
     <releaseinfo>
       for tester [VERSION].
-      The latest version of this documentation can be found on-line at
-      <ulink role="online-location" url="http://[SERVER]/tester/index.html";>http://[SERVER]/tester/</ulink>.
     </releaseinfo>
   </bookinfo>
 
diff --git a/tests/sanity.sh b/tests/sanity.sh
index 6b03bf9..24b6d95 100755
--- a/tests/sanity.sh
+++ b/tests/sanity.sh
@@ -16,10 +16,6 @@ for path in $dir/*/docs*/html; do
     echo 1>&2 "no or empty $path/index.html"
     nok=`expr $nok + 1`; break;
   fi
-  if test ! -s $path/index.sgml ; then
-    echo 1>&2 "no or empty $path/index.sgml"
-    nok=`expr $nok + 1`; break;
-  fi
   if test ! -s $path/home.png ; then
     echo 1>&2 "no or empty $path/home.png"
     nok=`expr $nok + 1`; break;
@@ -34,24 +30,6 @@ if test $nok -gt 0 ; then failed=`expr $failed + 1`; fi
 tested=`expr $tested + 1`
 
 
-# check online/anchor tags
-nok=0
-for file in $dir/*/docs*/html/index.sgml; do
-  grep >/dev/null "<ONLINE href=" $file
-  if test $? = 1 ; then
-    echo 1>&2 "missing ONLINE reference in $file"
-    nok=`expr $nok + 1`; break;
-  fi
-  grep >/dev/null "<ANCHOR id=" $file
-  if test $? = 1 ; then
-    echo 1>&2 "missing ANCHOR reference in $file"
-    nok=`expr $nok + 1`; break;
-  fi
-done
-if test $nok -gt 0 ; then failed=`expr $failed + 1`; fi
-tested=`expr $tested + 1`
-
-
 # check validity of generated xml files
 nok=0
 for file in $dir/*/docs*/xml/*.xml; do


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]