2011-03-13 14:59:20 +03:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
=head1
|
|
|
|
|
|
|
|
Generate a testament describing the current SVN status. This gets written
|
|
|
|
out in a C form which can be used to construct the NetSurf SVN testament
|
|
|
|
file for signon notification.
|
|
|
|
|
|
|
|
If there is no SVN in place, the data is invented arbitrarily.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
my $root = shift @ARGV;
|
|
|
|
my $targetfile = shift @ARGV;
|
|
|
|
|
|
|
|
my %svninfo; # The SVN info output
|
|
|
|
|
|
|
|
my $svn_present = 0;
|
|
|
|
if ( -d ".svn" ) {
|
|
|
|
$svn_present = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $svn_present ) {
|
|
|
|
foreach my $line (split(/\n/, `cd $root;svn info`)) {
|
|
|
|
my ($key, $value) = split(/: /, $line, 2);
|
|
|
|
$key = lc($key);
|
|
|
|
$key =~ s/\s+//g;
|
|
|
|
$svninfo{$key} = $value;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$svninfo{repositoryroot} = "http://nowhere/";
|
2011-03-13 15:09:01 +03:00
|
|
|
$svninfo{url} = "http://nowhere/tarball/";
|
|
|
|
$svninfo{revision} = "unknown";
|
2011-03-13 14:59:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
my %svnstatus; # The SVN status output
|
|
|
|
|
|
|
|
if ( $svn_present ) {
|
|
|
|
foreach my $line (split(/\n/, `cd $root; svn status `)) {
|
|
|
|
my $op = substr($line, 0, 1);
|
|
|
|
if ($op eq ' ' && substr($line, 1, 1) ne ' ') { $op = "p"; }
|
|
|
|
my $fn = substr($line, 7);
|
|
|
|
next unless (care_about_file($fn, $op));
|
|
|
|
$svnstatus{$fn} = $op;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my %userinfo; # The information about the current user
|
|
|
|
|
|
|
|
{
|
|
|
|
my $pwdline = `getent passwd $<`;
|
|
|
|
chomp $pwdline;
|
|
|
|
my @pwdinfo = split(/:/, $pwdline);
|
|
|
|
$userinfo{USERNAME} = $pwdinfo[0];
|
|
|
|
my $gecos = $pwdinfo[4];
|
|
|
|
$gecos =~ s/,.+//g;
|
|
|
|
$gecos =~ s/"/'/g;
|
|
|
|
$userinfo{GECOS} = $gecos;
|
|
|
|
}
|
|
|
|
|
2011-03-13 20:32:00 +03:00
|
|
|
# The current date, in AmigaOS version friendly format (dd.mm.yyyy)
|
|
|
|
|
|
|
|
my $compiledate = `date +%d.%m.%Y`;
|
|
|
|
chomp $compiledate;
|
|
|
|
|
2011-03-13 14:59:20 +03:00
|
|
|
# Spew the testament out
|
|
|
|
|
|
|
|
my $testament = "";
|
|
|
|
|
|
|
|
$testament .= "#define USERNAME \"$userinfo{USERNAME}\"\n";
|
|
|
|
$testament .= "#define GECOS \"$userinfo{GECOS}\"\n";
|
|
|
|
|
2011-03-13 15:17:18 +03:00
|
|
|
my $qroot = $root;
|
|
|
|
$qroot =~ s/"/\\"/g;
|
|
|
|
|
|
|
|
my $hostname = $ENV{HOSTNAME};
|
|
|
|
|
|
|
|
$hostname = "unknown-host" unless (defined($hostname) && $hostname ne "");
|
|
|
|
$hostname =~ s/"/\\"/g;
|
|
|
|
|
|
|
|
$testament .= "#define WT_ROOT \"$qroot\"\n";
|
|
|
|
$testament .= "#define WT_HOSTNAME \"$hostname\"\n";
|
2011-03-13 20:32:00 +03:00
|
|
|
$testament .= "#define WT_COMPILEDATE \"$compiledate\"\n";
|
2011-03-13 15:17:18 +03:00
|
|
|
|
2011-03-13 14:59:20 +03:00
|
|
|
my $url = $svninfo{url};
|
|
|
|
# This only works on 1.3.x and above
|
|
|
|
$url = substr($url, length($svninfo{repositoryroot}));
|
|
|
|
if ( substr($url,0,1) ne '/' ) { $url = "/$url"; }
|
|
|
|
$testament .= "#define WT_BRANCHPATH \"$url\"\n";
|
|
|
|
if ($url =~ m@/trunk/@) {
|
|
|
|
$testament .= "#define WT_BRANCHISTRUNK 1\n";
|
|
|
|
}
|
|
|
|
if ($url =~ m@/tags/@) {
|
|
|
|
$testament .= "#define WT_BRANCHISTAG 1\n";
|
|
|
|
}
|
2011-03-13 15:09:01 +03:00
|
|
|
if ($url =~ m@/tarball/@) {
|
|
|
|
$testament .= "#define WT_NO_SVN 1\n";
|
|
|
|
}
|
2011-03-13 14:59:20 +03:00
|
|
|
$testament .= "#define WT_REVID \"$svninfo{revision}\"\n";
|
|
|
|
$testament .= "#define WT_MODIFIED " . scalar(keys %svnstatus) . "\n";
|
|
|
|
$testament .= "#define WT_MODIFICATIONS {\\\n";
|
|
|
|
my $doneone = 0;
|
|
|
|
foreach my $filename (sort keys %svnstatus) {
|
|
|
|
if ($doneone) {
|
|
|
|
$testament .= ", \\\n";
|
|
|
|
}
|
|
|
|
$testament .= " { \"$filename\", '$svnstatus{$filename}' }";
|
|
|
|
$doneone = 1;
|
|
|
|
}
|
|
|
|
$testament .= " \\\n}\n";
|
|
|
|
|
|
|
|
use Digest::MD5 qw(md5_hex);
|
|
|
|
|
|
|
|
my $oldcsum = "";
|
|
|
|
if ( -e $targetfile ) {
|
|
|
|
open OLDVALUES, "<", $targetfile;
|
|
|
|
foreach my $line (readline(OLDVALUES)) {
|
|
|
|
if ($line =~ /MD5:([0-9a-f]+)/) {
|
|
|
|
$oldcsum = $1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close OLDVALUES;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $newcsum = md5_hex($testament);
|
|
|
|
|
|
|
|
if ($oldcsum ne $newcsum) {
|
|
|
|
print "TESTMENT: $targetfile\n";
|
|
|
|
open NEWVALUES, ">", $targetfile or die "$!";
|
|
|
|
print NEWVALUES "/* ", $targetfile,"\n";
|
|
|
|
print NEWVALUES <<'EOS';
|
|
|
|
*
|
|
|
|
* Revision testament.
|
|
|
|
*
|
|
|
|
* *WARNING* this file is automatically generated by svn-testament.pl
|
|
|
|
*
|
|
|
|
* Copyright 2011 NetSurf Browser Project
|
|
|
|
*/
|
|
|
|
|
|
|
|
EOS
|
|
|
|
|
|
|
|
print NEWVALUES "#ifndef NETSURF_REVISION_TESTAMENT\n";
|
|
|
|
print NEWVALUES "#define NETSURF_REVISION_TESTAMENT \"$newcsum\"\n\n";
|
|
|
|
print NEWVALUES "/* Revision testament checksum:\n";
|
|
|
|
print NEWVALUES " * MD5:", $newcsum,"\n */\n\n";
|
|
|
|
print NEWVALUES "/* Revision testament: */\n";
|
|
|
|
print NEWVALUES $testament;
|
|
|
|
print NEWVALUES "\n#endif\n";
|
|
|
|
close NEWVALUES;
|
|
|
|
foreach my $unwanted (@ARGV) {
|
|
|
|
next unless(-e $unwanted);
|
|
|
|
print "TESTAMENT: Removing $unwanted\n";
|
|
|
|
system("rm", "-f", "--", $unwanted);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print "TESTMENT: unchanged\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
sub care_about_file {
|
|
|
|
my ($fn, $op) = @_;
|
|
|
|
return 0 if ($fn =~ /\.d$/); # Don't care for extraneous DEP files
|
|
|
|
return 0 if ($fn =~ /\.a$/); # Don't care for extraneous archive files
|
|
|
|
return 0 if ($fn =~ /\.md5$/); # Don't care for md5sum files
|
|
|
|
return 0 if ($fn =~ /\.map$/); # Don't care for map files
|
|
|
|
return 1;
|
|
|
|
}
|