]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blobdiff - lib/CPANPLUS/Dist/Gentoo.pm
This is 0.05
[perl/modules/CPANPLUS-Dist-Gentoo.git] / lib / CPANPLUS / Dist / Gentoo.pm
index 3dff39c1e37a3c0c2376c55876d6eeaa471de513..d40bf881a8f6969adad3e31fe5c49e5aa98fd293 100644 (file)
@@ -9,6 +9,7 @@ use File::Path qw/mkpath/;
 use File::Spec::Functions qw/catdir catfile/;
 
 use IPC::Cmd qw/run can_run/;
+use version;
 
 use CPANPLUS::Error;
 
@@ -20,11 +21,11 @@ CPANPLUS::Dist::Gentoo - CPANPLUS backend generating Gentoo ebuilds.
 
 =head1 VERSION
 
-Version 0.04
+Version 0.05
 
 =cut
 
-our $VERSION = '0.04';
+our $VERSION = '0.05';
 
 =head1 SYNOPSIS
 
@@ -41,7 +42,7 @@ our $VERSION = '0.04';
 
 This module is a CPANPLUS backend that recursively generates Gentoo ebuilds for a given package in the specified overlay (defaults to F</usr/local/portage>), updates the manifest, and even emerges it (together with its dependencies) if the user requires it. You need write permissions on the directory where Gentoo fetches its source files (usually F</usr/portage/distfiles>). The valid C<KEYWORDS> for the generated ebuilds are by default those given in C<ACCEPT_KEYWORDS>, but you can specify your own with the C<keywords> dist-option.
 
-The generated ebuilds are placed into the C<perl-gcpanp> category. They favour depending on C<perl-core>, C<dev-perl> or C<perl-gcpan> (in that order) rather than C<perl-gcpanp>.
+The generated ebuilds are placed into the C<perl-gcpanp> category. They favour depending on a C<virtual>, on C<perl-core>, C<dev-perl> or C<perl-gcpan> (in that order) rather than C<perl-gcpanp>.
 
 =head1 INSTALLATION
 
@@ -58,6 +59,7 @@ use constant CATEGORY => 'perl-gcpanp';
 my $overlays;
 my $default_keywords;
 my $default_distdir;
+my $main_portdir;
 
 sub _unquote {
  my $s = shift;
@@ -88,6 +90,9 @@ sub format_available {
     if (/^DISTDIR=(.*)$/m) {
      $default_distdir = abs_path(_unquote($1));
     }
+    if (/^PORTDIR=(.*)$/m) {
+     $main_portdir = abs_path(_unquote($1));
+    }
    }
   } else {
    error $errmsg;
@@ -105,7 +110,7 @@ sub init {
  my $stat = $self->status;
  my $conf = $self->parent->parent->configure_object;
 
- $stat->mk_accessors(qw/name version author distribution desc uri license
+ $stat->mk_accessors(qw/name version author distribution desc uri src license
                         deps eb_name eb_version eb_dir eb_file fetched_arch
                         portdir_overlay
                         overlay distdir keywords do_manifest header footer
@@ -250,12 +255,11 @@ sub prepare {
  my $portdir_overlay;
  for (@$overlays) {
   if ($_ eq $overlay or File::Spec::Functions::abs2rel($overlay, $_) eq $cur) {
-   $portdir_overlay = join ' ', @$overlays;
+   $portdir_overlay = [ @$overlays ];
    last;
   }
  }
- $portdir_overlay = join ' ', @$overlays, $overlay
-                                                unless defined $portdir_overlay;
+ $portdir_overlay = [ @$overlays, $overlay ] unless $portdir_overlay;
  $stat->portdir_overlay($portdir_overlay);
 
  my $name = $mod->package_name;
@@ -318,6 +322,13 @@ sub prepare {
 
  $stat->uri('http://search.cpan.org/dist/' . $name);
 
+ unless ($author =~ /^(.)(.)/) {
+  error 'Wrong author name -- aborting';
+  return 0;
+ }
+ $stat->src("mirror://cpan/modules/by-authors/id/$1/$1$2/$author/"
+            . $mod->package);
+
  $stat->license([ qw/Artistic GPL-2/ ]);
 
  my $prereqs = $mod->status->prereqs;
@@ -339,7 +350,7 @@ sub prepare {
      $version = $obj->package_version;
     }
    }
-   push @depends, [ $obj , $version ];
+   push @depends, [ $obj->package_name, $version ];
   }
  }
  $stat->deps(\@depends);
@@ -385,26 +396,17 @@ sub create {
  my $d = $stat->header;
  $d   .= "# Generated by CPANPLUS::Dist::Gentoo version $VERSION\n\n";
  $d   .= 'MODULE_AUTHOR="' . $stat->author . "\"\ninherit perl-module\n\n";
+ $d   .= 'S="${WORKDIR}/' . $stat->distribution . "\"\n";
  $d   .= 'DESCRIPTION="' . $stat->desc . "\"\n";
- $d   .= 'HOMEPAGE="' . $stat->uri . "\"\n\n";
+ $d   .= 'HOMEPAGE="' . $stat->uri . "\"\n";
+ $d   .= 'SRC_URI="' . $stat->src . "\"\n";
  $d   .= "SLOT=\"0\"\n";
  $d   .= 'LICENSE="|| ( ' . join(' ', sort @{$stat->license}) . " )\"\n";
  $d   .= 'KEYWORDS="' . join(' ', sort @{$stat->keywords}) . "\"\n";
- $d   .= 'DEPEND="' . join "\n",
+ $d   .= 'DEPEND="' . join("\n",
   'dev-lang/perl',
-  map {
-   my $a = $_->[0]->package_name;
-   $a = $gentooism{$a} || $a;
-   my $x = '';
-   if (defined $_->[1]) {
-    $x  = '>=';
-    $a .= '-' . $_->[1];
-   }
-   '|| ( ' . join(' ', map "$x$_/$a",
-                           qw/perl-core dev-perl perl-gcpan/, CATEGORY)
-           . ' )';
-  } @{$stat->deps};
- $d   .= "\"\n";
+  map $self->_cpan2portage(@$_), @{$stat->deps}
+ ) . "\"\n";
  $d   .= "SRC_TEST=\"do\"\n";
  $d   .= $stat->footer;
 
@@ -435,6 +437,41 @@ sub create {
  return 1;
 }
 
+sub _cpan2portage {
+ my ($self, $name, $version) = @_;
+
+ $name = $gentooism{$name} || $name;
+ my $ver;
+ $ver = eval { version->new($version) } if defined $version;
+
+ my @portdirs = ($main_portdir, @{$self->status->portdir_overlay});
+
+ for my $category (qw/virtual perl-core dev-perl perl-gcpan/, CATEGORY) {
+  my $atom = ($category eq 'virtual' ? 'perl-' : '') . $name;
+
+  for my $portdir (@portdirs) {
+   my @ebuilds = glob catfile($portdir, $category, $atom,"$atom-*.ebuild");
+   next unless @ebuilds;
+
+   if (defined $ver) { # implies that $version is defined
+    for (@ebuilds) {
+     next unless /\Q$atom\E-v?([\d._]+).*?\.ebuild$/;
+     my $eb_ver = eval { version->new($1) };
+     next unless defined $eb_ver and $eb_ver >= $ver;
+     return ">=$category/$atom-$version";
+    }
+   } else {
+    return "$category/$atom";
+   }
+
+  }
+
+ }
+
+ error "Couldn't find an appropriate ebuild for $name in the portage tree -- skipping";
+ return '';
+}
+
 sub install {
  my $self = shift;
  my $stat = $self->status;
@@ -470,7 +507,7 @@ sub _run {
  my $stat = $self->status;
 
  my ($success, $errmsg, $output) = do {
-  local $ENV{PORTDIR_OVERLAY}     = $stat->portdir_overlay;
+  local $ENV{PORTDIR_OVERLAY}     = join ' ', @{$stat->portdir_overlay};
   local $ENV{PORTAGE_RO_DISTDIRS} = $stat->distdir;
   run command => $cmd, verbose => $verbose;
  };
@@ -491,7 +528,7 @@ sub _run {
 
 Gentoo (L<http://gentoo.org>).
 
-L<CPANPLUS>, L<IPC::Cmd> (core modules since 5.9.5).
+L<CPANPLUS>, L<IPC::Cmd> (core modules since 5.9.5), L<version> (since 5.009).
 
 L<Cwd> (since perl 5) L<File::Path> (5.001), L<File::Copy> (5.002), L<File::Spec::Functions> (5.00504).
 
@@ -525,7 +562,7 @@ Kent Fredric, for testing and suggesting improvements.
 
 =head1 COPYRIGHT & LICENSE
 
-Copyright 2008 Vincent Pit, all rights reserved.
+Copyright 2008-2009 Vincent Pit, all rights reserved.
 
 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.