makedocs.pl 4.28 KB
Newer Older
1
#!/usr/bin/perl
2 3 4
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
#
6 7
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
8 9

# This script compiles all the documentation.
10 11 12 13 14
#
# Required software:
#
# 1) Sphinx documentation builder (python-sphinx package on Debian/Ubuntu)
#
15 16 17 18 19 20 21
# 2a) rst2pdf
# or
# 2b) pdflatex, which means the following Debian/Ubuntu packages:
#     * texlive-latex-base
#     * texlive-latex-recommended
#     * texlive-latex-extra
#     * texlive-fonts-recommended
22 23 24
#
# All these TeX packages together are close to a gig :-| But after you've
# installed them, you can remove texlive-latex-extra-doc to save 400MB.
25

26
use 5.10.1;
27
use strict;
28
use warnings;
29

30
use File::Basename;
31
BEGIN { chdir dirname($0); }
32

33
use lib qw(.. ../lib lib);
34

35 36 37
use Cwd;
use File::Copy::Recursive qw(rcopy);
use File::Find;
38
use File::Path qw(rmtree make_path);
39
use File::Which qw(which);
40 41 42 43 44
use Pod::Simple;

use Bugzilla::Constants qw(BUGZILLA_VERSION bz_locations);
use Pod::Simple::HTMLBatch::Bugzilla;
use Pod::Simple::HTML::Bugzilla;
45

46 47 48 49
###############################################################################
# Subs
###############################################################################

50
my $error_found = 0;
51

52
sub MakeDocs {
53
  my ($name, $cmdline) = @_;
54

55 56 57
  say "Creating $name documentation ..." if defined $name;
  system('make', $cmdline) == 0 or $error_found = 1;
  print "\n";
58 59
}

60
sub make_pod {
61 62 63
  say "Creating API documentation...";

  my $converter = Pod::Simple::HTMLBatch::Bugzilla->new;
64

65 66 67
  # Don't output progress information.
  $converter->verbose(0);
  $converter->html_render_class('Pod::Simple::HTML::Bugzilla');
68

69 70 71
  my $doctype      = Pod::Simple::HTML::Bugzilla->DOCTYPE;
  my $content_type = Pod::Simple::HTML::Bugzilla->META_CT;
  my $bz_version   = BUGZILLA_VERSION;
72

73
  my $contents_start = <<END_HTML;
74 75 76 77 78 79 80 81 82 83
$doctype
<html>
  <head>
    $content_type
    <title>Bugzilla $bz_version API Documentation</title>
  </head>
  <body class="contentspage">
    <h1>Bugzilla $bz_version API Documentation</h1>
END_HTML

84 85 86 87 88 89 90
  $converter->contents_page_start($contents_start);
  $converter->contents_page_end("</body></html>");
  $converter->add_css('./../../../../style.css');
  $converter->javascript_flurry(0);
  $converter->css_flurry(0);
  make_path('html/integrating/api');
  $converter->batch_convert(['../../'], 'html/integrating/api');
91

92
  print "\n";
93 94
}

95 96 97 98
###############################################################################
# Make the docs ...
###############################################################################

99
my @langs;
100

101
# search for sub directories which have a 'rst' sub-directory
102 103
opendir(LANGS, './');
foreach my $dir (readdir(LANGS)) {
104 105 106 107
  next if (($dir eq '.') || ($dir eq '..') || (!-d $dir));
  if (-d "$dir/rst") {
    push(@langs, $dir);
  }
108
}
109 110 111 112
closedir(LANGS);

my $docparent = getcwd();
foreach my $lang (@langs) {
113
  chdir "$docparent/$lang";
114

115
  make_pod();
116

117
  next if grep { $_ eq '--pod-only' } @ARGV;
118

119
  chdir $docparent;
120

121 122 123 124 125 126 127 128 129
  # Generate extension documentation, both normal and API
  my $ext_dir = bz_locations()->{'extensionsdir'};
  my @ext_paths
    = grep { $_ !~ /\/create\.pl$/ && !-e "$_/disabled" } glob("$ext_dir/*");
  my %extensions;
  foreach my $item (@ext_paths) {
    my $basename = basename($item);
    if (-d "$item/docs/$lang/rst") {
      $extensions{$basename} = "$item/docs/$lang/rst";
130
    }
131
  }
132

133 134
  # Collect up local extension documentation into the extensions/ dir.
  rmtree("$lang/rst/extensions", 0, 1);
135

136 137 138 139 140 141
  foreach my $ext_name (keys %extensions) {
    my $src = $extensions{$ext_name} . "/*";
    my $dst = "$docparent/$lang/rst/extensions/$ext_name";
    mkdir($dst) unless -d $dst;
    rcopy($src, $dst);
  }
142

143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
  chdir "$docparent/$lang";

  MakeDocs('HTML', 'html');
  MakeDocs('TXT',  'text');

  if (grep { $_ eq '--with-pdf' } @ARGV) {
    if (which('pdflatex')) {
      MakeDocs('PDF', 'latexpdf');
    }
    elsif (which('rst2pdf')) {
      rmtree('pdf', 0, 1);
      MakeDocs('PDF', 'pdf');
    }
    else {
      say 'pdflatex or rst2pdf not found. Skipping PDF file creation';
158
    }
159
  }
160

161
  rmtree('doctrees', 0, 1);
162
}
163 164

die "Error occurred building the documentation\n" if $error_found;