Home | History | Annotate | Line # | Download | only in regression
      1  1.1  mrg #!/usr/bin/perl
      2  1.1  mrg 
      3  1.1  mrg # Copy log files from a GCC build for HTTP access.
      4  1.1  mrg # Copyright (C) 2008, 2009 Free Software Foundation, Inc.
      5  1.1  mrg # 
      6  1.1  mrg # This program is free software: you can redistribute it and/or modify
      7  1.1  mrg # it under the terms of the GNU General Public License as published by
      8  1.1  mrg # the Free Software Foundation, either version 3 of the License, or
      9  1.1  mrg # (at your option) any later version.
     10  1.1  mrg # 
     11  1.1  mrg # This program is distributed in the hope that it will be useful,
     12  1.1  mrg # but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  1.1  mrg # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14  1.1  mrg # GNU General Public License for more details.
     15  1.1  mrg # 
     16  1.1  mrg # You should have received a copy of the GNU General Public License
     17  1.1  mrg # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     18  1.1  mrg 
     19  1.1  mrg # INPUT:
     20  1.1  mrg # mkindex.pl <srcdir> <destdir> <branchname>
     21  1.1  mrg 
     22  1.1  mrg # This script copies log files from a GCC build directory, compresses
     23  1.1  mrg # and indexes them for web browser access.  It's aimed at having an
     24  1.1  mrg # easy-to-access collection of files for analyzing regressions without
     25  1.1  mrg # needing to run the build yourself.  Binary files (.o, executables)
     26  1.1  mrg # are intentionally not included since usually if they are needed it's
     27  1.1  mrg # better to just run a build, and because they take up a lot of space.
     28  1.1  mrg 
     29  1.1  mrg # 'srcdir' is the root directory of a GCC build (was $objdir in the build).
     30  1.1  mrg # 'destdir' will be erased and replaced with the log files, and should be an
     31  1.1  mrg #   absolute path.
     32  1.1  mrg # 'branchname' is used only to produce the title of the index page,
     33  1.1  mrg #   which will be named 'index.html'.
     34  1.1  mrg 
     35  1.1  mrg use warnings;
     36  1.1  mrg use strict;
     37  1.1  mrg use File::Path qw(mkpath rmtree);
     38  1.1  mrg use File::Find qw(find);
     39  1.1  mrg 
     40  1.1  mrg if ($#ARGV != 2) {
     41  1.1  mrg     print "usage: $0 <srcdir> <destdir> <branchname>\n";
     42  1.1  mrg     exit 1;
     43  1.1  mrg }
     44  1.1  mrg 
     45  1.1  mrg my ($srcdir, $destdir, $branchname) = @ARGV;
     46  1.1  mrg die "destdir is not absolute" unless ($destdir =~ m,^/,);
     47  1.1  mrg 
     48  1.1  mrg # Erase the destination.
     49  1.1  mrg rmtree $destdir;
     50  1.1  mrg mkdir $destdir or die "${destdir}: $!";
     51  1.1  mrg 
     52  1.1  mrg # Copy and compress the files into the destination, and keep a list in @files.
     53  1.1  mrg my @files = ();
     54  1.1  mrg sub my_wanted {
     55  1.1  mrg     # Copy all files ending with .log or .sum.
     56  1.1  mrg     if (/\.(log|sum)$/ && -f) {
     57  1.1  mrg 
     58  1.1  mrg 	die unless (substr ($File::Find::dir,0,(length $srcdir)) eq $srcdir);
     59  1.1  mrg 	my $dir = substr $File::Find::dir,(length $srcdir);
     60  1.1  mrg 	$dir = substr $dir,1 unless ($dir eq '');
     61  1.1  mrg 	my $name = $_;
     62  1.1  mrg 	$name = $dir . '/' . $_ if ($dir ne '');
     63  1.1  mrg 
     64  1.1  mrg 	mkpath $destdir . '/' . $dir;
     65  1.1  mrg 	# Compress the files.  Use .gzip instead of .gz for the
     66  1.1  mrg 	# extension to avoid (broken) browser workarounds for broken
     67  1.1  mrg 	# web servers.
     68  1.1  mrg 	system ("gzip -c -q -9 $_ > $destdir/${name}.gzip") == 0 or exit 2;
     69  1.1  mrg 
     70  1.1  mrg 	# Write the (compressed) size consistently in Kbytes.
     71  1.1  mrg 	my $size = -s $destdir .'/' . $name . '.gzip';
     72  1.1  mrg 	my $printable_size = (sprintf "%.0fK",$size / 1024);
     73  1.1  mrg 
     74  1.1  mrg 	push @files,[$name.'.gzip',$name,$printable_size];
     75  1.1  mrg     }
     76  1.1  mrg }
     77  1.1  mrg find ({wanted => \&my_wanted}, $srcdir);
     78  1.1  mrg 
     79  1.1  mrg # Sort the list of files for the index.
     80  1.1  mrg @files = sort {$a->[1] cmp $b->[1]} @files;
     81  1.1  mrg 
     82  1.1  mrg # Create the index.
     83  1.1  mrg open INDEX,'>',$destdir . '/index.html' or die "${destdir}/index.html: $!";
     84  1.1  mrg # Use strict XHTML 1.0, and set charset to UTF-8.
     85  1.1  mrg print INDEX <<EOF or die "writing index: $!";
     86  1.1  mrg <!DOCTYPE html
     87  1.1  mrg      PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     88  1.1  mrg      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     89  1.1  mrg <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
     90  1.1  mrg <head>
     91  1.1  mrg  <title>Log files for $branchname</title>
     92  1.1  mrg  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
     93  1.1  mrg </head>
     94  1.1  mrg <body>
     95  1.1  mrg <h1>Log files for $branchname</h1>
     96  1.1  mrg <table><tr><th>Name</th><th align='right'>Size</th></tr>
     97  1.1  mrg EOF
     98  1.1  mrg # The index will have two columns, filename (without .gzip) and
     99  1.1  mrg # compressed size.
    100  1.1  mrg foreach my $f (@files) {
    101  1.1  mrg     printf INDEX "<tr><td><a href=\"%s\">%s</a></td><td align=\'right\'>%s</td></tr>\n",
    102  1.1  mrg 	$f->[0], $f->[1], $f->[2] or die "writing index: $!";
    103  1.1  mrg }
    104  1.1  mrg 
    105  1.1  mrg print INDEX "</table></body></html>\n" or die "writing index: $!";
    106  1.1  mrg close INDEX or die "writing index: $!";
    107  1.1  mrg exit 0;
    108