From 82cd5d32c86d7bfcc5a1c90e02c182cf790f4c68 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 8 Feb 2010 21:16:30 -0800 Subject: [PATCH] work on autobuild system --- build-pspp | 131 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 85 insertions(+), 46 deletions(-) diff --git a/build-pspp b/build-pspp index a20152e284..92e1d9a266 100755 --- a/build-pspp +++ b/build-pspp @@ -18,55 +18,67 @@ my $builder = `hostname`; chomp $builder; # Select build number. -my $buildnumber = POSIX::strftime("%Y%m%d%H%M%S", localtime); -print "\tBUILDNUMBER=$buildnumber\n"; +my $build_number = POSIX::strftime("%Y%m%d%H%M%S", localtime); # Create build directory. -my $builddir = "builds/$buildnumber"; -print "Create $builddir\n"; +my $builddir = "builds/$build_number"; mkdir "builds" or die "builds: mkdir: $!\n" if ! -d "builds"; mkdir $builddir or die "$builddir: mkdir: $!\n"; -$resultsdir = "$builddir/results"; +our $resultsdir = "$builddir/results"; mkdir $resultsdir or die "$resultsdir: mkdir: $!\n"; +mkdir "$resultsdir/vars" or die "$resultsdir/vars: mkdir: $!\n"; -$logfile = "$resultsdir/LOG"; +my $logfile = "$resultsdir/LOG"; open (LOG, '>', $logfile) or die "creating $logfile failed: $!\n"; -$varsfile = "$resultsdir/VARS"; -open (VARS, '>', $varsfile) or die "creating $varsfile failed: $!\n"; - - +set_var ("builder", $builder); +set_var ("build_number", $build_number); +sub start_step { + my ($msg) = @_; + print LOG " \n$msg\n"; + print "$msg\n"; +} +sub set_var { + my ($var, $value) = @_; + 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"; +} my $tarball; if (@ARGV == 2) { my ($repo, $branch) = @ARGV; # Fetch branch - print "Fetch $repo, branch $branch\n"; + start_step ("Fetch $repo, branch $branch"); run ("git fetch $repo +$branch:buildtmp/$$/pspp"); # Get revision number. my $revision = `git rev-parse buildtmp/$$/pspp`; chomp $revision; - print "\tREVISION=$revision\n"; - my $abbrev_revision = substr ($revision, 0, 6); + set_var ("pspp_commit", $revision); + my $abbrev_commit = substr ($revision, 0, 6); # Extract source. - print "Extract branch into $builddir/pspp$buildnumber\n"; - run ("git archive --format=tar --prefix=pspp$buildnumber/ buildtmp/$$/pspp | (cd $builddir && tar xf -)"); + start_step ("Extract branch into $builddir/pspp$build_number"); + run ("git archive --format=tar --prefix=pspp$build_number/ buildtmp/$$/pspp | (cd $builddir && tar xf -)"); # Extract version number. - print "Extract version number\n"; - my $trace = `cd $builddir/pspp$buildnumber && autoconf -t AC_INIT`; + start_step ("Extract version number"); + my $trace = `cd $builddir/pspp$build_number && autoconf -t AC_INIT`; chomp $trace; my ($file, $line, $macro, $package, $version, @rest) = split (':', $trace); - print "\tVERSION=$version\n"; + set_var ("pspp_version", $version); # Append -g012345 to AC_INIT version number. - my $fullname = "$builddir/pspp$buildnumber/$file"; + start_step ("Adding -g$abbrev_commit to version number"); + my $fullname = "$builddir/pspp$build_number/$file"; open (OLDFILE, '<', $fullname) or die "opening $fullname failed: $!\n"; open (NEWFILE, '>', "$fullname.new") @@ -75,7 +87,7 @@ if (@ARGV == 2) { if ($. != $line) { print NEWFILE $_; } else { - print NEWFILE "AC_INIT([$package], [$version-g$abbrev_revision]"; + print NEWFILE "AC_INIT([$package], [$version-g$abbrev_commit]"; print NEWFILE ", [$_]" foreach @rest; print NEWFILE ")\n"; } @@ -86,7 +98,8 @@ if (@ARGV == 2) { or die "rename $fullname.new to $fullname failed: $!\n"; # Add note to beginning of NEWS (otherwise "make dist" fails). - $fullname = "$builddir/pspp$buildnumber/NEWS"; + start_step ("Updating NEWS"); + $fullname = "$builddir/pspp$build_number/NEWS"; open (OLDFILE, '<', $fullname) or die "opening $fullname failed: $!\n"; open (NEWFILE, '>', "$fullname.new") @@ -96,7 +109,7 @@ if (@ARGV == 2) { if (!$found_changes && /^Changes/) { $found_changes = 1; print NEWFILE <) { @@ -120,74 +134,79 @@ EOF } die "$fullname does not specify a Git commit number\n" if !defined ($gnulib_commit); - print "\tGNULIB_REVISION=$gnulib_commit\n"; + set_var ("gnulib_commit", $gnulib_commit); # If we don't already have that Gnulib commit, update Gnulib. `git rev-parse $gnulib_commit`; if ($? != 0) { + start_step ("Updating Gnulib to obtain commit"); run ("git fetch gnulib"); } # Extract gnulib source. + start_step ("Extract Gnulib source"); run ("git archive --format=tar --prefix=gnulib/ $gnulib_commit | (cd $builddir && tar xf -)"); # Bootstrap. - run ("cd $builddir/pspp$buildnumber && make -f Smake"); + start_step ("Bootstrap (make -f Smake)"); + run ("cd $builddir/pspp$build_number && make -f Smake"); # Configure. - run ("cd $builddir/pspp$buildnumber && mkdir _build && cd _build && ../configure"); + start_step ("Configure source"); + run ("cd $builddir/pspp$build_number && mkdir _build && cd _build && ../configure"); # Distribute. - run ("cd $builddir/pspp$buildnumber/_build && make dist"); + start_step ("Make dist tarball"); + run ("cd $builddir/pspp$build_number/_build && make dist"); - $tarball = "$builddir/pspp$buildnumber/_build/pspp-$version-g$abbrev_revision.tar.gz"; + $tarball = "$builddir/pspp$build_number/_build/pspp-$version-g$abbrev_commit.tar.gz"; } else { $tarball = $ARGV[0]; } -print "Determining $tarball target directory\n"; +start_step ("Determining $tarball target directory"); my $sample_filename = `zcat $tarball | tar tf - | head -1`; my ($tarball_dir) = $sample_filename =~ m%^(?:[./])*([^/]+)/%; -print "\tTARBALL_DIR=$tarball_dir\n"; +set_var ("dist_dir", $tarball_dir); -print "Extracting $tarball into $builddir/$tarball_dir\n"; +start_step ("Extracting $tarball into $builddir/$tarball_dir"); run ("zcat $tarball | (cd $builddir && tar xf -)"); -print "Extracting tar version\n"; +start_step ("Extracting tar version"); my ($version) = `cd $builddir/$tarball_dir && ./configure --version | head -1` =~ /configure (\S+)$/; -print "\tVERSION=$version\n"; -my ($binary_version) = "$version-$builder-build$buildnumber"; -print "\tBINARY_VERSION=$version\n"; +set_var ("dist_version", $version); +my ($binary_version) = "$version-$builder-build$build_number"; +set_var ("binary_version", $binary_version); -print "Configuring\n"; +start_step ("Configuring"); run ("chmod -R a-w $builddir/$tarball_dir"); run ("chmod u+w $builddir/$tarball_dir"); run ("mkdir $builddir/$tarball_dir/_build"); run ("chmod a-w $builddir/$tarball_dir"); run ("cd $builddir/$tarball_dir/_build && ../configure --enable-relocatable --prefix=''"); -print "Build\n"; +start_step ("Build"); run ("cd $builddir/$tarball_dir/_build && make"); -print "Install\n"; +start_step ("Install"); run ("cd $builddir/$tarball_dir/_build && make install DESTDIR=\$PWD/pspp-$binary_version"); -print "Make binary distribution\n"; +start_step ("Make binary distribution"); run ("cd $builddir/$tarball_dir/_build && tar cfz pspp-$binary_version.tar.gz pspp-$binary_version"); -print "Check\n"; +start_step ("Check"); run ("cd $builddir/$tarball_dir/_build && make check"); -print "Uninstall\n"; +start_step ("Uninstall"); run ("cd $builddir/$tarball_dir/_build && make uninstall DESTDIR=\$PWD/pspp-$binary_version"); -print "Check uninstall\n"; +start_step ("Check uninstall"); run ("cd $builddir/$tarball_dir/_build && make distuninstallcheck distuninstallcheck_dir=\$PWD/pspp-$binary_version"); # distcleancheck -print "Success\n"; +start_step ("Success"); sub usage { print <) { + print LOG $_; + print "\r", $i++; + } + close (COMMAND); + print "\r \r"; + + if ($? == 0) { + return; } elsif ($? & 127) { printf "%s: child died with signal %d, %s coredump\n", $command, ($? & 127), ($? & 128) ? 'with' : 'without'; -- 2.30.2