Package: sbuild
Version: 0.64.1-1
Severity: normal
Tags: patch

Hi,

I have a post-build command that should copy files out of the pkgbuild
directory. To do this correctly, this command needs to know the chroot and the
pkgbuild directory. The attached patchs add support for exporting
SBUILD_CHROOT_DIR, SBUILD_BUILD_DIR, SBUILD_PKGBUILD_DIR.

PS: It would be nice if the chroot session ID would be available, too.
Description: Export additional variables to external commands.
Author: Benjamin Drung <bdr...@debian.org>

--- a/lib/Sbuild/Build.pm
+++ b/lib/Sbuild/Build.pm
@@ -1072,11 +1072,20 @@
     my $dsc = $self->get('DSC');
     my $changes;
     $changes = $self->get('Changes File') if ($self->get('Changes File'));
+    my $build_dir = $self->get('Build Dir');
+    my $pkgbuild_dir = $build_dir . '/' . $self->get('DSC Dir');
     my %percent = (
 	"%" => "%",
 	"d" => $dsc, "SBUILD_DSC" => $dsc,
 	"c" => $changes, "SBUILD_CHANGES" => $changes,
+	"b" => $build_dir, "SBUILD_BUILD_DIR" => $build_dir,
+	"p" => $pkgbuild_dir, "SBUILD_PKGBUILD_DIR" => $pkgbuild_dir,
     );
+    if ($chroot == 0) {
+	my $chroot_dir = $self->get('Chroot Dir');
+	$percent{r} = $chroot_dir;
+	$percent{SBUILD_CHROOT_DIR} = $chroot_dir;
+    }
     # Our escapes pattern, with longer escapes first, then sorted lexically.
     my $keyword_pat = join("|",
 	sort {length $b <=> length $a || $a cmp $b} keys %percent);
--- a/man/sbuild.1.in
+++ b/man/sbuild.1.in
@@ -456,6 +456,19 @@
 \fB%c\fR, \fB%SBUILD_CHANGES\fR
 These escapes are converted to the absolute path to a package's source .changes
 file.
+.TP
+\fB%r\fR, \fB%SBUILD_CHROOT_DIR\fR
+These escapes are converted to the absolute path on the host to the root
+directory of the chroot. This variable is not set if the external command is
+run inside the chroot.
+.TP
+\fB%b\fR, \fB%SBUILD_BUILD_DIR\fR
+These escapes are converted to the absolute path to the build directory inside
+the chroot.
+.TP
+\fB%p\fR, \fB%SBUILD_PKGBUILD_DIR\fR
+These escapes are converted to the absolute path to the package build directory
+inside the chroot.
 .PP
 Percent escapes are only substituted when an appropriate value is defined for
 them. At other times, it is left unchanged. For example, a .changes file is only

Reply via email to