]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blobdiff - lib/CPANPLUS/Dist/Gentoo.pm
Simplify the bootstrap process
[perl/modules/CPANPLUS-Dist-Gentoo.git] / lib / CPANPLUS / Dist / Gentoo.pm
index 0003b36992ae0dff913006b9419cf720fdae86cb..3c6d883ae76652ab8d84b346133b1f4008279300 100644 (file)
@@ -63,61 +63,41 @@ You have two ways for installing this module :
 =item *
 
 Use the perl overlay located at L<http://git.overlays.gentoo.org/gitweb/?p=proj/perl-overlay.git>.
-It contains an ebuild for L<CPANPLUS::Dist::Gentoo>.
+It contains an ebuild for L<CPANPLUS::Dist::Gentoo> which will most likely be up-to-date given the reactivity of Gentoo's Perl herd.
 
 =item *
 
 Bootstrap an ebuild for L<CPANPLUS::Dist::Gentoo> using itself.
-Note that if your Gentoo system C<perl> is C<5.8.x>, L<CPANPLUS> and its dependencies are not installed and not even available in the main portage tree.
-So you need to bootstrap them as well.
 
-First, fetch tarballs for L<CPANPLUS> and L<CPANPLUS::Dist::Gentoo> :
+First, make sure your system C<perl> is C<5.10> or greater, so that the L<CPANPLUS> toolchain is available.
 
-    $ cd /tmp
-    $ wget http://search.cpan.org/CPAN/authors/id/B/BI/BINGOS/CPANPLUS-0.9003.tar.gz
-    $ wget http://search.cpan.org/CPAN/authors/id/V/VP/VPIT/CPANPLUS-Dist-Gentoo-0.10.tar.gz
-
-Log in as root and unpack them in e.g. your home directory :
-
-    # cd
-    # tar xzf /tmp/CPANPLUS-0.9003.tar.gz
-    # tar xzf /tmp/CPANPLUS-Dist-Gentoo-0.10.tar.gz
-
-Set up environment variables so that the toolchain is temporarily available :
-
-    # export OLDPATH=$PATH
-    # export PATH=/root/CPANPLUS-0.9003/bin:$PATH
-    # export PERL5LIB=/root/CPANPLUS-Dist-Gentoo-0.10/blib/lib:/root/CPANPLUS-0.9003/lib:/root/CPANPLUS-0.9003/inc/bundle
-
-Make sure you don't have an old C<.cpanplus> configuration visible :
+    $ perl -v
+    This is perl 5, version 12, subversion 2 (v5.12.2) built for x86_64-linux
+    ...
 
-    # [ -d /root/.cpanplus ] && mv /root/.cpanplus{,.bak}
+C<perl> C<5.12> is the current stable Perl version in Gentoo.
+If you still have C<perl> C<5.8.x>, you can upgrade it by running the following commands as root :
 
-Bootstrap L<CPANPLUS> :
+    # emerge -tv ">=dev-lang/perl-5.10"
+    # perl-cleaner --all
 
-    # cd /root/CPANPLUS-Dist-Gentoo-0.10
-    # samples/g-cpanp CPANPLUS
+Then, fetch the L<CPANPLUS::Dist::Gentoo> tarball :
 
-Reset the environment :
-
-    # export PATH=$OLDPATH
-    # unset PERL5LIB OLDPATH
-
-Emerge L<CPANPLUS> with the ebuilds you've just generated :
+    $ cd /tmp
+    $ wget http://search.cpan.org/CPAN/authors/id/V/VP/VPIT/CPANPLUS-Dist-Gentoo-0.10.tar.gz
 
-    # emerge -tv CPANPLUS
+Log in as root and unpack it in e.g. your home directory :
 
-As of september 2009, C<podlators> and C<ExtUtils-MakeMaker> may fail to emerge due to collisions.
-You can work around this by disabling the C<protect-owned> C<FEATURE> for them :
+    # cd
+    # tar xzf /tmp/CPANPLUS-Dist-Gentoo-0.10.tar.gz
+    # cd CPANPLUS-Dist-Gentoo-0.10
 
-    # FEATURES="-protect-owned" emerge podlators
-    # FEATURES="-protect-owned" emerge ExtUtils-MakeMaker
+Bootstrap L<CPANPLUS::Dist::Gentoo> using the bundled shell script C<g-cpanp> :
 
-You may need to run each of these commands two times for them to succeed.
+    # PERL5LIB=blib/lib samples/g-cpanp CPANPLUS::Dist::Gentoo
 
-At this point, you can bootstrap L<CPANPLUS::Dist::Gentoo> using the system L<CPANPLUS> :
+Finally, emerge the C<CPANPLUS-Dist-Gentoo> ebuild you've just generated :
 
-    # PERL5LIB=/root/CPANPLUS-Dist-Gentoo-0.10/blib/lib samples/g-cpanp CPANPLUS::Dist::Gentoo
     # emerge -tv CPANPLUS-Dist-Gentoo
 
 =back
@@ -136,6 +116,7 @@ my $default_keywords;
 my $default_distdir;
 my $main_portdir;
 
+my %dependencies;
 my %forced;
 
 my $unquote = sub {
@@ -195,7 +176,8 @@ sub init {
 
  $stat->mk_accessors(qw/name version author distribution desc uri src license
                         meta min_perl
-                        fetched_arch requires
+                        fetched_arch
+                        requires configure_requires recursive_requires
                         ebuild_name ebuild_version ebuild_dir ebuild_file
                         portdir_overlay
                         overlay distdir keywords do_manifest header footer
@@ -207,6 +189,25 @@ sub init {
  return 1;
 }
 
+my $filter_prereqs = sub {
+ my ($int, $prereqs) = @_;
+
+ my @requires;
+ for my $prereq (sort keys %$prereqs) {
+  next if $prereq =~ /^perl(?:-|\z)/;
+
+  my $obj = $int->module_tree($prereq);
+  next unless $obj; # Not in the module tree (e.g. Config)
+  next if $obj->package_is_perl_core;
+
+  my $version = $prereqs->{$prereq} || undef;
+
+  push @requires, [ $obj->package_name, $version ];
+ }
+
+ return \@requires;
+};
+
 sub prepare {
  my $self = shift;
  my $mod  = $self->parent;
@@ -289,7 +290,7 @@ sub prepare {
 
  $stat->distribution($name . '-' . $version);
 
- $stat->ebuild_version(CPANPLUS::Dist::Gentoo::Maps::version_c2g($version));
+ $stat->ebuild_version(CPANPLUS::Dist::Gentoo::Maps::version_c2g($name, $version));
 
  $stat->ebuild_name(CPANPLUS::Dist::Gentoo::Maps::name_c2g($name));
 
@@ -333,7 +334,10 @@ sub prepare {
  return $FAIL->() unless $stat->prepared;
 
  my $desc = $mod->description;
- ($desc = $name) =~ s/-+/::/g unless $desc;
+ $desc    = $mod->comment                unless $desc;
+ $desc    = "$name Perl distribution (provides " . $mod->module . ')'
+                                         unless $desc;
+ $desc    = substr($desc, 0, 77) . '...' if length $desc > 80;
  $stat->desc($desc);
 
  $stat->uri('http://search.cpan.org/dist/' . $name);
@@ -343,29 +347,16 @@ sub prepare {
 
  $stat->license($self->intuit_license);
 
- my $prereqs = $mod->status->requires;
- my @requires;
- for my $prereq (sort keys %$prereqs) {
-  next if $prereq =~ /^perl(?:-|\z)/;
-  my $obj = $int->module_tree($prereq);
-  next unless $obj; # Not in the module tree (e.g. Config)
-  next if $obj->package_is_perl_core;
-  {
-   my $version;
-   if ($prereqs->{$prereq}) {
-    if ($obj->installed_version && $obj->installed_version < $obj->version) {
-     $version = $obj->installed_version;
-    } else {
-     $version = $obj->package_version;
-    }
-   }
-   push @requires, [ $obj->package_name, $version ];
-  }
- }
- $stat->requires(\@requires);
+ my $mstat = $mod->status;
+ $stat->configure_requires($int->$filter_prereqs($mstat->configure_requires));
+ $stat->requires($int->$filter_prereqs($mstat->requires));
+ $stat->recursive_requires([ ]);
 
+ $dependencies{$name} = [ map $_->[0], @{ $stat->requires } ];
+
+ my $meta = $self->meta;
  $stat->min_perl(CPANPLUS::Dist::Gentoo::Maps::perl_version_c2g(
-  eval { $self->meta->{requires}->{perl} }
+  $meta->{requires}->{perl},
  ));
 
  return $OK->();
@@ -391,6 +382,7 @@ sub meta {
   my $meta_file = File::Spec->catdir($extract_dir, $name);
   next unless -e $meta_file;
 
+  local $@;
   my $meta = eval { Parse::CPAN::Meta::LoadFile($meta_file) };
   if (defined $meta) {
    $stat->meta($meta);
@@ -426,7 +418,8 @@ sub intuit_license {
   return \@licenses if @licenses;
  }
 
- my $license = $self->meta->{license};
+ my $meta    = $self->meta;
+ my $license = $meta->{license};
  if (defined $license) {
   my @licenses = CPANPLUS::Dist::Gentoo::Maps::license_c2g($license);
   return \@licenses if @licenses;
@@ -546,33 +539,83 @@ Returns the source of the ebuild for the current dist object, or C<undef> when o
 
 =cut
 
+my $dep_tree_contains;
+{
+ my %seen;
+
+ $dep_tree_contains = sub {
+  my ($dist, $target) = @_;
+
+  return 0 if $seen{$dist};
+  local $seen{$dist} = 1;
+
+  for my $kid (@{ $dependencies{$dist} }) {
+   return 1 if $kid eq $target
+            or $dep_tree_contains->($kid, $target);
+  }
+
+  return 0;
+ }
+}
+
 sub ebuild_source {
  my $self = shift;
  my $stat = $self->status;
 
+ {
+  my $name = $stat->name;
+  my %recursive_kids = map { $_ => 1 }
+                        grep $dep_tree_contains->($_, $name),
+                         @{ $dependencies{$name} };
+  if (%recursive_kids) {
+   my (@requires, @recursive_requires);
+   for (@{ $stat->requires }) {
+    if ($recursive_kids{$_->[0]}) {
+     push @recursive_requires, $_;
+    } else {
+     push @requires, $_;
+    }
+   }
+   $stat->requires(\@requires);
+   $stat->recursive_requires(\@recursive_requires);
+  }
+ }
+
  # We must resolve the deps now and not inside prepare because _cpan2portage
  # has to see the ebuilds already generated for the dependencies of the current
  # dist.
- my @requires;
- for (@{$stat->requires}) {
-  my $atom = $self->_cpan2portage(@$_);
-  unless (defined $atom) {
-   $self->_abort(
-    "Couldn't find an appropriate ebuild for $_->[0] in the portage tree"
-   );
-   return;
-  }
-  push @requires, $atom;
- }
 
- my $min_perl = $stat->min_perl;
- my $perl = CPANPLUS::Dist::Gentoo::Atom->new(
+ my (@configure_requires, @requires, @recursive_requires);
+
+ my @phases = (
+  [ configure_requires => \@configure_requires ],
+  [ requires           => \@requires           ],
+  [ recursive_requires => \@recursive_requires ],
+ );
+
+ push @requires, CPANPLUS::Dist::Gentoo::Atom->new(
   category => 'dev-lang',
   name     => 'perl',
-  (defined $min_perl ? (version => $min_perl, range => '>=') : ()),
+  version  => $stat->min_perl,
  );
 
- @requires = CPANPLUS::Dist::Gentoo::Atom->fold($perl, @requires);
+ for (@phases) {
+  my ($phase, $list) = @$_;
+
+  for (@{ $stat->$phase }) {
+   my $atom = $self->_cpan2portage(@$_);
+   unless (defined $atom) {
+    $self->_abort(
+     "Couldn't find an appropriate ebuild for $_->[0] in the portage tree"
+    );
+    return;
+   }
+
+   push @$list, $atom;
+  }
+
+  @$list = CPANPLUS::Dist::Gentoo::Atom->fold(@$list);
+ }
 
  my $d = $stat->header;
  $d   .= "# Generated by CPANPLUS::Dist::Gentoo version $VERSION\n\n";
@@ -584,8 +627,10 @@ sub ebuild_source {
  $d   .= "SLOT=\"0\"\n";
  $d   .= 'LICENSE="|| ( ' . join(' ', sort @{$stat->license}) . " )\"\n";
  $d   .= 'KEYWORDS="' . join(' ', sort @{$stat->keywords}) . "\"\n";
- $d   .= 'RDEPEND="' . join("\n", sort @requires) . "\"\n";
- $d   .= "DEPEND=\"\${RDEPEND}\"\n";
+ $d   .= 'RDEPEND="' . join("\n", sort @requires) . "\"\n" if @requires;
+ $d   .= 'PDEPEND="' . join("\n", sort @recursive_requires) . "\"\n"
+                                                         if @recursive_requires;
+ $d   .= 'DEPEND="' . join("\n", '${RDEPEND}', sort @configure_requires) . "\"\n";
  $d   .= "SRC_TEST=\"do\"\n";
  $d   .= $stat->footer;
 
@@ -593,10 +638,10 @@ sub ebuild_source {
 }
 
 sub _cpan2portage {
- my ($self, $name, $version) = @_;
+ my ($self, $dist_name, $dist_version) = @_;
 
$name    = CPANPLUS::Dist::Gentoo::Maps::name_c2g($name);
$version = CPANPLUS::Dist::Gentoo::Maps::version_c2g($version);
my $name    = CPANPLUS::Dist::Gentoo::Maps::name_c2g($dist_name);
my $version = CPANPLUS::Dist::Gentoo::Maps::version_c2g($dist_name, $dist_version);
 
  my @portdirs = ($main_portdir, @{$self->status->portdir_overlay});
 
@@ -619,7 +664,7 @@ sub _cpan2portage {
    return CPANPLUS::Dist::Gentoo::Atom->new(
     category => $last->category,
     name     => $last->name,
-    (defined $version ? (version => $version, range => '>=') : ()),
+    version  => $version,
     ebuild   => $last->ebuild,
    );
   }