Package: sbuild
Version: 0.57.0-1
Severity: wishlist
Tags: patch

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.

To make clear the use case, I should explain how I've been using this feature in the past. The MIT Debian-Athena project (http://debathena.mit.edu) has since summer 2007 been using a monkey patch implementation of this feature to build Debian packages for Athena-specific software and new software that we've written for all current releases of Debian and Ubuntu. In order to upload the builds on different releases to the same repository, we add tags of the form ~debian4.0 or ~ubuntu7.10 to the version numbers of the binary packages. These particular tags are chosen so that if the user upgrades to a newer release, their packages will upgrade, while ensuring that if the package ever ends up in Debian proper with the same version number, they will upgrade to the upstream Debian version.

I've attached a patch that adds support for this. It adds a new argument --append-to-version=<string>. The patch documents the feature in the man page, and also fixes some minor documentation errors related to the binNMU feature.

I've attached an additional patch that cleans up some of the code related to binNMUs because with my changes, binNMU_version returns the original version if nothing is being appended to the version and binNMUver is not specified.

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.

        -Tim Abbott
diff --exclude='config.*' -ur sbuild-0.57.0/bin/sbuild sbuild-0.57.0-tabbott/bin/sbuild
--- sbuild-0.57.0/bin/sbuild	2008-01-01 06:39:56.000000000 -0500
+++ sbuild-0.57.0-tabbott/bin/sbuild	2008-03-30 00:24:54.000000000 -0400
@@ -86,6 +86,7 @@
 @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) {
@@ -129,6 +130,7 @@
 			   $main::binNMUver ||= 1;
 		       },
 		       "binNMU=i" => \$main::binNMUver,
+		       "append-to-version=s" => \$main::append_to_version,
 		       "database=s" => \$main::database,
 		       "D|debug+" => \$conf::debug,
 		       "d|dist=s" => sub {
@@ -244,9 +246,9 @@
     {
 	my $tpkg = basename($pkgv);
 
-	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;
 	}
@@ -606,8 +608,8 @@
 	    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";
@@ -639,7 +641,7 @@
     }
 
     $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 = "";
@@ -648,7 +650,7 @@
 	    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";
@@ -657,9 +659,15 @@
 	    }
 	    $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;
@@ -799,7 +807,8 @@
 	}
 
 	$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") {
@@ -2470,6 +2479,8 @@
     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.
 	    if (not defined $main::binNMUver) {
 		print F "$job $main::distribution\n";
 	    } else {
diff --exclude='config.*' -ur sbuild-0.57.0/lib/Sbuild.pm sbuild-0.57.0-tabbott/lib/Sbuild.pm
--- sbuild-0.57.0/lib/Sbuild.pm	2008-01-01 06:39:56.000000000 -0500
+++ sbuild-0.57.0-tabbott/lib/Sbuild.pm	2008-03-29 22:24:11.000000000 -0400
@@ -169,8 +169,12 @@
 sub binNMU_version {
 	my $v = shift;
 	my $binNMUver = shift;
-
-	return "$v+b$binNMUver";
+	my $append_to_version = shift;
+	if ($binNMUver) {
+	    return "$v${append_to_version}+b$binNMUver";
+	} else {
+	    return "$v${append_to_version}";
+	}
 }
 
 1;
diff --exclude='config.*' -ur sbuild-0.57.0/man/sbuild.1.in sbuild-0.57.0-tabbott/man/sbuild.1.in
--- sbuild-0.57.0/man/sbuild.1.in	2008-01-01 06:39:56.000000000 -0500
+++ sbuild-0.57.0-tabbott/man/sbuild.1.in	2008-03-29 23:54:13.000000000 -0400
@@ -150,14 +150,22 @@
 .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.
+.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"
diff --exclude='sbuild~' -ur sbuild-0.57.0-tabbott-backup/bin/sbuild sbuild-0.57.0-tabbott/bin/sbuild
--- sbuild-0.57.0-tabbott-backup/bin/sbuild	2008-03-30 00:24:54.000000000 -0400
+++ sbuild-0.57.0-tabbott/bin/sbuild	2008-03-30 00:32:27.000000000 -0400
@@ -246,12 +246,10 @@
     {
 	my $tpkg = basename($pkgv);
 
-	if ($main::binNMU || $main::append_to_version) {
-	    $tpkg =~ /^([^_]+)_([^_]+)(.*)$/;
-	    $tpkg = $1 . "_" . binNMU_version($2,$main::binNMUver,$main::append_to_version);
-	    $main::binNMU_name = $tpkg;
-	    $tpkg .= $3;
-	}
+	$tpkg =~ /^([^_]+)_([^_]+)(.*)$/;
+	$tpkg = $1 . "_" . binNMU_version($2,$main::binNMUver,$main::append_to_version);
+	$main::binNMU_name = $tpkg;
+	$tpkg .= $3;
 
 	next if !open_pkg_log( $tpkg, $main::distribution );
     }
@@ -608,7 +606,7 @@
 	    return 0;
 	}
 	my $tree_version = $1;
-	my $cmp_version = (($main::binNMU || $main::append_to_version) && -f "$dir/debian/.sbuild-binNMU-done") ?
+	my $cmp_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 ".
@@ -806,9 +804,7 @@
 	    }
 	}
 
-	$changes = "${pkg}_".
-	    (($main::binNMU || $main::append_to_version) ? 
-	     binNMU_version($sversion,$main::binNMUver,$main::append_to_version) : $sversion).
+	$changes = "${pkg}_". binNMU_version($sversion,$main::binNMUver,$main::append_to_version).
 	    "_$main::arch.changes";
 	my @cfiles;
 	if (-r "$main::chroot_build_dir/$changes") {

Reply via email to