get it working pretty well
[pspp] / build-pspp
index 6177b0ec7457da8ea1e4a3f6c1e31e24c738c919..3d3959095ac1d6449ce2e2aa2b0b85d0496dbdeb 100755 (executable)
@@ -23,7 +23,7 @@ chomp $builder;
 # Select build number.
 my $build_number = POSIX::strftime("%Y%m%d%H%M%S", localtime);
 
-my $topdir = getcwd();
+my $topdir = getcwd ();
 
 # Create build directory.
 my $builddir = "builds/$build_number";
@@ -100,14 +100,37 @@ if (@ARGV == 2) {
     run ("git archive --format=tar --prefix=pspp$build_number/ buildtmp/$$/pspp | (cd $builddir && tar xf -)");
 
     # Extract version number.
-    start_step ("Extract version number");
+    start_step ("Extract repository version number");
     my $trace = `cd $builddir/pspp$build_number && autoconf -t AC_INIT`;
     chomp $trace;
-    my ($file, $line, $macro, $package, $version, @rest) = split (':', $trace);
-    set_var ("pspp_version", $version);
-
-    # Append -g012345 to AC_INIT version number.
-    start_step ("Adding -g$abbrev_commit to version number");
+    my ($file, $line, $macro, $package, $repo_version, @rest)
+      = split (':', $trace);
+    set_var ("repo_version", $repo_version);
+
+    # Is this a "gnits" mode tree?
+    start_step ("Checking Automake mode");
+    open (MAKEFILE_AM, '<', "$builddir/pspp$build_number/Makefile.am");
+    my $am_mode = "gnu";
+    while (<MAKEFILE_AM>) {
+       if (/gnits/) {
+           $am_mode = "gnits";
+           last;
+       }
+    }
+    close (MAKEFILE_AM);
+    set_var ("am_mode", $am_mode);
+
+    # Generate version number for build.
+    # We want to append -g012345, but if we're in Gnits mode and the
+    # version number already has a hyphen, we have to omit it.
+    start_step ("Generate build version number");
+    my $version = $repo_version;
+    $version .= '-' unless $version =~ /-/;
+    $version .= "g$abbrev_commit";
+    set_var ("version", $version);
+
+    # Append -g012345 to configure.ac version number.
+    start_step ("Updating version number in $file");
     my $fullname = "$builddir/pspp$build_number/$file";
     open (OLDFILE, '<', $fullname)
       or die "opening $fullname failed: $!\n";
@@ -117,7 +140,7 @@ if (@ARGV == 2) {
        if ($. != $line) {
            print NEWFILE $_;
        } else {
-           print NEWFILE "AC_INIT([$package], [$version-g$abbrev_commit]";
+           print NEWFILE "AC_INIT([$package], [$version]";
            print NEWFILE ", [$_]" foreach @rest;
            print NEWFILE ")\n";
        }
@@ -139,7 +162,7 @@ if (@ARGV == 2) {
        if (!$found_changes && /^Changes/) {
            $found_changes = 1;
            print NEWFILE <<EOF;
-Changes from $version to $version-g$abbrev_commit:
+Changes from $repo_version to $version:
 
  * Built automatically from commit $revision
    in branch $branch by builder $builder
@@ -179,22 +202,26 @@ EOF
 
     # 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");
-    my $tarname = "pspp-$version-g$abbrev_commit.tar.gz";
+    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 the manual in various formats.
-    start_step ("Build manual");
-    run ("cd $builddir/pspp$build_number/doc && GENDOCS_TEMPLATE_DIR=$topdir/gnulib/doc $topdir/gnulib/build-aux/gendocs.sh --email bug-gnu-pspp\@gnu.org pspp \\\"GNU PSPP Manual\\\"");
-    save_result ("$builddir/pspp$build_number/doc/manual");
+    # 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\"", "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-dev \"GNU PSPP Developers Guide\"", "dev-guide");
 } else {
     $tarball = $ARGV[0];
 }
@@ -220,34 +247,34 @@ if ($build_binary) {
     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
 }
@@ -268,11 +295,11 @@ EOF
 }
 
 sub run {
-    exit 1 if !try_run(@_);
+    fail () if !try_run (@_);
 }
 
 sub try_run {
-    my ($command) = @_;
+    my ($command, $id) = @_;
 
     print LOG "$command\n";
 
@@ -285,14 +312,29 @@ sub try_run {
        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";
     }
     close (COMMAND);
-    print "\r      \r";
+    print "\r", " " x 79, "\r";
+
+    write_timing ($id, time () - $start) if defined ($id);
 
     return 1 if !$?;
 
@@ -304,3 +346,40 @@ sub try_run {
     }
     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";
+}