#!/usr/bin/perl

use warnings;
use strict;

use Config::Tiny;
use Cwd;
use SVN::Agent;

my $config_file = Config::Tiny->new->read('status.conf');

my %config;

foreach (qw(domain trunk lib script arch libdoc bindoc)) {
	$config{$_} = $config_file->{_}->{$_} || die "No '$_' specified in status.conf";
}

die "trunk dir doesn't exist"     unless -e $config{'trunk'};
die "trunk dir isn't a directory" unless -d _;
die "trunk dir isn't readable"    unless -r _;
die "trunk dir isn't writable"    unless -w _;

my $sa = SVN::Agent->load({ path => $config{'trunk'} });
$sa->update;

my $program_dir = cwd;

chdir $config{'trunk'};
system("perl Build.PL --force \
	install_path=lib=$config{'lib'} \
	install_path=script=$config{'script'} \
	install_path=arch=$config{'arch'} \
	install_path=libdoc=$config{'libdoc'} \
	install_path=bindoc=$config{'bindoc'}");
	
my (undef, undef, undef, $day, $month, $year) = localtime(time);
$year += 1900;
$month = sprintf("%02d", ++$month);

system("perl Build");
system("perl Build test verbose=1 2>&1 > $program_dir/reports/test-results-$year-$month-$day.txt");