From patchwork Wed Dec 14 18:08:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wookey X-Patchwork-Id: 5716 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 0574F23E0C for ; Wed, 14 Dec 2011 18:08:45 +0000 (UTC) Received: from mail-ey0-f180.google.com (mail-ey0-f180.google.com [209.85.215.180]) by fiordland.canonical.com (Postfix) with ESMTP id ED4DDA18058 for ; Wed, 14 Dec 2011 18:08:44 +0000 (UTC) Received: by eaak10 with SMTP id k10so994239eaa.11 for ; Wed, 14 Dec 2011 10:08:44 -0800 (PST) Received: by 10.204.131.74 with SMTP id w10mr1502234bks.36.1323886124687; Wed, 14 Dec 2011 10:08:44 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.205.129.2 with SMTP id hg2cs15739bkc; Wed, 14 Dec 2011 10:08:44 -0800 (PST) Received: by 10.180.105.131 with SMTP id gm3mr6974532wib.50.1323886123213; Wed, 14 Dec 2011 10:08:43 -0800 (PST) Received: from stoneboat.aleph1.co.uk (stoneboat.aleph1.co.uk. [80.68.88.63]) by mx.google.com with ESMTPS id k42si2090610weq.41.2011.12.14.10.08.43 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 14 Dec 2011 10:08:43 -0800 (PST) Received-SPF: neutral (google.com: 80.68.88.63 is neither permitted nor denied by best guess record for domain of wookey@wookware.org) client-ip=80.68.88.63; Authentication-Results: mx.google.com; spf=neutral (google.com: 80.68.88.63 is neither permitted nor denied by best guess record for domain of wookey@wookware.org) smtp.mail=wookey@wookware.org Received: from host-78-151-164-206.static.as13285.net ([78.151.164.206] helo=dream.aleph1.co.uk) by stoneboat.aleph1.co.uk with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1RatFs-0006C2-K9 for patches@linaro.org; Wed, 14 Dec 2011 18:08:42 +0000 Received: from wookey by dream.aleph1.co.uk with local (Exim 4.72) (envelope-from ) id 1RatFm-0006Ry-Ft for patches@linaro.org; Wed, 14 Dec 2011 18:08:30 +0000 Date: Wed, 14 Dec 2011 18:08:30 +0000 From: Wookey To: patches@linaro.org Message-ID: <20111214180830.GV28260@dream.aleph1.co.uk> MIME-Version: 1.0 Content-Disposition: inline Organization: Wookware User-Agent: Mutt/1.5.20 (2009-06-14) X-SA-Exim-Connect-IP: 78.151.164.206 X-SA-Exim-Mail-From: wookey@wookware.org X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on stoneboat.aleph1.co.uk X-Spam-Level: X-Spam-Status: No, score=-2.1 required=4.5 tests=AWL,BAYES_00 autolearn=no version=3.3.1 Subject: 0008-First-attempt-to-add-Xapt-as-dependency-resolver.patch X-SA-Exim-Version: 4.2.1 (built Mon, 22 Mar 2010 06:51:10 +0000) X-SA-Exim-Scanned: Yes (on stoneboat.aleph1.co.uk) >From d6b46bd8d71468ee135d336fedcbbb05aba92290 Mon Sep 17 00:00:00 2001 From: Hector Oron Date: Mon, 12 Dec 2011 19:21:29 +0000 Subject: [PATCH 08/17] First attempt to add Xapt as dependency resolver. Signed-off-by: Hector Oron --- lib/Sbuild/Conf.pm | 8 +++- lib/Sbuild/Resolver.pm | 2 + lib/Sbuild/ResolverBase.pm | 54 +++++++++++++++++++++++ lib/Sbuild/XaptResolver.pm | 102 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 lib/Sbuild/XaptResolver.pm diff --git a/lib/Sbuild/Conf.pm b/lib/Sbuild/Conf.pm index b2820af..b5b962a 100644 --- a/lib/Sbuild/Conf.pm +++ b/lib/Sbuild/Conf.pm @@ -253,6 +253,10 @@ sub setup ($) { DEFAULT => 'aptitude', HELP => 'Path to aptitude binary' }, + 'XAPT' => { + CHECK => $validate_program, + DEFAULT => 'xapt' + }, 'DPKG_BUILDPACKAGE_USER_OPTIONS' => { TYPE => 'ARRAY:STRING', GROUP => '__INTERNAL', @@ -873,9 +877,9 @@ sub setup ($) { die '$key: Invalid build-dependency resolver \'' . $conf->get($key) . - "'\nValid algorthms are 'internal', 'apt' and 'aptitude'\n" + "'\nValid algorithms are 'internal', 'xapt', 'apt' and 'aptitude'\n" if !isin($conf->get($key), - qw(internal apt aptitude)); + qw(internal xapt apt aptitude)); }, HELP => 'Build dependency resolver. The \'apt\' resolver is currently the default, and recommended for most users. This resolver uses apt-get to resolve dependencies. Alternative resolvers are \'apt\' and \'aptitude\', which use a built-in resolver module and aptitude to resolve build dependencies, respectively. The internal resolver is not capable of resolving complex alternative and virtual package dependencies, but is otherwise equivalent to apt. The aptitude resolver is similar to apt, but is useful in more complex situations, such as where multiple distributions are required, for example when building from experimental, where packages are needed from both unstable and experimental, but defaulting to unstable.' }, diff --git a/lib/Sbuild/Resolver.pm b/lib/Sbuild/Resolver.pm index 7c51a95..9437aa1 100644 --- a/lib/Sbuild/Resolver.pm +++ b/lib/Sbuild/Resolver.pm @@ -46,6 +46,8 @@ sub get_resolver ($$$) { my $resolver; if ($conf->get('BUILD_DEP_RESOLVER') eq "apt") { $resolver = Sbuild::AptResolver->new($conf, $session, $host); + } elsif ($conf->get('BUILD_DEP_RESOLVER') eq "xapt") { + $resolver = Sbuild::XaptResolver->new($conf, $session, $host); } elsif ($conf->get('BUILD_DEP_RESOLVER') eq "aptitude") { $resolver = Sbuild::AptitudeResolver->new($conf, $session, $host); } else { diff --git a/lib/Sbuild/ResolverBase.pm b/lib/Sbuild/ResolverBase.pm index 3f003c8..d2362bd 100644 --- a/lib/Sbuild/ResolverBase.pm +++ b/lib/Sbuild/ResolverBase.pm @@ -433,6 +433,60 @@ sub run_apt { return $mode eq "-s" || $status == 0; } +sub run_xapt { + my $self = shift; + my $mode = shift; + my $inst_ret = shift; + my $rem_ret = shift; + my $action = shift; + my @packages = @_; + my( $msgs, $status, $pkgs, $rpkgs ); + + $msgs = ""; + # redirection of stdin from /dev/null so that conffile question + # are treated as if RETURN was pressed. + # dpkg since 1.4.1.18 issues an error on the conffile question if + # it reads EOF -- hardwire the new --force-confold option to avoid + # the questions. + my @xapt_command = ($self->get_conf('XAPT'), + '-a', $self->get_conf('HOST_ARCH')); + # FIXME?:push @xapt_command, "$mode", $action, @packages; + push @xapt_command, @packages; + my $pipe = + $self->pipe_xapt_command( + { COMMAND => \@xapt_command, + ENV => {'DEBIAN_FRONTEND' => 'noninteractive'}, + USER => 'root', + PRIORITY => 0, + DIR => '/' }); + if (!$pipe) { + $self->log("Can't open pipe to xapt: $!\n"); + return 0; + } + + while(<$pipe>) { + $msgs .= $_; + $self->log($_) if $mode ne "-s" || debug($_); + } + close($pipe); + $status = $?; + + $pkgs = $rpkgs = ""; + if ($msgs =~ /NEW packages will be installed:\n((^[ ].*\n)*)/mi) { + ($pkgs = $1) =~ s/^[ ]*((.|\n)*)\s*$/$1/m; + $pkgs =~ s/\*//g; + } + if ($msgs =~ /packages will be REMOVED:\n((^[ ].*\n)*)/mi) { + ($rpkgs = $1) =~ s/^[ ]*((.|\n)*)\s*$/$1/m; + $rpkgs =~ s/\*//g; + } + @$inst_ret = split( /\s+/, $pkgs ); + @$rem_ret = split( /\s+/, $rpkgs ); + + $self->log("xapt failed.\n") if $status && $mode ne "-s"; + return $mode eq "-s" || $status == 0; +} + sub format_deps { my $self = shift; diff --git a/lib/Sbuild/XaptResolver.pm b/lib/Sbuild/XaptResolver.pm new file mode 100644 index 0000000..6bc9309 --- /dev/null +++ b/lib/Sbuild/XaptResolver.pm @@ -0,0 +1,102 @@ +# ResolverBase.pm: build library for sbuild +# Copyright © 2005 Ryan Murray +# Copyright © 2005-2008 Roger Leigh +# Copyright © 2008 Simon McVittie +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# . +# +####################################################################### + +package Sbuild::XaptResolver; + +use strict; +use warnings; + +use Sbuild qw(debug); +use Sbuild::Base; +use Sbuild::ResolverBase; + +BEGIN { + use Exporter (); + our (@ISA, @EXPORT); + + @ISA = qw(Exporter Sbuild::ResolverBase); + + @EXPORT = qw(); +} + +sub new { + my $class = shift; + my $conf = shift; + my $session = shift; + my $host = shift; + + my $self = $class->SUPER::new($conf, $session, $host); + bless($self, $class); + + return $self; +} + +sub install_deps { + my $self = shift; + my $name = shift; + my @pkgs = @_; + + my $status = 0; + my $session = $self->get('Session'); + my $dummy_pkg_name = 'sbuild-build-depends-' . $name. '-dummy'; + + # Call functions to setup an archive to install dummy package. + return 0 unless ($self->setup_apt_archive($dummy_pkg_name, @pkgs)); + return 0 unless (!$self->update_archive()); + + + $self->log_subsection("Install $name cross-build dependencies (xapt-based resolver)"); + + # Install the dummy package + my (@instd, @rmvd); + $self->log("Installing cross-build dependencies\n"); + if (!$self->run_apt("-yf", \@instd, \@rmvd, 'install', $dummy_pkg_name)) { + $self->log("Package installation failed\n"); + if (defined ($self->get('Session')->get('Session Purged')) && + $self->get('Session')->get('Session Purged') == 1) { + $self->log("Not removing build depends: cloned chroot in use\n"); + } else { + $self->set_installed(@instd); + $self->set_removed(@rmvd); + goto package_cleanup; + } + return 0; + } + $self->set_installed(@instd); + $self->set_removed(@rmvd); + $status = 1; + + package_cleanup: + if ($status == 0) { + if (defined ($session->get('Session Purged')) && + $session->get('Session Purged') == 1) { + $self->log("Not removing installed packages: cloned chroot in use\n"); + } else { + $self->uninstall_deps(); + } + } + + $self->cleanup_apt_archive(); + + return $status; +} + +1;