tags 595934 + patch fixed-upstream pending
thanks

On Mon, Nov 01, 2010 at 08:22:42PM +0000, Roger Leigh wrote:
> On Tue, Sep 07, 2010 at 02:33:41PM +0200, Lucas Nussbaum wrote:
> > sbuild breaks when trying to install build-dependencies that are
> > provided by another package.
> > Example building time 1.7-23:
> > E: Package 'automaken' has no installation candidate
> > automaken is a virtual package provided by: 
> > Using  (no default, using first one)
> 
> sbuild doesn't support the use of virtual build dependencies
> using the "internal" resolver.  It should do when using the
> "aptitude" resolver, but this isn't currently used by the
> buildds (except for experimental).
> 
> The internal resolver had limited (but broken) support for
> hard-coded alternatives, but not package-provided alternatives.
> I've recently ripped out the lot, since it was barely useful
> and non-functional.
> 
> We can in theory implement virtual package resolving in the
> internal resolver.  However, we would need to read and parse
> the entire apt database, dumped with "apt-cache show '.*' or
> equivalent.  I'd have to say, this will be both slow and not
> a very productive use of our time to write, especially when
> the aptitude resolver does this natively already.
> 
> If we do implement this, the main issue is which alternative
> to pick when there are multiple choices.  The first one found,
> first alphabetically, etc.?  Not sure what aptitude does, I
> think apt-get just installs the first.

It turns out this was actually really simple to implement, so
I've gone and done it.  Patch against current git master
branch attached.

If you'd like to try it out yourself, I'd be grateful for
some feedback.


Thanks,
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.
From 9bd583320f1acab840c5b2c122f83947a30fa78d Mon Sep 17 00:00:00 2001
From: Roger Leigh <rle...@debian.org>
Date: Mon, 1 Nov 2010 21:03:55 +0000
Subject: [PATCH 1/2] Sbuild::InternalBuildDepSatisfier: Resolve simple virtual dependencies

get_virtual gets a list of packages providing a given package
(or a single concrete package if it's not virtual), using
"apt-cache --names-only search '^$pkg$'".  This appears, at
present, to be the most efficient way of finding virtual
package providers.  Packages are listed in alphabetical order.

virtual_dependencies uses get_virtual to expand all virtual
dependencies.  It currently picks the first returned package,
which is the first sorted alphabetically.
---
 lib/Sbuild/InternalBuildDepSatisfier.pm |   60 +++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/lib/Sbuild/InternalBuildDepSatisfier.pm b/lib/Sbuild/InternalBuildDepSatisfier.pm
index b268640..b0b47be 100644
--- a/lib/Sbuild/InternalBuildDepSatisfier.pm
+++ b/lib/Sbuild/InternalBuildDepSatisfier.pm
@@ -75,12 +75,20 @@ sub install_deps {
 	return 0;
     }
 
+    debug("Finding virtual packages\n");
+    if (!$self->virtual_dependencies(\...@positive)) {
+	$builder->log("Package installation not possible\n");
+	$builder->unlock_file($builder->get('Session')->get('Install Lock'));
+	return 0;
+    }
+
     $builder->log("Checking for dependency conflicts...\n");
     if (!$builder->run_apt("-s", \...@instd, \...@rmvd, @positive)) {
 	$builder->log("Test what should be installed failed.\n");
 	$builder->unlock_file($builder->get('Session')->get('Install Lock'));
 	return 0;
     }
+
     # add negative deps as to be removed for checking srcdep conflicts
     push( @rmvd, @negative );
     my @confl;
@@ -309,6 +317,23 @@ sub filter_dependencies {
     return 1;
 }
 
+sub virtual_dependencies {
+    my $self = shift;
+    my $pos_list = shift;
+
+    my $builder = $self->get('Builder');
+
+    # The first returned package only is used.
+    foreach my $pkg (@$pos_list) {
+	my @virtuals = $self->get_virtual($pkg);
+	return 0
+	    if (scalar(@virtuals) == 0);
+	$pkg = $virtuals[0];
+    }
+
+    return 1;
+}
+
 sub check_dependencies {
     my $self = shift;
     my $dependencies = shift;
@@ -379,4 +404,39 @@ sub check_dependencies {
     return $fail;
 }
 
+# Return a list of packages which provide a package.
+# Note: will return both concrete and virtual packages.
+sub get_virtual {
+    my $self = shift;
+    my $pkg = shift;
+
+    my $builder = $self->get('Builder');
+
+    my $pipe = $builder->get('Session')->pipe_apt_command(
+	{ COMMAND => [$self->get_conf('APT_CACHE'),
+		      '-q', '--names-only', 'search', "^$pkg\$"],
+	  USER => $self->get_conf('USERNAME'),
+	  PRIORITY => 0,
+	  DIR => '/'});
+    if (!$pipe) {
+	$self->log("Can't open pipe to $conf::apt_cache: $!\n");
+	return ();
+    }
+
+    my @virtuals;
+
+    while( <$pipe> ) {
+	my $virtual = $1 if /^(\S+)\s+\S+.*$/mi;
+	push(@virtuals, $virtual);
+    }
+    close($pipe);
+
+    if ($?) {
+	$self->log($self->get_conf('APT_CACHE') . " exit status $?: $!\n");
+	return ();
+    }
+
+    return sort(@virtuals);
+}
+
 1;
-- 
1.7.2.3

From 4f83985c0280d09767ab1384f0e3e262d575067e Mon Sep 17 00:00:00 2001
From: Roger Leigh <rle...@debian.org>
Date: Mon, 1 Nov 2010 21:35:24 +0000
Subject: [PATCH 2/2] Sbuild::Conf: Add RESOLVE_VIRTUAL option to disable virtual package resolving

Defaults to enabled.
---
 lib/Sbuild/Conf.pm                      |    5 +++++
 lib/Sbuild/InternalBuildDepSatisfier.pm |   12 +++++++-----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/lib/Sbuild/Conf.pm b/lib/Sbuild/Conf.pm
index 248d10c..b7c2475 100644
--- a/lib/Sbuild/Conf.pm
+++ b/lib/Sbuild/Conf.pm
@@ -463,6 +463,9 @@ sub init_allowed_keys {
 			     qw(internal aptitude));
 	    },
 	},
+	'RESOLVE_VIRTUAL'				=> {
+	    DEFAULT => 1
+	},
     );
 
     $self->set_allowed_keys(\%sbuild_keys);
@@ -549,6 +552,7 @@ sub read_config {
     my $job_file = undef;
     my $build_dir = undef;
     my $build_dep_resolver = undef;
+    my $resolve_virtual = undef;
     my $core_depends = undef;
 
     foreach ($Sbuild::Sysconfig::paths{'SBUILD_CONF'}, "$HOME/.sbuildrc") {
@@ -563,6 +567,7 @@ sub read_config {
 
     # Set before APT_GET or APTITUDE to allow correct validation.
     $self->set('BUILD_DEP_RESOLVER', $build_dep_resolver);
+    $self->set('RESOLVE_VIRTUAL', $resolve_virtual);
     $self->set('CORE_DEPENDS', $core_depends);
     $self->set('ARCH', $arch);
     $self->set('DISTRIBUTION', $distribution);
diff --git a/lib/Sbuild/InternalBuildDepSatisfier.pm b/lib/Sbuild/InternalBuildDepSatisfier.pm
index b0b47be..7c47f66 100644
--- a/lib/Sbuild/InternalBuildDepSatisfier.pm
+++ b/lib/Sbuild/InternalBuildDepSatisfier.pm
@@ -75,11 +75,13 @@ sub install_deps {
 	return 0;
     }
 
-    debug("Finding virtual packages\n");
-    if (!$self->virtual_dependencies(\...@positive)) {
-	$builder->log("Package installation not possible\n");
-	$builder->unlock_file($builder->get('Session')->get('Install Lock'));
-	return 0;
+    if ($self->get_conf('RESOLVE_VIRTUAL')) {
+	debug("Finding virtual packages\n");
+	if (!$self->virtual_dependencies(\...@positive)) {
+	    $builder->log("Package installation not possible\n");
+	    $builder->unlock_file($builder->get('Session')->get('Install Lock'));
+	    return 0;
+	}
     }
 
     $builder->log("Checking for dependency conflicts...\n");
-- 
1.7.2.3

Attachment: signature.asc
Description: Digital signature

Reply via email to