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