From 4138eb6b6199bcb31345250dd0292f8559f14558 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 4 Jul 2020 22:31:49 +0000 Subject: [PATCH] Convert build-pspp to Python 3. --- build-pspp | 937 +++++++++++++++++++++++++++++------------------------ 1 file changed, 509 insertions(+), 428 deletions(-) diff --git a/build-pspp b/build-pspp index 4ed0a4909b..62e8a75030 100755 --- a/build-pspp +++ b/build-pspp @@ -1,470 +1,551 @@ -#! /usr/bin/env perl - -use Cwd; -use File::Basename; -use File::Spec; -use Getopt::Long qw(:config bundling no_ignore_case); -use IO::Handle; -use POSIX; - -use strict; -use warnings; - -my $help = 0; -my $build_binary = 1; -my $batch = 0; -my $builddir; -my $build_number; -my $builder = `hostname`; -chomp $builder; -GetOptions ("h|help" => \$help, - "binary!" => \$build_binary, - "batch!" => \$batch, - "o|output=s" => \$builddir, - "builder=s" => \$builder, - "build-number=i" => \$build_number); - -usage () if $help; - -die "$0: exactly one or two nonoption arguments are required\n" - if @ARGV != 1 && @ARGV != 2; - -my $tarball; -if (@ARGV == 1) { - $tarball = File::Spec->rel2abs ($ARGV[0]); -} else { - # Tarball will be generated later. -} +#! /usr/bin/env python3 + +import getopt +import os.path +import re +import socket +import subprocess +import sys + +from datetime import datetime +from pathlib import Path + + +def backquotes(command): + output = subprocess.check_output(command, shell=True, text=True) + if output.endswith('\n'): + output = output[:-1] + return output + + +def print_usage(): + print("""\ +%s, for building and testing PSPP +usage: %s [OPTIONS] [TARBALL | REPO REFSPEC] +where TARBALL is the name of a tarball produced by "make dist" + or REPO and REFSPEC are a Git repo and refspec (e.g. branch) to clone. + +Options: + --help Print this usage message and exit + --no-binary Build source tarballs but no binaries. + --batch Do not print progress to stdout.""" + % (sys.argv[0], sys.argv[0])) + sys.exit(0) + + +def run(command, id=None): + if not try_run(command, id): + fail() + + +def try_run(command, id=None): + LOG.write("%s\n" % command) + + p = subprocess.Popen(command, shell=True, text=True, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + + start = datetime.now() + est_time = 0 if id is None else read_timing(id) + + lines = 0 + for s in p.stdout: + LOG.write(s) + + elapsed = (datetime.now() - start).seconds + progress = "%d lines logged, %d s elapsed" % (lines, elapsed) + lines += 1 + if est_time > 0: + left = est_time - elapsed + if left > 0: + progress += ", ETA %d s" % left + if not batch: + sys.stdout.write("\r%s%s\r" + % (progress, " " * (79 - len(progress)))) + if not batch: + sys.stdout.write("\r%s\r" % (' ' * 79)) + + if id is not None: + write_timing(id, (datetime.now() - start).seconds) + + rc = p.wait() + if rc == 0: + return True + + if rc < 0: + sys.stderr.write("%s: child died with signal %d\n" % (command, -rc)) + else: + sys.stderr.write("%s: child exited with value %d\n" % (command, rc)) + return False + + +def read_timing(id): + try: + for s in open("%s/timings" % topdir): + m = re.match('([^=]+)=(.*)', s.rstrip()) + if m: + key, value = m.groups() + if key == id: + try: + return int(value) + except ValueError: + return 0 + return 0 + except FileNotFoundError: + return 0 + + +def write_timing(id, time): + tmpname = "%s/timings.tmp%d" % (topdir, os.getpid()) + NEWTIMINGS = open(tmpname, 'w') + try: + OLDTIMINGS = open("%s/timings" % topdir, "r") + for s in OLDTIMINGS: + m = re.match('([^=]+)=(.*)', s.rstrip()) + if m: + key, value = m.groups() + if key == id: + continue + NEWTIMINGS.write(s) + except FileNotFoundError: + pass + NEWTIMINGS.write("%s=%s\n" % (id, time)) + NEWTIMINGS.close() + os.rename(tmpname, "%s/timings" % topdir) + + +def fail(): + sys.stderr.write("Build failed, refer to:\n\t%s\nfor details.\n" % logfile) + sys.exit(1) + + +def start_step(msg): + LOG.write(" \n%s\n" % msg) + if not batch: + print(msg) + + +def set_var(var, value): + VARS.write("%s=%s\n" % (var, value)) + if not batch: + print("\t%s=%s" % (var, value)) + + VAR = open("%s/vars/%s" % (resultsdir, var), "wt") + VAR.write("%s\n" % value) + VAR.close() + + +def saved_result(name, product): + start_step("Saving %s: %s" % (name, product)) + + +def save_result(name, src, rm_src=False): + basename = os.path.basename(src) + dst = "%s/%s" % (resultsdir, basename) + + saved_result(name, basename) + run("cp -R %s %s" % (src, dst)) + + if rm_src: + run("rm %s" % src) + + return dst + + +def save_result_if_exists(name, src, rm_src=False): + if Path(src).exists(): + save_result(name, src, rm_src) + else: + start_step("%s does not exist, cannot save" % src) + + +def ref_to_commit(ref, repo='.'): + return backquotes("cd %s && %s rev-parse %s" % (repo, GIT, ref)) + + +try: + opts, args = getopt.gnu_getopt(sys.argv[1:], "ho:", + ["help", + "binary", "no-binary", + "batch", "no-batch", + "output=", + "builder=", "build-number="]) +except getopt.GetoptError as err: + # print help information and exit: + print(err) # will print something like "option -a not recognized" + sys.exit(1) + +build_binary = True +batch = not os.isatty(1) +builddir = None +build_number = None +builder = None +for o, a in opts: + if o in ("-h", "--help"): + print_usage() + elif o == "--binary": + build_binary = True + elif o == "--no-binary": + build_binary = False + elif o == "--batch": + batch = True + elif o == "--no-batch": + batch = False + elif o in ("-o", "--output"): + builddir = a + elif o == "--builder": + builder = a + elif o == "--build-number": + build_number = a + else: + assert False, "unhandled option" +if builder is None: + builder = socket.gethostname() + +if len(args) not in (1, 2): + sys.stderr.write( + "%s: exactly one or two nonoption arguments are required\n" + % sys.argv[0]) + sys.exit(1) + +if len(args) == 1: + tarball = os.path.abspath(args[0]) +else: + pass # Tarball will be generated later. # Select build number. -if (!defined ($build_number)) { - $build_number = POSIX::strftime("%Y%m%d%H%M%S", localtime); -} +if build_number is None: + build_number = datetime.now().strftime("%Y%m%d%H%M%S") -my $topdir = dirname ($0); -$topdir = cwd () . "/$topdir" if $topdir !~ m%^/%; +topdir = os.path.dirname(sys.argv[0]) +if not topdir.startswith("/"): + topdir = "%s/%s" % (os.getcwd(), topdir) # Create build directory. -if (!defined ($builddir)) { - $builddir = "builds/$build_number"; - mkdir "builds" or die "builds: mkdir: $!\n" if ! -d "builds"; -} -$builddir = File::Spec->rel2abs ($builddir); --d $builddir or mkdir $builddir or die "$builddir: mkdir: $!\n"; -chdir ($builddir) or die "$builddir: chdir: $!\n"; - -our $resultsdir = "$builddir/results"; -mkdir $resultsdir or die "$resultsdir: mkdir: $!\n"; -mkdir "$resultsdir/vars" or die "$resultsdir/vars: mkdir: $!\n"; - -my $varsfile = "$resultsdir/VARS"; -open (VARS, '>', $varsfile) or die "creating $varsfile failed: $!\n"; -VARS->autoflush (1); - -our $logfile = "$resultsdir/LOG"; -open (LOG, '>', $logfile) or die "creating $logfile failed: $!\n"; - -set_var ("builder", $builder); -set_var ("build_number", $build_number); - -our $GIT = "git --git-dir=$topdir/.git"; - -sub start_step { - my ($msg) = @_; - print LOG " \n$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; -} - -sub saved_result { - my ($name, $product) = @_; - start_step ("Saving $name: $product"); -} - -sub save_result { - my ($name, $src, $rm_src) = @_; - my ($basename) = $src; - $basename =~ s(^.*/)(); - my ($dst) = "$resultsdir/$basename"; - - saved_result ($name, $basename); - run ("cp -R $src $dst"); - - if (defined ($rm_src) && $rm_src) { - run ("rm $src"); - } - - return $dst; -} - -sub save_result_if_exists { - my ($name, $src, $rm_src) = @_; - if (-e $src) { - save_result (@_); - } else { - start_step ("$src does not exist, cannot save"); - } -} - -sub ref_to_commit { - my ($ref) = @_; - my $commit = `$GIT rev-parse $ref`; - chomp $commit; - return $commit; -} - -my $ssw = "spread-sheet-widget-0.4"; -if (@ARGV == 2) { - my ($repo, $branch) = @ARGV; - - my $ssw_tar = "$topdir/$ssw.tar.gz"; - #save_result ("spread-sheet-widget source", $ssw_tar); - start_step ("Extract spread-sheet-widget"); - run ("tar xzf $ssw_tar"); - - start_step ("Configure spread-sheet-widget"); - run ("cd $ssw && ./configure --prefix=''"); - - start_step ("Build spread-sheet-widget"); - run ("cd $ssw && make -j10"); - - start_step ("Install spread-sheet-widget"); - run ("cd $ssw && make -j10 install DESTDIR=\$PWD/inst"); - - start_step ("Fetch branch from Git"); - set_var ("git_repo", $repo); - set_var ("git_branch", $branch); - run ("$GIT fetch $repo +$branch:refs/builds/$build_number/pspp"); +if builddir is None: + builddir = "builds/%s" % build_number + if not Path('builds').is_dir(): + os.mkdir('builds') +builddir = os.path.abspath(builddir) +if not Path(builddir).is_dir(): + os.mkdir(builddir) +os.chdir(builddir) + +resultsdir = "%s/results" % builddir +os.mkdir(resultsdir) +os.mkdir("%s/vars" % resultsdir) + +varsfile = "%s/VARS" % resultsdir +VARS = open(varsfile, "wt", buffering=1) + +logfile = "%s/LOG" % resultsdir +LOG = open(logfile, "wt", buffering=1) + +set_var("builder", builder) +set_var("build_number", build_number) + +GIT = "git --git-dir=%s/.git" % topdir + +# ssw = "https://alpha.gnu.org/gnu/ssw/spread-sheet-widget-0.4.tar.gz" +ssw = "https://git.savannah.gnu.org/git/ssw.git master" + +if ssw.endswith('.tar.gz'): + ssw_basename = os.path.basename(ssw) + ssw_file = '%s/%s' % (topdir, ssw_basename) + ssw_dir = ssw_basename[:-7] +else: + ssw_dir = 'ssw' +if len(args) == 2: + repo, branch = args + + if ssw.endswith('.tar.gz'): + if not Path(ssw_file).exists(): + start_step("Retrieve spread-sheet-widget tarball %s" % ssw_file) + run("wget -O %s %s" % (ssw_file, ssw)) + + start_step("Extract %s into %s" % (ssw_file, ssw_dir)) + run("tar xzf %s" % ssw_file) + elif ' ' in ssw: + ssw_url, ssw_ref = ssw.split() + + start_step("Clone spread-sheet-widget into %s" % ssw_dir) + run("git clone %s %s" % (ssw_url, ssw_dir)) + + start_step("Check out %s in ssw" % ssw_ref) + run("cd %s && git checkout %s" % (ssw_dir, ssw_ref)) + set_var("ssw_commit", ref_to_commit("HEAD", "ssw")) + + start_step("Bootstrap ssw") + run("cd %s && ./bootstrap" % ssw_dir) + else: + assert False + + start_step("Configure spread-sheet-widget") + run("cd %s && ./configure --prefix=''" % ssw_dir) + + start_step("Build spread-sheet-widget") + run("cd %s && make -j10" % ssw_dir) + + start_step("Install spread-sheet-widget") + run("cd %s && make -j10 install DESTDIR=$PWD/inst" % ssw_dir) + + start_step("Fetch branch from Git") + set_var("git_repo", repo) + set_var("git_branch", branch) + run("%s fetch %s +%s:refs/builds/%s/pspp" + % (GIT, repo, branch, build_number)) # Get revision number. - set_var ("pspp_ref", "refs/builds/$build_number/pspp"); - my $revision = ref_to_commit ("refs/builds/$build_number/pspp"); - set_var ("pspp_commit", $revision); - my $abbrev_commit = substr ($revision, 0, 6); + set_var("pspp_ref", "refs/builds/%s/pspp" % build_number) + revision = ref_to_commit("refs/builds/%s/pspp" % build_number) + set_var("pspp_commit", revision) + abbrev_commit = revision[:6] # Extract source. - start_step ("Extract branch into source directory"); - run ("$GIT archive --format=tar --prefix=pspp/ refs/builds/$build_number/pspp | tar xf -"); + start_step("Extract branch into source directory") + run("%s archive --format=tar --prefix=pspp/ refs/builds/%s/pspp | tar xf -" + % (GIT, build_number)) # Extract version number. - start_step ("Extract repository version number"); - my $trace = `cd pspp && autoconf -t AC_INIT`; - chomp $trace; - my ($file, $line, $macro, $package, $repo_version, @rest) - = split (':', $trace); - set_var ("repo_version", $repo_version); + start_step("Extract repository version number") + fields = backquotes("cd pspp && autoconf -t AC_INIT").split(':') + file, line, macro, package, repo_version = fields[:5] + rest = fields[5:] + set_var("repo_version", repo_version) # Is this a "gnits" mode tree? - start_step ("Checking Automake mode"); - open (MAKEFILE_AM, '<', "pspp/Makefile.am"); - my $am_mode = "gnu"; - while () { - if (/gnits/) { - $am_mode = "gnits"; - last; - } - } - close (MAKEFILE_AM); - print LOG "Automake mode is $am_mode\n"; + start_step("Checking Automake mode") + + am_mode = "gnu" + for s in open("pspp/Makefile.am"): + if "gnits" in s: + am_mode = "gnits" + break + LOG.write("Automake mode is %s\n" % 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); + start_step("Generate build version number") + version = repo_version + if '-' not in version: + 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 = "pspp/$file"; - open (OLDFILE, '<', $fullname) - or die "opening $fullname failed: $!\n"; - open (NEWFILE, '>', "$fullname.new") - or die "creating $fullname.new failed: $!\n"; - while () { - if ($. != $line) { - print NEWFILE $_; - } else { - print NEWFILE "AC_INIT([$package], [$version]"; - print NEWFILE ", [$_]" foreach @rest; - print NEWFILE ")\n"; - } - } - close (NEWFILE); - close (OLDFILE); - rename ("$fullname.new", $fullname) - or die "rename $fullname.new to $fullname failed: $!\n"; + start_step("Updating version number in %s" % file) + fullname = "pspp/%s" % file + NEWFILE = open("%s.new" % fullname, "w") + ln = 1 + for s in open(fullname): + if ln != int(line): + NEWFILE.write(s) + else: + NEWFILE.write("AC_INIT([%s], [%s]" % (package, version)) + for field in rest: + NEWFILE.write(", [%s]" % field) + NEWFILE.write(")\n") + ln += 1 + NEWFILE.close() + os.rename("%s.new" % fullname, fullname) # Get Gnulib commit number. - start_step ("Reading README.Git to find Gnulib commit number"); - my $gnulib_commit; - $fullname = "pspp/README.Git"; - open (README_GIT, '<', $fullname) - or die "opening $fullname failed: $!\n"; - while () { - ($gnulib_commit) = /^\s+commit ([0-9a-fA-F]{8,})/ and last; - } - die "$fullname does not specify a Git commit number\n" - if !defined ($gnulib_commit); - set_var ("gnulib_commit", $gnulib_commit); + start_step("Reading README.Git to find Gnulib commit number") + fullname = "pspp/README.Git" + gnulib_commit = None + for s in open(fullname): + m = re.match(r'\s+commit ([0-9a-fA-F]{8,})', s) + if m: + gnulib_commit = m.group(1) + break + if gnulib_commit is None: + sys.stderr.write("%s does not specify a Git commit number\n" + % fullname) + sys.exit(1) + set_var("gnulib_commit", gnulib_commit) # Add note to beginning of NEWS (otherwise "make dist" fails). - start_step ("Updating NEWS"); - $fullname = "pspp/NEWS"; - open (OLDFILE, '<', $fullname) - or die "opening $fullname failed: $!\n"; - open (NEWFILE, '>', "$fullname.new") - or die "creating $fullname.new failed: $!\n"; - my $found_changes = 0; - while () { - if (!$found_changes && /^Changes/) { - $found_changes = 1; - print NEWFILE < /dev/null"); - if ($? != 0) { - start_step ("Updating Gnulib to obtain commit"); - run ("$GIT fetch gnulib"); - } - run ("$GIT update-ref refs/builds/$build_number/gnulib $gnulib_commit"); - set_var ("gnulib_ref", "refs/builds/$build_number/gnulib"); + rc = os.system("%s rev-parse --verify --quiet %s^0 > /dev/null" + % (GIT, gnulib_commit)) + if rc: + start_step("Updating Gnulib to obtain commit") + run("%s fetch gnulib" % GIT) + run("%s update-ref refs/builds/%s/gnulib %s" + % (GIT, build_number, gnulib_commit)) + set_var("gnulib_ref", "refs/builds/%s/gnulib" % build_number) # Extract gnulib source. - start_step ("Extract Gnulib source"); - run ("$GIT archive --format=tar --prefix=gnulib/ $gnulib_commit | tar xf -"); + start_step("Extract Gnulib source") + run("%s archive --format=tar --prefix=gnulib/ %s | tar xf -" + % (GIT, gnulib_commit)) # Bootstrap. - start_step ("Bootstrap (make -f Smake)"); - run ("cd pspp && make -f Smake -j10", "bootstrap"); + start_step("Bootstrap (make -f Smake)") + run("cd pspp && make -f Smake -j10", "bootstrap") # Configure. - start_step ("Configure source"); - run ("cd pspp && mkdir _build && cd _build && ../configure PKG_CONFIG_PATH=\$PWD/../../../source/$ssw/inst/lib/pkgconfig", "configure"); + start_step("Configure source") + run("cd pspp && " + "mkdir _build && " + "cd _build && ../configure " + "PKG_CONFIG_PATH=$PWD/../../%s/inst/lib/pkgconfig" % ssw_dir, + "configure") # Distribute. - start_step ("Make source tarball"); - run ("cd pspp/_build && make dist", "dist"); - my $tarname = "pspp-$version.tar.gz"; - $tarball = save_result ("source distribution", "pspp/_build/$tarname", 1); + start_step("Make source tarball") + run("cd pspp/_build && make dist", "dist") + tarname = "pspp-%s.tar.gz" % version + tarball = save_result("source distribution", "pspp/_build/%s" % tarname, 1) # Save translation templates. - my $potfile = "pspp/_build/po/pspp.pot"; - $potfile = "pspp/po/pspp.pot" if ! -e $potfile; - save_result ("translation templates", $potfile); + potfile = "pspp/_build/po/pspp.pot" + if not Path(potfile).exists(): + potfile = "pspp/po/pspp.pot" + save_result("translation templates", potfile) # Build user manual - start_step ("Build user manual"); - run ("cd pspp && GENDOCS_TEMPLATE_DIR=$topdir $topdir/gendocs.sh -s doc/pspp.texi -I doc -o $resultsdir/user-manual --email bug-gnu-pspp\@gnu.org pspp \"GNU PSPP User Manual\"", "user-manual"); - saved_result ("User Manual", "user-manual"); + start_step("Build user manual") + run("cd pspp && " + "GENDOCS_TEMPLATE_DIR=%s %s/gendocs.sh -s doc/pspp.texi -I doc " + "-o %s/user-manual --email bug-gnu-pspp@gnu.org " + "pspp \"GNU PSPP User Manual\"" % (topdir, topdir, resultsdir), + "user-manual") + saved_result("User Manual", "user-manual") # Build developer's guide - start_step ("Build developers guide"); - run ("cd pspp && GENDOCS_TEMPLATE_DIR=$topdir $topdir/gendocs.sh -s doc/pspp-dev.texi -I doc -o $resultsdir/dev-guide --email bug-gnu-pspp\@gnu.org pspp-dev \"GNU PSPP Developers Guide\"", "dev-guide"); - saved_result ("Developers Guide", "dev-guide"); -} else { - start_step ("Starting from $tarball"); -} - -if ($build_binary) { - start_step ("Save tarball to Git"); - run ("GIT_DIR=$topdir/.git $topdir/git-import-tar $tarball refs/builds/$build_number/dist", "git-dist"); - set_var ("dist_ref", "refs/builds/$build_number/dist"); - set_var ("dist_commit", ref_to_commit ("refs/builds/$build_number/dist")); - - start_step ("Determining $tarball target directory"); - my $sample_filename = `zcat $tarball | tar tf - | head -1`; - my ($tarball_dir) = $sample_filename =~ m%^(?:[./])*([^/]+)/%; - set_var ("dist_dir", $tarball_dir); - - start_step ("Extracting source tarball"); - run ("zcat $tarball | (cd $builddir && tar xf -)"); - - start_step ("Extracting tar version"); - my ($version) = `cd $builddir/$tarball_dir && ./configure --version | head -1` - =~ /configure (\S+)$/; - set_var ("dist_version", $version); - my ($binary_version) = "$version-$builder-build$build_number"; - set_var ("binary_version", $binary_version); - - start_step ("Configuring"); - run ("chmod -R a-w $builddir/$tarball_dir"); - run ("chmod u+w $builddir/$tarball_dir"); - run ("chmod -R u+w $builddir/$tarball_dir/perl-module"); - run ("mkdir $builddir/$tarball_dir/_build"); - run ("chmod a-w $builddir/$tarball_dir"); - my $ok = try_run ("cd $builddir/$tarball_dir/_build && ../configure --with-perl-module --enable-relocatable --prefix='' PKG_CONFIG_PATH=\$PWD/../../../source/$ssw/inst/lib/pkgconfig CPPFLAGS=\"-I\$PWD/../../../source/$ssw/inst/include\" LDFLAGS=\"-L\$PWD/../../../source/$ssw/inst/lib\"", "bin-configure"); - for my $basename ("config.h", "config.log") { - save_result_if_exists ("build configuration", - "$builddir/$tarball_dir/_build/$basename"); - } - fail () if !$ok; - - start_step ("Build"); - run ("cd $builddir/$tarball_dir/_build && make -j10", "build"); - run ("cd $builddir/$tarball_dir/_build/perl-module && perl Makefile.PL && make -j10", "build Perl module"); - - start_step ("Install"); - run ("cd $builddir/$tarball_dir/_build && make install DESTDIR=\$PWD/pspp-$binary_version", "install"); - run ("cd ../source/$ssw && make -j10 install DESTDIR=$builddir/$tarball_dir/_build/pspp-$binary_version"); - run ("cd $builddir/$tarball_dir/_build/perl-module && make install DESTDIR=$builddir/$tarball_dir/_build/pspp-$binary_version", "install Perl module"); - run ("cd $builddir/$tarball_dir/_build/perl-module && make install DESTDIR=\$PWD/inst"); - - start_step ("Make binary distribution"); - run ("cd $builddir/$tarball_dir/_build && tar cfz pspp-$binary_version.tar.gz pspp-$binary_version"); - save_result ("binary distribution", "$builddir/$tarball_dir/_build/pspp-$binary_version.tar.gz", 1); - - start_step ("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 ("test logs", "$builddir/$tarball_dir/_build/$basename"); - } - fail () if !$ok; - - start_step ("Uninstall"); - run ("cd ../source/$ssw && make -j10 uninstall DESTDIR=$builddir/$tarball_dir/_build/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/perl-module/inst && find -type f -print) | (cd $builddir/$tarball_dir/_build/pspp-$binary_version && xargs rm)", "uninstall Perl module"); - run ("cd $builddir/$tarball_dir/_build && make distuninstallcheck distuninstallcheck_dir=\$PWD/pspp-$binary_version", "distuninstallcheck"); + start_step("Build developers guide") + run("cd pspp && " + "GENDOCS_TEMPLATE_DIR=%s %s/gendocs.sh -s doc/pspp-dev.texi " + "-I doc -o %s/dev-guide --email bug-gnu-pspp@gnu.org " + "pspp-dev \"GNU PSPP Developers Guide\"" + % (topdir, topdir, resultsdir), "dev-guide") + saved_result("Developers Guide", "dev-guide") +else: + start_step("Starting from %s" % tarball) + +if build_binary: + start_step("Save tarball to Git") + run("GIT_DIR=%s/.git %s/git-import-tar %s refs/builds/%s/dist" + % (topdir, topdir, tarball, build_number), "git-dist") + set_var("dist_ref", "refs/builds/%s/dist" % build_number) + set_var("dist_commit", ref_to_commit("refs/builds/%s/dist" % build_number)) + + start_step("Determining %s target directory" % tarball) + sample_filename = backquotes("zcat %s | tar tf - | head -1" % tarball) + tarball_dir = re.match('(?:[./])*([^/]+)/', sample_filename).group(1) + set_var("dist_dir", tarball_dir) + + start_step("Extracting source tarball") + run("zcat %s | (cd %s && tar xf -)" % (tarball, builddir)) + + start_step("Extracting tar version") + version_line = backquotes("cd %s/%s && ./configure --version | head -1" + % (builddir, tarball_dir)) + version = re.search(r'configure (\S+)$', version_line).group(1) + set_var("dist_version", version) + binary_version = "%s-%s-build%s" % (version, builder, build_number) + set_var("binary_version", binary_version) + + start_step("Configuring") + run("chmod -R a-w %s/%s" % (builddir, tarball_dir)) + run("chmod u+w %s/%s" % (builddir, tarball_dir)) + run("chmod -R u+w %s/%s/perl-module" % (builddir, tarball_dir)) + run("mkdir %s/%s/_build" % (builddir, tarball_dir)) + run("chmod a-w %s/%s" % (builddir, tarball_dir)) + ok = try_run( + "cd %(builddir)s/%(tarball_dir)s/_build && ../configure " + "--with-perl-module --enable-relocatable --prefix='' " + "PKG_CONFIG_PATH=$PWD/../../../source/%(ssw_dir)s/inst/lib/pkgconfig " + "CPPFLAGS=\"-I$PWD/../../../source/%(ssw_dir)s/inst/include\" " + "LDFLAGS=\"-L$PWD/../../../source/%(ssw_dir)s/inst/lib\"" + % {"builddir": builddir, + "tarball_dir": tarball_dir, + "ssw_dir": ssw_dir}, + "bin-configure") + for basename in ("config.h", "config.log"): + save_result_if_exists("build configuration", + "%s/%s/_build/%s" % (builddir, tarball_dir, + basename)) + if not ok: + fail() + + start_step("Build") + run("cd %s/%s/_build && make -j10" % (builddir, tarball_dir), "build") + run("cd %s/%s/_build/perl-module && perl Makefile.PL && make -j10" + % (builddir, tarball_dir), "build Perl module") + + start_step("Install") + run("cd %s/%s/_build && make install DESTDIR=$PWD/pspp-%s" + % (builddir, tarball_dir, binary_version), "install") + run("cd ../source/%s && make -j10 install DESTDIR=%s/%s/_build/pspp-%s" + % (ssw_dir, builddir, tarball_dir, binary_version)) + run("cd %s/%s/_build/perl-module && " + "make install DESTDIR=%s/%s/_build/pspp-%s" + % (builddir, tarball_dir, builddir, tarball_dir, binary_version), + "install Perl module") + run("cd %s/%s/_build/perl-module && make install DESTDIR=$PWD/inst" + % (builddir, tarball_dir)) + + start_step("Make binary distribution") + run("cd %s/%s/_build && tar cfz pspp-%s.tar.gz pspp-%s" + % (builddir, tarball_dir, binary_version, binary_version)) + save_result("binary distribution", "%s/%s/_build/pspp-%s.tar.gz" + % (builddir, tarball_dir, binary_version), 1) + + start_step("Check") + ok = try_run("cd %s/%s/_build && make check" % (builddir, tarball_dir), + "check") + for basename in ("tests/testsuite.log", "tests/testsuite.dir"): + save_result_if_exists("test logs", "%s/%s/_build/%s" + % (builddir, tarball_dir, basename)) + if not ok: + fail() + + start_step("Uninstall") + run("cd ../source/%s && make -j10 uninstall DESTDIR=%s/%s/_build/pspp-%s" + % (ssw_dir, builddir, tarball_dir, binary_version)) + run("cd %s/%s/_build && make uninstall DESTDIR=$PWD/pspp-%s" + % (builddir, tarball_dir, binary_version), "uninstall") + + start_step("Check uninstall") + run("(cd %s/%s/_build/perl-module/inst && find -type f -print) | " + "(cd %s/%s/_build/pspp-%s && xargs rm)" + % (builddir, tarball_dir, + builddir, tarball_dir, binary_version), "uninstall Perl module") + run("cd %s/%s/_build && " + "make distuninstallcheck distuninstallcheck_dir=$PWD/pspp-%s" + % (builddir, tarball_dir, binary_version), + "distuninstallcheck") # distcleancheck -} - -start_step ("Success"); -sub usage { - print <) { - print LOG $_; - - my $elapsed = time () - $start; - my $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", " " x 79, "\r" unless $batch; - - write_timing ($id, time () - $start) if defined ($id); - - return 1 if !$?; - - if ($? & 127) { - printf STDERR "%s: child died with signal %d, %s coredump\n", - $command, ($? & 127), ($? & 128) ? 'with' : 'without'; - } else { - 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 () { - 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 () { - 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$logfile\nfor details.\n"; -} +start_step("Success") -- 2.30.2