make_docs.pl 8.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/usr/bin/env perl

use strict;
use warnings;

    # Finding out own path in order to reference own components (including own modules):
use Cwd            ();
use File::Basename ();
BEGIN {
    $ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( Cwd::realpath($0) ) );
    unshift @INC, $ENV{'EHIVE_ROOT_DIR'}.'/modules';
}

14 15
use Getopt::Long qw(:config no_auto_abbrev);

16 17 18 19 20 21 22
use Bio::EnsEMBL::Hive::Version;

my $ehrd        = $ENV{'EHIVE_ROOT_DIR'}        or die "Environment variable 'EHIVE_ROOT_DIR' not defined, please check your setup";
my $erd         = $ENV{'ENSEMBL_CVS_ROOT_DIR'}  or die "Environment variable 'ENSEMBL_CVS_ROOT_DIR' not defined, please check your setup";
my $code_ver    = Bio::EnsEMBL::Hive::Version->get_code_version();


23 24 25 26 27 28 29 30 31 32
main();


sub main {
    my ($no_schema_desc, $no_script_docs, $no_doxygen);

    GetOptions(
            'no_schema_desc'    => \$no_schema_desc,
            'no_script_docs'    => \$no_script_docs,
            'no_doxygen'        => \$no_doxygen,
33 34 35 36 37
    ) or die "Error in command line arguments\n";

    if (@ARGV) {
        die "ERROR: There are invalid arguments on the command-line: ". join(" ", @ARGV). "\n";
    }
38 39 40 41 42 43 44 45

    generate_hive_schema_desc() unless($no_schema_desc);
    generate_docs_scripts()     unless($no_script_docs);
    unless($no_doxygen) {
        generate_docs_doxygen_perl();
        generate_docs_doxygen_python();
    }
}
46 47


48 49 50 51 52 53
sub generate_hive_schema_desc {

    print "Regenerating $ehrd/docs/hive_schema.html ...\n\n";

    my $sql2html = "$erd/ensembl-production/scripts/sql2html.pl";

54
    die "Cannot find '$sql2html', please make sure ensembl-production API is intalled properly.\n" unless(-r $sql2html);
55 56 57

    my @cmds = (
        "perl $sql2html -i $ehrd/sql/tables.mysql -d Hive -intro $ehrd/docs/hive_schema.inc -sort_headers 0 -sort_tables 0 -o $ehrd/docs/tmp_hive_schema.html",
58
        "(head -n 3 $ehrd/docs/tmp_hive_schema.html ; cat $ehrd/docs/hive_schema.hdr ; tail -n +4 $ehrd/docs/tmp_hive_schema.html) | sed 's/\\/i\\/16\\//http:\\/\\/www.ensembl.org\\/i\\/16\\//' > $ehrd/docs/hive_schema.html",
59
        "rm $ehrd/docs/tmp_hive_schema.html",       # remove the non-patched version
60 61 62 63 64 65 66 67 68 69
    );

    foreach my $cmd (@cmds) {
        print "Running the following command:\n\t$cmd\n\n";

        system( $cmd );
    }
}


70 71 72 73 74 75 76 77
sub generate_docs_scripts {

    print "Regenerating $ehrd/docs/scripts ...\n\n";

    my @cmds = (
        "find $ehrd/docs/scripts -type f -not -name index.html | xargs rm",     # delete all but index.html
        "cd   $ehrd/scripts",
    );
78 79 80 81 82 83 84 85 86
    opendir( my $script_dir, "$ehrd/scripts") || die "Can't opendir $ehrd/scripts: $!";
    foreach my $plname ( readdir($script_dir) ) {
        if( (-f "$ehrd/scripts/$plname") && $plname=~/^(\w+)\.pl$/) {
            my $htmlname = $1.'.html';
            push @cmds, "pod2html --noindex --title=$plname $ehrd/scripts/$plname >$ehrd/docs/scripts/$htmlname";
        }
    }
    closedir($script_dir);
    push @cmds, "rm   pod2htm?.tmp";                                            # clean up after pod2html
87 88 89 90 91 92 93 94 95

    foreach my $cmd (@cmds) {
        print "Running the following command:\n\t$cmd\n\n";

        system( $cmd );
    }
}


96
sub generate_docs_doxygen_perl {
97 98 99

    print "Regenerating $ehrd/docs/doxygen ...\n\n";

100 101 102 103 104
    my $doxy_bin    = `which doxygen`;
    chomp $doxy_bin;

    die "Cannot run doxygen binary, please make sure it is installed and is in the path.\n" unless(-r $doxy_bin);

105 106
    my $doxy_filter = "$erd/ensembl/misc-scripts/doxygen_filter/ensembldoxygenfilter.pl";

107
    die "Cannot run the Ensembl-Doxygen Perl filter at '$doxy_filter', please make sure Ensembl core API is intalled properly.\n" unless(-x $doxy_filter);
108 109 110 111 112 113 114 115 116 117 118

    my @cmds = (
        "rm   -rf $ehrd/docs/doxygen",
        "doxygen -g -",
        "echo 'PROJECT_NAME           = ensembl-hive'",
        "echo 'PROJECT_NUMBER         = $code_ver'",
        "echo 'OUTPUT_DIRECTORY       = $ehrd/docs'",
        "echo 'STRIP_FROM_PATH        = $ehrd'",
        "echo 'INPUT                  = $ehrd'",
        "echo 'INPUT_FILTER           = $doxy_filter'",
        "echo 'HTML_OUTPUT            = doxygen'",
119
        "echo 'EXTENSION_MAPPING      = pm=C pl=C'",
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
        "echo 'EXTRACT_ALL            = YES'",
        "echo 'FILE_PATTERNS          = *.pm *.pl README.md'",
        "echo 'USE_MDFILE_AS_MAINPAGE = README.md'",
        "echo 'ENABLE_PREPROCESSING   = NO'",
        "echo 'RECURSIVE              = YES'",
        "echo 'EXAMPLE_PATTERNS       = *'",
        "echo 'HTML_TIMESTAMP         = NO'",
        "echo 'HTML_DYNAMIC_SECTIONS  = YES'",
        "echo 'GENERATE_TREEVIEW      = YES'",
        "echo 'GENERATE_LATEX         = NO'",
        "echo 'CLASS_DIAGRAMS         = NO'",
        "echo 'HAVE_DOT               = YES'",
        "echo 'CALL_GRAPH             = YES'",
        "echo 'CALLER_GRAPH           = YES'",
    );

    my $full_cmd = '('.join(' ; ', @cmds).") | doxygen -";

    print "Running the following command:\n\t$full_cmd\n\n";

    system( $full_cmd );
}


144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
sub generate_docs_doxygen_python {

    print "Regenerating $ehrd/wrappers/python3/doxygen ...\n\n";

    my $doxy_bin    = `which doxygen`;
    chomp $doxy_bin;
    die "Cannot run doxygen binary, please make sure it is installed and is in the path.\n" unless(-r $doxy_bin);

    my $doxy_filter = `which doxypy`;
    chomp $doxy_filter;

    die "Cannot find the Doxygen Python filter 'doxypy' in the current PATH.\n" unless -e $doxy_filter;

    my @cmds = (
        "rm -rf $ehrd/wrappers/python3/doxygen",
        "doxygen -g -",
        "echo 'PROJECT_NAME           = ensembl-hive-python3'",
        "echo 'PROJECT_NUMBER         = $code_ver'",
        "echo 'OUTPUT_DIRECTORY       = $ehrd/wrappers/python3'",
        "echo 'STRIP_FROM_PATH        = $ehrd/wrappers/python3'",
        "echo 'INPUT                  = $ehrd/wrappers/python3'",
        "echo 'INPUT_FILTER           = $doxy_filter'",
        "echo 'HTML_OUTPUT            = doxygen'",
        "echo 'EXTRACT_ALL            = YES'",
        "echo 'EXTRACT_PRIVATE        = YES'",
        "echo 'EXTRACT_STATIC         = YES'",
        "echo 'FILE_PATTERNS          = *.py README.md'",
        "echo 'USE_MDFILE_AS_MAINPAGE = README.md'",
        "echo 'ENABLE_PREPROCESSING   = NO'",
        "echo 'RECURSIVE              = YES'",
        "echo 'EXAMPLE_PATTERNS       = *'",
        "echo 'HTML_TIMESTAMP         = NO'",
        "echo 'HTML_DYNAMIC_SECTIONS  = YES'",
        "echo 'GENERATE_TREEVIEW      = YES'",
        "echo 'GENERATE_LATEX         = NO'",
        "echo 'CLASS_DIAGRAMS         = YES'",
        "echo 'HAVE_DOT               = YES'",
        "echo 'CALL_GRAPH             = YES'",
        "echo 'CALLER_GRAPH           = YES'",
        "echo 'COLLABORATION_GRAPH    = NO'",
        "echo 'SOURCE_BROWSER         = YES'",
    );

    my $full_cmd = '('.join(' ; ', @cmds).") | doxygen -";

    print "Running the following command:\n\t$full_cmd\n\n";

    system( $full_cmd );
}


195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
__DATA__

=pod

=head1 NAME

    make_docs.pl

=head1 DESCRIPTION

    An internal eHive script for regenerating the documentation both in docs/scripts (using pod2html) and docs/doxygen (using doxygen).

    The script doesn't have any options at the moment.

=head1 LICENSE

211
    Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Brandon Walts's avatar
Brandon Walts committed
212
    Copyright [2016-2020] EMBL-European Bioinformatics Institute
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228

    Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License
    is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and limitations under the License.

=head1 CONTACT

    Please subscribe to the Hive mailing list:  http://listserver.ebi.ac.uk/mailman/listinfo/ehive-users  to discuss Hive-related questions or to be notified of our updates

=cut