6 use Getopt::Long qw(:config bundling no_ignore_case);
18 GetOptions ("h|help" => \$help,
19 "binary!" => \$build_binary,
21 "o|output=s" => \$builddir,
22 "build-number=i" => \$build_number);
26 die "$0: exactly one or two nonoption arguments are required\n"
27 if @ARGV != 1 && @ARGV != 2;
31 $tarball = File::Spec->rel2abs ($ARGV[0]);
33 # Tarball will be generated later.
36 # Select build number.
37 if (!defined ($build_number)) {
38 $build_number = POSIX::strftime("%Y%m%d%H%M%S", localtime);
41 my $topdir = dirname ($0);
42 $topdir = cwd () . "/$topdir" if $topdir !~ m%^/%;
44 # Create build directory.
45 if (!defined ($builddir)) {
46 $builddir = "builds/$build_number";
47 mkdir "builds" or die "builds: mkdir: $!\n" if ! -d "builds";
49 $builddir = File::Spec->rel2abs ($builddir);
50 -d $builddir or mkdir $builddir or die "$builddir: mkdir: $!\n";
51 chdir ($builddir) or die "$builddir: chdir: $!\n";
53 our $resultsdir = "$builddir/results";
54 mkdir $resultsdir or die "$resultsdir: mkdir: $!\n";
55 mkdir "$resultsdir/vars" or die "$resultsdir/vars: mkdir: $!\n";
57 my $varsfile = "$resultsdir/VARS";
58 open (VARS, '>', $varsfile) or die "creating $varsfile failed: $!\n";
61 our $logfile = "$resultsdir/LOG";
62 open (LOG, '>', $logfile) or die "creating $logfile failed: $!\n";
64 my $build_host = `hostname`;
66 set_var ("build_host", $build_host);
67 set_var ("build_number", $build_number);
71 print LOG "
\f\n$msg\n";
72 print "$msg\n" unless $batch;
76 my ($var, $value) = @_;
78 print VARS "$var=$value\n";
80 print "\t$var=$value\n" unless $batch;
82 open (VAR, '>', "$resultsdir/vars/$var")
83 or die "creating $resultsdir/$var failed: $!\n";
89 my ($name, $product) = @_;
90 start_step ("Saving $name: $product");
94 my ($name, $src, $rm_src) = @_;
95 my ($basename) = $src;
96 $basename =~ s(^.*/)();
97 my ($dst) = "$resultsdir/$basename";
99 saved_result ($name, $basename);
100 run ("cp -R $src $dst");
102 if (defined ($rm_src) && $rm_src) {
109 sub save_result_if_exists {
110 my ($name, $src, $rm_src) = @_;
114 start_step ("$src does not exist, cannot save");
118 my $GIT = "git --git-dir=$topdir/.git";
121 my ($repo, $branch) = @ARGV;
124 start_step ("Fetch $repo, branch $branch");
125 run ("$GIT fetch $repo +$branch:refs/builds/$build_number/pspp");
127 # Get revision number.
128 my $revision = `$GIT rev-parse refs/builds/$build_number/pspp`;
130 set_var ("pspp_commit", $revision);
131 my $abbrev_commit = substr ($revision, 0, 6);
134 start_step ("Extract branch into source directory");
135 run ("$GIT archive --format=tar --prefix=pspp$build_number/ refs/builds/$build_number/pspp | tar xf -");
137 # Extract version number.
138 start_step ("Extract repository version number");
139 my $trace = `cd pspp$build_number && autoconf -t AC_INIT`;
141 my ($file, $line, $macro, $package, $repo_version, @rest)
142 = split (':', $trace);
143 set_var ("repo_version", $repo_version);
145 # Is this a "gnits" mode tree?
146 start_step ("Checking Automake mode");
147 open (MAKEFILE_AM, '<', "pspp$build_number/Makefile.am");
149 while (<MAKEFILE_AM>) {
156 set_var ("am_mode", $am_mode);
158 # Generate version number for build.
159 # We want to append -g012345, but if we're in Gnits mode and the
160 # version number already has a hyphen, we have to omit it.
161 start_step ("Generate build version number");
162 my $version = $repo_version;
163 $version .= '-' unless $version =~ /-/;
164 $version .= "g$abbrev_commit";
165 set_var ("version", $version);
167 # Append -g012345 to configure.ac version number.
168 start_step ("Updating version number in $file");
169 my $fullname = "pspp$build_number/$file";
170 open (OLDFILE, '<', $fullname)
171 or die "opening $fullname failed: $!\n";
172 open (NEWFILE, '>', "$fullname.new")
173 or die "creating $fullname.new failed: $!\n";
178 print NEWFILE "AC_INIT([$package], [$version]";
179 print NEWFILE ", [$_]" foreach @rest;
185 rename ("$fullname.new", $fullname)
186 or die "rename $fullname.new to $fullname failed: $!\n";
188 # Get Gnulib commit number.
189 start_step ("Reading README.Git to find Gnulib commit number");
191 $fullname = "pspp$build_number/README.Git";
192 open (README_GIT, '<', $fullname)
193 or die "opening $fullname failed: $!\n";
194 while (<README_GIT>) {
195 ($gnulib_commit) = /^\s+commit ([0-9a-fA-F]{8,})/ and last;
197 die "$fullname does not specify a Git commit number\n"
198 if !defined ($gnulib_commit);
199 set_var ("gnulib_commit", $gnulib_commit);
201 # Add note to beginning of NEWS (otherwise "make dist" fails).
202 start_step ("Updating NEWS");
203 $fullname = "pspp$build_number/NEWS";
204 open (OLDFILE, '<', $fullname)
205 or die "opening $fullname failed: $!\n";
206 open (NEWFILE, '>', "$fullname.new")
207 or die "creating $fullname.new failed: $!\n";
208 my $found_changes = 0;
210 if (!$found_changes && /^Changes/) {
213 Changes from $repo_version to $version:
215 * Built from PSPP commit $revision
216 in branch $branch on host $build_host.
218 * Built from Gnulib commit $gnulib_commit.
226 rename ("$fullname.new", $fullname)
227 or die "rename $fullname.new to $fullname failed: $!\n";
229 # If we don't already have that Gnulib commit, update Gnulib.
230 system ("$GIT rev-parse --verify --quiet $gnulib_commit");
232 start_step ("Updating Gnulib to obtain commit");
233 run ("$GIT fetch gnulib");
235 run ("$GIT update-ref refs/builds/$build_number/gnulib $gnulib_commit");
237 # Extract gnulib source.
238 start_step ("Extract Gnulib source");
239 run ("$GIT archive --format=tar --prefix=gnulib/ $gnulib_commit | tar xf -");
242 start_step ("Bootstrap (make -f Smake)");
243 run ("cd pspp$build_number && make -f Smake", "bootstrap");
246 start_step ("Configure source");
247 run ("cd pspp$build_number && mkdir _build && cd _build && ../configure", "configure");
250 start_step ("Make source tarball");
251 run ("cd pspp$build_number/_build && make dist", "dist");
252 my $tarname = "pspp-$version.tar.gz";
253 $tarball = save_result ("source distribution", "pspp$build_number/_build/$tarname", 1);
256 start_step ("Build user manual");
257 run ("cd pspp$build_number && cp _build/doc/*.texi doc/");
258 run ("cd pspp$build_number && GENDOCS_TEMPLATE_DIR=$topdir $topdir/gendocs.sh -s doc/pspp.texinfo -o $resultsdir/user-manual --email bug-gnu-pspp\@gnu.org pspp \"GNU PSPP User Manual\"", "user-manual");
259 saved_result ("User Manual", "user-manual");
261 # Build developer's guide
262 start_step ("Build developers guide");
263 run ("cd pspp$build_number && GENDOCS_TEMPLATE_DIR=$topdir $topdir/gendocs.sh -s doc/pspp-dev.texinfo -o $resultsdir/dev-guide --email bug-gnu-pspp\@gnu.org pspp-dev \"GNU PSPP Developers Guide\"", "dev-guide");
264 saved_result ("Developers Guide", "dev-guide");
268 start_step ("Determining $tarball target directory");
269 my $sample_filename = `zcat $tarball | tar tf - | head -1`;
270 my ($tarball_dir) = $sample_filename =~ m%^(?:[./])*([^/]+)/%;
271 set_var ("dist_dir", $tarball_dir);
273 start_step ("Extracting source tarball");
274 run ("zcat $tarball | (cd $builddir && tar xf -)");
276 start_step ("Extracting tar version");
277 my ($version) = `cd $builddir/$tarball_dir && ./configure --version | head -1`
278 =~ /configure (\S+)$/;
279 set_var ("dist_version", $version);
280 my ($binary_version) = "$version-$build_host-build$build_number";
281 set_var ("binary_version", $binary_version);
283 start_step ("Configuring");
284 run ("chmod -R a-w $builddir/$tarball_dir");
285 run ("chmod u+w $builddir/$tarball_dir");
286 run ("mkdir $builddir/$tarball_dir/_build");
287 run ("chmod a-w $builddir/$tarball_dir");
288 my $ok = try_run ("cd $builddir/$tarball_dir/_build && ../configure --enable-relocatable --prefix=''", "bin-configure");
289 for my $basename ("config.h", "config.log") {
290 save_result_if_exists ("build configuration",
291 "$builddir/$tarball_dir/_build/$basename");
295 start_step ("Build");
296 run ("cd $builddir/$tarball_dir/_build && make", "build");
298 start_step ("Install");
299 run ("cd $builddir/$tarball_dir/_build && make install DESTDIR=\$PWD/pspp-$binary_version", "install");
301 start_step ("Make binary distribution");
302 run ("cd $builddir/$tarball_dir/_build && tar cfz pspp-$binary_version.tar.gz pspp-$binary_version");
303 save_result ("binary distribution", "$builddir/$tarball_dir/_build/pspp-$binary_version.tar.gz", 1);
305 start_step ("Check");
306 $ok = try_run ("cd $builddir/$tarball_dir/_build && make check", "check");
307 for my $basename ("tests/testsuite.log", "tests/testsuite.dir") {
308 save_result_if_exists ("test logs", "$builddir/$tarball_dir/_build/$basename");
312 start_step ("Uninstall");
313 run ("cd $builddir/$tarball_dir/_build && make uninstall DESTDIR=\$PWD/pspp-$binary_version", "uninstall");
315 start_step ("Check uninstall");
316 run ("cd $builddir/$tarball_dir/_build && make distuninstallcheck distuninstallcheck_dir=\$PWD/pspp-$binary_version", "distuninstallcheck");
321 start_step ("Success");
325 $0, for building and testing PSPP
326 usage: $0 [OPTIONS] [TARBALL | REPO REFSPEC]
327 where TARBALL is the name of a tarball produced by "make dist"
328 or REPO and REFSPEC are a Git repo and refspec (e.g. branch) to clone.
331 --help Print this usage message and exit
332 --no-binary Build source tarballs but no binaries.
333 --batch Do not print progress to stdout.
339 fail () if !try_run (@_);
343 my ($command, $id) = @_;
345 print LOG "$command\n";
347 my $pid = open (COMMAND, '-|');
348 if (!defined ($pid)) {
349 die "fork failed: $!\n";
353 die "$command: exec failed: $!\n";
356 my ($start) = time ();
357 my ($est_time) = (defined ($id) ? read_timing ($id) : 0);
364 my $elapsed = time () - $start;
365 my $progress = sprintf "%d lines logged, %d s elapsed",
368 my $left = $est_time - $elapsed;
370 $progress .= sprintf ", ETA %d s", $left;
373 print "\r$progress", " " x (79 - length ($progress)), "\r"
377 print "\r", " " x 79, "\r" unless $batch;
379 write_timing ($id, time () - $start) if defined ($id);
384 printf STDERR "%s: child died with signal %d, %s coredump\n",
385 $command, ($? & 127), ($? & 128) ? 'with' : 'without';
387 printf STDERR "%s: child exited with value %d\n", $command, $? >> 8;
394 open (TIMINGS, "<", "$topdir/timings") or return 0;
397 my ($key, $value) = /^([^=]+)=(.*)/ or next;
398 return $value if $key eq $id;
405 my ($id, $time) = @_;
407 open (NEWTIMINGS, ">", "$topdir/timings.tmp$$") or return;
409 if (open (OLDTIMINGS, "<", "$topdir/timings")) {
410 while (<OLDTIMINGS>) {
411 if (my ($key, $value) = /^([^=]+)=(.*)/) {
419 print NEWTIMINGS "$id=$time\n";
422 rename ("$topdir/timings.tmp$$", "$topdir/timings");
426 die "Build failed, refer to:\n\t$logfile\nfor details.\n";