Timothy G Abbott <[EMAIL PROTECTED]> writes:

> I think sbuild should support appending a string to the version number
> of the package at build time, similar in function to --binNMU, but
> with support for appending arbitrary strings to the version numbers.
[...]

> One thing that I do not handle in my patch is how one should append
> failed builds using --append-to-version to the job log, since I'm not
> familiar with the parsers for the job log that are in use.  My patch
> contains a comment noting this in the relevant section of the code;
> this should be replaced with whatever the right solution is.

Many thanks for the patch.  I reviewed the patch, and it looks good.
A slightly modified version of this is attached; I altered the
binNMU_version function for compatibility with other programs using
binNMU_version in Sbuild.pm who won't provide the third argument
(wanna-build).  I also added some further details to your comment
about the failed builds.

The patch looks good and works, but I did find a bug with combining
--append-to-version and --make-binNMU:


% sbuild --append-to-version=rleigh --make-binNMU=Test. --binNMU=2 -d unstable 
-s -A dadadodo_1.04-3
[...]
dpkg-shlibdeps -Tdebian/dadadodo.substvars -dDepends \
                        
/build/rleigh/dadadodo_1.04-3/debian/dadadodo/usr/bin/dadadodo
install -d /build/rleigh/dadadodo_1.04-3/debian/dadadodo/DEBIAN
cd /build/rleigh/dadadodo_1.04-3/debian/dadadodo >/dev/null ;\
         find * -type f ! -regex '^DEBIAN/.*' -print0 | xargs -r0 md5sum > 
DEBIAN/md5sums
dpkg-gencontrol -isp -pdadadodo -Tdebian/dadadodo.substvars \
                        -P/build/rleigh/dadadodo_1.04-3/debian/dadadodo
dpkg --build /build/rleigh/dadadodo_1.04-3/debian/dadadodo ..
dpkg-deb: building package `dadadodo' in 
`../dadadodo_1.04-3rleigh+b2_powerpc.deb'.
 dpkg-genchanges  >../dadadodo_1.04-3rleigh+b2_powerpc.changes
dpkg-genchanges: failure: cannot open .dsc file ../dadadodo_1.04-3rleigh.dsc: 
No such file or directory
dpkg-buildpackage: failure: dpkg-genchanges gave error exit status 2
******************************************************************************
Build finished at 20080420-1259
FAILED [dpkg-buildpackage died]
------------------------------------------------------------------------------
******************************************************************************
Finished at 20080420-1259
Build needed 00:00:13, 404k disk space


I'm not sure why dpkg-genchanges fails here: I can run it with the
same version outside the chroot and it works fine.  It may be a bug in
dpkg-buildpackage, but I'm not really sure about that.

Due to this problem, I haven't applied the patch as yet.  Once this
bug can be fixed, I'll be happy to apply the patch.  If you have any
idea what might be causing this, that would expedite merging this
change.

By the way, the patch is diffed against the latest version in our GIT
repository.  You can get a copy with

  % git clone git://git.debian.org/git/buildd-tools/sbuild.git sbuild

While diffs against earlier versions were fine in this case, it does
make things easier if patches are based against the master head.


There is also a problem here in that sbuild does not clean up the
build directory and generated files in the chroot when
dpkg-buildpackage fails at this point.  I'm thinking of adding a
temporary directory inside /build/$user for each build so that the
entire directory can be purged on failure.


Regards,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.
diff --git a/bin/sbuild b/bin/sbuild
index 22f09fb..673cb67 100755
--- a/bin/sbuild
+++ b/bin/sbuild
@@ -147,6 +147,7 @@ $main::chroot_build_dir = "";
 @main::toolchain_pkgs = ();
 $main::override_distribution = 0;
 $main::sub_task = "initialisation";
+$main::append_to_version = "";
 
 # Be verbose by default if on a tty
 if (-t STDIN && -t STDOUT && $main::verbose == 0) {
@@ -190,6 +191,7 @@ exit 1 if !GetOptions ("arch=s" => \$main::user_arch,
 			   $main::binNMUver ||= 1;
 		       },
 		       "binNMU=i" => \$main::binNMUver,
+		       "append-to-version=s" => \$main::append_to_version,
 		       "database=s" => \$main::database,
 		       "D|debug+" => \$conf::debug,
 		       "apt-update" => \$conf::apt_update,
@@ -308,9 +310,9 @@ foreach $dscfile (@ARGV) {
 	# TODO: This should be $pkg_start_time, set in build().
 	my $date = strftime("%Y%m%d-%H%M",localtime);
 
-	if ($main::binNMU) {
+	if ($main::binNMU || $main::append_to_version) {
 	    $tpkg =~ /^([^_]+)_([^_]+)(.*)$/;
-	    $tpkg = $1 . "_" . binNMU_version($2,$main::binNMUver);
+	    $tpkg = $1 . "_" . binNMU_version($2,$main::binNMUver,$main::append_to_version);
 	    $main::binNMU_name = $tpkg;
 	    $tpkg .= $3;
 	}
@@ -661,8 +663,8 @@ sub build ($$) {
 	    return 0;
 	}
 	my $tree_version = $1;
-	my $cmp_version = ($main::binNMU && -f "$dir/debian/.sbuild-binNMU-done") ?
-	    binNMU_version($version,$main::binNMUver) : $version;
+	my $cmp_version = (($main::binNMU || $main::append_to_version) && -f "$dir/debian/.sbuild-binNMU-done") ?
+	    binNMU_version($version,$main::binNMUver,$main::append_to_version) : $version;
 	if ($tree_version ne $cmp_version) {
 	    print PLOG "The unpacked source tree $dir is version ".
 		"$tree_version, not wanted $cmp_version!\n";
@@ -694,7 +696,7 @@ sub build ($$) {
     }
 
     $main::pkg_fail_stage = "hack-binNMU";
-    if ($main::binNMU && ! -f "debian/.sbuild-binNMU-done") {
+    if (($main::binNMU || $main::append_to_version) && ! -f "debian/.sbuild-binNMU-done") {
 	if (open( F, "<debian/changelog" )) {
 	    my($firstline, $text);
 	    $firstline = "";
@@ -703,7 +705,7 @@ sub build ($$) {
 	    close( F );
 	    $firstline =~ /^(\S+)\s+\((\S+)\)\s+([^;]+)\s*;\s*urgency=(\S+)\s*$/;
 	    my ($name, $version, $dists, $urgent) = ($1, $2, $3, $4);
-	    my $NMUversion = binNMU_version($version,$main::binNMUver);
+	    my $NMUversion = binNMU_version($version,$main::binNMUver,$main::append_to_version);
 	    chomp( my $date = `date -R` );
 	    if (!open( F, ">debian/changelog" )) {
 		print PLOG "Can't open debian/changelog for binNMU hack: $!\n";
@@ -712,9 +714,15 @@ sub build ($$) {
 	    }
 	    $dists = $main::distribution;
 	    print F "$name ($NMUversion) $dists; urgency=low\n\n";
-	    print F "  * Binary-only non-maintainer upload for $main::arch; ",
+	    if ($main::append_to_version) {
+		print F "  * Append $main::append_to_version to version; no source changes\n";
+	    }
+	    if ($main::binNMU) {
+		print F "  * Binary-only non-maintainer upload for $main::arch; ",
 	    "no source changes.\n";
-	    print F "  * ", join( "    ", split( "\n", $main::binNMU )), "\n\n";
+		print F "  * ", join( "    ", split( "\n", $main::binNMU )), "\n";
+	    }
+	    print F "\n";
 	    print F " -- $conf::maintainer_name  $date\n\n";
 
 	    print F $firstline, $text;
@@ -854,7 +862,8 @@ EOF
 	}
 
 	$changes = "${pkg}_".
-	    ($main::binNMU ? binNMU_version($sversion,$main::binNMUver) : $sversion).
+	    (($main::binNMU || $main::append_to_version) ? 
+	     binNMU_version($sversion,$main::binNMUver,$main::append_to_version) : $sversion).
 	    "_$main::arch.changes";
 	my @cfiles;
 	if (-r "$main::chroot_build_dir/$changes") {
@@ -2525,6 +2534,14 @@ sub shutdown ($) {
     if (open( F, ">>$f" )) {
 	foreach $job (@npkgs) {
 	    next if grep( /^\Q$job\E\s/, @pkgs );
+            # This is not correctly handled with --append-to-version
+	    # because I'm not sure what the line below should look like.
+	    # -- Timothy G Abbott
+	    # REDO is read by buildd, so the format buildd reads would
+	    # need updating at the same time.  --append-to-version
+	    # would most likely not be used by buildd, so we will
+	    # leave the code as is for the time being.
+	    # -- Roger Leigh
 	    if (not defined $main::binNMUver) {
 		print F "$job $main::distribution\n";
 	    } else {
@@ -2776,6 +2793,7 @@ sub add_space_entry ($$) {
 
 sub dump_main_state () {
     print STDERR Data::Dumper->Dump([EMAIL PROTECTED]::additional_deps,
+				     $main::append_to_version,
 				     $main::arch,
 				     $main::auto_giveback,
 				     $main::auto_giveback_host,
@@ -2825,6 +2843,7 @@ sub dump_main_state () {
 				     $main::useSNAP,
 				     $main::verbose],
 				    [qw(@main::additional_deps
+					$main::append_to_version
 					$main::arch
 					$main::auto_giveback
 					$main::auto_giveback_host
diff --git a/lib/Sbuild.pm b/lib/Sbuild.pm
index 46c106c..a72835c 100644
--- a/lib/Sbuild.pm
+++ b/lib/Sbuild.pm
@@ -42,7 +42,7 @@ sub do_version_cmp ($$);
 sub order ($);
 sub version_cmp_single ($$);
 sub split_version ($);
-sub binNMU_version ($$);
+sub binNMU_version ($$$);
 sub parse_date ($);
 sub isin ($@);
 
@@ -179,11 +179,19 @@ sub split_version ($) {
 	return( $epoch, $vers, $revision );
 }
 
-sub binNMU_version ($$) {
+sub binNMU_version ($$$) {
 	my $v = shift;
 	my $binNMUver = shift;
+	my $append_to_version = shift;
 
-	return "$v+b$binNMUver";
+	my $ver = $v;
+	if (defined($append_to_version) && $append_to_version) {
+	    $ver .= $append_to_version;
+	}
+	if (defined($binNMUver) && $binNMUver) {
+	    $ver .= "+b$binNMUver";
+	}
+	return $ver;
 }
 
 my %monname = ('jan', 0, 'feb', 1, 'mar', 2, 'apr', 3, 'may', 4, 'jun', 5,
diff --git a/man/sbuild.1.in b/man/sbuild.1.in
index 41d5607..d79f109 100644
--- a/man/sbuild.1.in
+++ b/man/sbuild.1.in
@@ -152,14 +152,23 @@ Be quiet.  This is the opposite of \-\-verbose.
 .IR "\-\-make\-binNMU=<entry>"
 With this option, \fBsbuild\fR will create a new changelog entry in
 debian/changelog of every package built. The version number will be in the
-format for binary-only NMUs (three dotted parts in the Debian revision); the
-maintainer is set to the maintainer name configured for \fBsbuild\fR. The
-\fIentry\fR parameter will be used as a changelog entry after a fixed one
-\[lq]Binary-only non-maintainer upload for ARCH -- no source
-changes\[rq]. Please note that the versions in the \fIpackage-to-build\fR
-arguments still have to be the unmodified (non-NMU ones) so that sources can be
-found. The version number in log files and mails will be modified by
-\fBsbuild\fR automatically.
+format for binary-only NMUs (ending with +b<number>); the maintainer is set to
+the maintainer name configured for \fBsbuild\fR. The \fIentry\fR parameter will
+be used as a changelog entry after a fixed one \[lq]Binary-only non-maintainer
+upload for ARCH -- no source changes\[rq]. Please note that the versions in the
+\fIpackage-to-build\fR arguments still have to be the unmodified (non-NMU ones)
+so that sources can be found. The version number in log files and mails will be
+modified by \fBsbuild\fR automatically.
+.TP
+.IR "\-\-binNMU=<number>"
+This option sets the number in the Debian revision added by --make-binNMU.  The
+default is 1.
+.TP
+.IR "\-\-append\-to\-version=<string>"
+This option is similar to --make-binNMU except that it allows the user to
+specify an arbitrary string to be appended to the version number (immediately
+before the second dot in the Debian revision if --make-binNMU is also provided).
+.TP
 .SH ENVIRONMENT VARIABLES
 The following environment variables are used by \fBsbuild\fR:
 .IP "HOME"

Attachment: pgpWWTRMWol0D.pgp
Description: PGP signature

Reply via email to