[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#800093: ITP: libdpkg-parse-perl -- module to parse various dpkg files into Perl Objects



Hi!

On Mon, 2015-09-28 at 12:37:22 +0100, Andrew Beverley wrote:
> On Mon, 2015-09-28 at 13:12 +0200, Guillem Jover wrote:
> > On Sat, 2015-09-26 at 21:12:57 +0300, Andy Beverley wrote:
> > > Package: wnpp
> > > Owner: Andy Beverley <andy@andybev.com>
> > > Severity: wishlist
> > > X-Debbugs-CC: debian-devel@lists.debian.org, 
> > > debian-perl@lists.debian.org
> > > 
> > > * Package name    : libdpkg-parse-perl
> > 
> > What's the advantage of this over the various modules in libdpkg-perl?
> 
> I think it's the only way to retrieve version information. It's a long time
> since I wrote my original patch for dh-make-perl, but I seem to remember
> that DPKG::Parse was the only module that provided certain information I
> needed (see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=774074).
> 
> I certainly tried to do it with other modules already packaged, but I
> couldn't gain all the required information.

The attached untested patch should in principle do it. In any case the
available file is only ever up-to-date when using dselect. If it's too
slow, this should be fixed in libdpkg-perl anyway as that would benefit
every caller.

Thanks,
Guillem
From 30408bf2dd2cd7da3a794a1a5869a4cdcf1c8332 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@debian.org>
Date: Tue, 29 Sep 2015 15:06:34 +0200
Subject: [PATCH] Switch from libdpkg-parse-perl to libdpkg-perl modules

---
 Build.PL                            |  3 ++-
 debian/control                      |  1 -
 lib/Debian/Control/FromCPAN.pm      | 18 ++++++++----------
 lib/DhMakePerl/Command/Packaging.pm | 16 +++++-----------
 4 files changed, 15 insertions(+), 23 deletions(-)

diff --git a/Build.PL b/Build.PL
index cc3ae8b..e2eaf31 100644
--- a/Build.PL
+++ b/Build.PL
@@ -7,7 +7,6 @@ my $builder = My::Builder->new(
     module_name         => 'DhMakePerl',
     license             => 'gpl',
     recommends          => {
-        'DPKG::Parse' => 0.02,
         'Git'         => 0,
         'IO::Dir'     => 0,
     },
@@ -24,6 +23,8 @@ my $builder = My::Builder->new(
         'CPAN::Meta'                => 0,
         'Cwd'                       => 0,
         'Dpkg'                      => 0,
+        'Dpkg::Index'               => 0,
+        'Dpkg::Control::Types'      => 0,
         'Dpkg::Source::Package'     => 0,
         'Email::Address'            => 0,
         'Email::Date::Format'       => 0,
diff --git a/debian/control b/debian/control
index f02f170..2de9da9 100644
--- a/debian/control
+++ b/debian/control
@@ -78,7 +78,6 @@ Depends: debhelper (>= 8),
          ${perl:Depends}
 Recommends: apt-file (>= 2.5.0),
             git,
-            libdpkg-parse-perl,
             pristine-tar
 Description: helper for creating Debian packages from perl modules
  dh-make-perl will create the files required to build a Debian source
diff --git a/lib/Debian/Control/FromCPAN.pm b/lib/Debian/Control/FromCPAN.pm
index b0895e1..f4d5d48 100644
--- a/lib/Debian/Control/FromCPAN.pm
+++ b/lib/Debian/Control/FromCPAN.pm
@@ -48,11 +48,12 @@ An instance of L<Debian::AptContents> to be used when locating to which package
 a required module belongs.
 
 =item dpkg_available
-An instance of L<DPKG::Parse::Available> to be used when checking whether
+
+An instance of L<Dpkg::Index> to be used when checking whether
 the locally available package is the required version. For example:
 
-    my $available = DPKG::Parse::Available->new;
-    $available->parse;
+    my $available = Dpkg::Index->new(type => CTRL_INFO_PKG);
+    $available->load("$Dpkg::ADMINDIR/available");
 
 =item dir
 
@@ -272,7 +273,7 @@ L<Debian::Dependencies> class) and a list of missing modules.
 
 Perl core is searched first, then installed packages, then the APT contents.
 
-If a DPKG::Parse::Available object is passed, also check the available package version
+If a Dpkg::Index object is passed, also check the available package version.
 
 =cut
 
@@ -307,12 +308,12 @@ sub find_debs_for_modules {
             );
 
             # Check the actual version available, if we've been passed
-            # a DPKG::Parse::Available object
+            # a Dpkg::Index object
             if ( $dpkg_available ) {
                 my @available;
                 my @satisfied = grep {
-                    if ( my $pkg = $dpkg_available->get_package('name' => $_) ) {
-                        my $have_pkg = Debian::Dependency->new( $_, '=', $pkg->version );
+                    if ( my $pkg = $dpkg_available->get_by_key($_) ) {
+                        my $have_pkg = Debian::Dependency->new( $_, '=', $pkg->{Version} );
                         push @available, $have_pkg;
                         $have_pkg->satisfies($dep);
                     }
@@ -327,9 +328,6 @@ sub find_debs_for_modules {
                     push @missing, $module;
                 }
             }
-            else {
-                warn "DPKG::Parse not available. Not checking version of $module.";
-            }
         }
 
         if (!$dep && $apt_contents) {
diff --git a/lib/DhMakePerl/Command/Packaging.pm b/lib/DhMakePerl/Command/Packaging.pm
index 8d96dd9..6f9117b 100644
--- a/lib/DhMakePerl/Command/Packaging.pm
+++ b/lib/DhMakePerl/Command/Packaging.pm
@@ -31,6 +31,9 @@ use Config::INI::Reader ();
 use CPAN ();
 use CPAN::Meta;
 use Cwd qw( getcwd );
+use Dpkg;
+use Dpkg::Index;
+use Dpkg::Control::Types;
 use Debian::Control::FromCPAN;
 use Debian::Dependencies;
 use Debian::Rules;
@@ -1391,19 +1394,10 @@ sub discover_dependencies {
         # control->discover_dependencies needs configured CPAN
         $self->configure_cpan;
 
-        # Attempt to get an instance of DPKG::Parse::Available. If this
-        # isn't available, warn the user, as versions of packages cannot
-        # be checked.
         # Don't cache this in case we've built and installed a
         # module in this instance.
-        my $dpkg_available;
-        if ( eval { require DPKG::Parse::Available } && DPKG::Parse->VERSION >= 0.02 ) {
-            $dpkg_available = DPKG::Parse::Available->new;
-            $dpkg_available->parse;
-        } else {
-            warn "DPKG::Parse v0.02 or higher not found.";
-            warn "Versions of required packages will not be checked.";
-        }
+        my $dpkg_available = Dpkg::Index->new(type => CTRL_INFO_PKG);
+        $dpkg_available->load("$Dpkg::ADMINDIR/available");
 
         return $self->control->discover_dependencies(
             {   dir            => $self->main_dir,
-- 
2.6.0.rc2.230.g3dd15c0


Reply to: