#! /usr/bin/env perl
+use Cwd;
+use File::Spec;
use Getopt::Long qw(:config bundling no_ignore_case);
+use IO::Handle;
use POSIX;
-use Cwd;
use strict;
use warnings;
my $help = 0;
my $build_binary = 1;
+my $batch = 0;
+my $builddir;
+my $build_number;
GetOptions ("h|help" => \$help,
- "binary!" => \$build_binary);
+ "binary!" => \$build_binary,
+ "batch!" => \$batch,
+ "o|output=s" => \$builddir,
+ "build-number=i" => \$build_number);
usage () if $help;
chomp $builder;
# Select build number.
-my $build_number = POSIX::strftime("%Y%m%d%H%M%S", localtime);
+if (!defined ($build_number)) {
+ $build_number = POSIX::strftime("%Y%m%d%H%M%S", localtime);
+}
my $topdir = getcwd ();
# Create build directory.
-my $builddir = "builds/$build_number";
-mkdir "builds" or die "builds: mkdir: $!\n" if ! -d "builds";
-mkdir $builddir or die "$builddir: mkdir: $!\n";
+if (!defined ($builddir)) {
+ $builddir = "builds/$build_number";
+ mkdir "builds" or die "builds: mkdir: $!\n" if ! -d "builds";
+}
+-d $builddir or mkdir $builddir or die "$builddir: mkdir: $!\n";
+my $abs_builddir = File::Spec->rel2abs ($builddir);
our $resultsdir = "$builddir/results";
mkdir $resultsdir or die "$resultsdir: mkdir: $!\n";
mkdir "$resultsdir/vars" or die "$resultsdir/vars: mkdir: $!\n";
+my $abs_resultsdir = File::Spec->rel2abs ($resultsdir);
+
+my $varsfile = "$resultsdir/VARS";
+open (VARS, '>', $varsfile) or die "creating $varsfile failed: $!\n";
+VARS->autoflush (1);
my $logfile = "$resultsdir/LOG";
open (LOG, '>', $logfile) or die "creating $logfile failed: $!\n";
sub start_step {
my ($msg) = @_;
print LOG "\f\n$msg\n";
- print "$msg\n";
+ print "$msg\n" unless $batch;
}
sub set_var {
my ($var, $value) = @_;
+
+ print VARS "$var=$value\n";
+
+ print "\t$var=$value\n" unless $batch;
+
open (VAR, '>', "$resultsdir/vars/$var")
or die "creating $resultsdir/$var failed: $!\n";
print VAR "$value\n";
close VAR;
- print LOG "$var=$value\n";
- print "\t$var=$value\n";
+}
+
+sub saved_result {
+ my ($product) = @_;
+ start_step ("Saving $product");
}
sub save_result {
my ($src, $rm_src) = @_;
- my ($dst) = $src;
- $dst =~ s(^.*/)();
- $dst = "$resultsdir/$dst";
+ my ($basename) = $src;
+ $basename =~ s(^.*/)();
+ my ($dst) = "$resultsdir/$basename";
- start_step ("Saving $src");
+ saved_result ($basename);
run ("cp -R $src $dst");
if (defined ($rm_src) && $rm_src) {
# Extract source.
start_step ("Extract branch into $builddir/pspp$build_number");
run ("git archive --format=tar --prefix=pspp$build_number/ buildtmp/$$/pspp | (cd $builddir && tar xf -)");
+ run ("git branch -D buildtmp/$$/pspp");
# Extract version number.
start_step ("Extract repository version number");
start_step ("Checking Automake mode");
open (MAKEFILE_AM, '<', "$builddir/pspp$build_number/Makefile.am");
my $am_mode = "gnu";
- while (<MAKEFILE>) {
+ while (<MAKEFILE_AM>) {
if (/gnits/) {
$am_mode = "gnits";
last;
}
}
+ close (MAKEFILE_AM);
set_var ("am_mode", $am_mode);
# Generate version number for build.
# Bootstrap.
start_step ("Bootstrap (make -f Smake)");
- run ("cd $builddir/pspp$build_number && make -f Smake");
+ run ("cd $builddir/pspp$build_number && make -f Smake", "bootstrap");
# Configure.
start_step ("Configure source");
- run ("cd $builddir/pspp$build_number && mkdir _build && cd _build && ../configure");
+ run ("cd $builddir/pspp$build_number && mkdir _build && cd _build && ../configure", "configure");
# Distribute.
start_step ("Make source tarball");
- run ("cd $builddir/pspp$build_number/_build && make dist");
+ run ("cd $builddir/pspp$build_number/_build && make dist", "dist");
my $tarname = "pspp-$version.tar.gz";
$tarball = save_result ("$builddir/pspp$build_number/_build/$tarname", 1);
# Build user manual
start_step ("Build user manual");
run ("cd $builddir/pspp$build_number && cp _build/doc/*.texi doc/");
- run ("cd $builddir/pspp$build_number && GENDOCS_TEMPLATE_DIR=$topdir $topdir/gendocs.sh -s doc/pspp.texinfo -o $topdir/$builddir/results/user-manual --email bug-gnu-pspp\@gnu.org pspp \"GNU PSPP User Manual\"");
+ run ("cd $builddir/pspp$build_number && GENDOCS_TEMPLATE_DIR=$topdir $topdir/gendocs.sh -s doc/pspp.texinfo -o $abs_resultsdir/user-manual --email bug-gnu-pspp\@gnu.org pspp \"GNU PSPP User Manual\"", "user-manual");
+ saved_result ("user-manual");
# Build developer's guide
start_step ("Build developers guide");
- run ("cd $builddir/pspp$build_number && GENDOCS_TEMPLATE_DIR=$topdir $topdir/gendocs.sh -s doc/pspp-dev.texinfo -o $topdir/$builddir/results/dev-guide --email bug-gnu-pspp\@gnu.org pspp \"GNU PSPP Developers Guide\"");
+ run ("cd $builddir/pspp$build_number && GENDOCS_TEMPLATE_DIR=$topdir $topdir/gendocs.sh -s doc/pspp-dev.texinfo -o $abs_resultsdir/dev-guide --email bug-gnu-pspp\@gnu.org pspp-dev \"GNU PSPP Developers Guide\"", "dev-guide");
+ saved_result ("dev-guide");
} else {
$tarball = $ARGV[0];
}
run ("chmod u+w $builddir/$tarball_dir");
run ("mkdir $builddir/$tarball_dir/_build");
run ("chmod a-w $builddir/$tarball_dir");
- my $ok = try_run ("cd $builddir/$tarball_dir/_build && ../configure --enable-relocatable --prefix=''");
+ my $ok = try_run ("cd $builddir/$tarball_dir/_build && ../configure --enable-relocatable --prefix=''", "bin-configure");
for my $basename ("config.h", "config.log") {
save_result_if_exists ("$builddir/$tarball_dir/_build/$basename");
}
- exit 1 if !$ok;
+ fail () if !$ok;
start_step ("Build");
- run ("cd $builddir/$tarball_dir/_build && make");
+ run ("cd $builddir/$tarball_dir/_build && make", "build");
start_step ("Install");
- run ("cd $builddir/$tarball_dir/_build && make install DESTDIR=\$PWD/pspp-$binary_version");
+ run ("cd $builddir/$tarball_dir/_build && make install DESTDIR=\$PWD/pspp-$binary_version", "install");
start_step ("Make binary distribution");
run ("cd $builddir/$tarball_dir/_build && tar cfz pspp-$binary_version.tar.gz pspp-$binary_version");
save_result ("$builddir/$tarball_dir/_build/pspp-$binary_version.tar.gz", 1);
start_step ("Check");
- $ok = try_run ("cd $builddir/$tarball_dir/_build && make check");
+ $ok = try_run ("cd $builddir/$tarball_dir/_build && make check", "check");
for my $basename ("tests/testsuite.log", "tests/testsuite.dir") {
save_result_if_exists ("$builddir/$tarball_dir/_build/$basename");
}
- exit 1 if !$ok;
+ fail () if !$ok;
start_step ("Uninstall");
- run ("cd $builddir/$tarball_dir/_build && make uninstall DESTDIR=\$PWD/pspp-$binary_version");
+ run ("cd $builddir/$tarball_dir/_build && make uninstall DESTDIR=\$PWD/pspp-$binary_version", "uninstall");
start_step ("Check uninstall");
- run ("cd $builddir/$tarball_dir/_build && make distuninstallcheck distuninstallcheck_dir=\$PWD/pspp-$binary_version");
+ run ("cd $builddir/$tarball_dir/_build && make distuninstallcheck distuninstallcheck_dir=\$PWD/pspp-$binary_version", "distuninstallcheck");
# distcleancheck
}
Options:
--help Print this usage message and exit
+ --no-binary Build source tarballs but no binaries.
+ --batch Do not print progress to stdout.
EOF
exit(0);
}
sub run {
- exit 1 if !try_run(@_);
+ fail () if !try_run (@_);
}
sub try_run {
- my ($command) = @_;
+ my ($command, $id) = @_;
print LOG "$command\n";
die "$command: exec failed: $!\n";
}
+ my ($start) = time ();
+ my ($est_time) = (defined ($id) ? read_timing ($id) : 0);
+
local ($|) = 1;
- my $i = 0;
+ my $lines = 0;
while (<COMMAND>) {
print LOG $_;
- print "\r", $i++;
+
+ my $elapsed = time () - $start;
+ $progress = sprintf "%d lines logged, %d s elapsed",
+ $lines++, $elapsed;
+ if ($est_time > 0) {
+ my $left = $est_time - $elapsed;
+ if ($left > 0) {
+ $progress .= sprintf ", ETA %d s", $left;
+ }
+ }
+ print "\r$progress", " " x (79 - length ($progress)), "\r"
+ unless $batch;
}
close (COMMAND);
- print "\r \r";
+ print "\r", " " x 79, "\r" unless $batch;
+
+ write_timing ($id, time () - $start) if defined ($id);
return 1 if !$?;
if ($? & 127) {
- printf "%s: child died with signal %d, %s coredump\n",
+ printf STDERR "%s: child died with signal %d, %s coredump\n",
$command, ($? & 127), ($? & 128) ? 'with' : 'without';
} else {
- printf "%s: child exited with value %d\n", $command, $? >> 8;
+ printf STDERR "%s: child exited with value %d\n", $command, $? >> 8;
}
return 0;
}
+
+sub read_timing {
+ my ($id) = @_;
+ open (TIMINGS, "<", "$topdir/timings") or return 0;
+ while (<TIMINGS>) {
+ chomp;
+ my ($key, $value) = /^([^=]+)=(.*)/ or next;
+ return $value if $key eq $id;
+ }
+ close (TIMINGS);
+ return 0;
+}
+
+sub write_timing {
+ my ($id, $time) = @_;
+
+ open (NEWTIMINGS, ">", "$topdir/timings.tmp$$") or return;
+
+ if (open (OLDTIMINGS, "<", "$topdir/timings")) {
+ while (<OLDTIMINGS>) {
+ if (my ($key, $value) = /^([^=]+)=(.*)/) {
+ next if $key eq $id;
+ }
+ print NEWTIMINGS $_;
+ }
+ close (OLDTIMINGS);
+ }
+
+ print NEWTIMINGS "$id=$time\n";
+ close (NEWTIMINGS);
+
+ rename ("$topdir/timings.tmp$$", "$topdir/timings");
+}
+
+sub fail {
+ die "Build failed, refer to:\n\t$topdir/$logfile\nfor details.\n";
+}