use warnings;
use Cwd qw/abs_path/;
+use List::Util qw/reduce/;
use File::Copy ();
use File::Path ();
use File::Spec;
=head1 VERSION
-Version 0.07
+Version 0.08
=cut
-our $VERSION = '0.07';
+our $VERSION = '0.08';
=head1 SYNOPSIS
=head1 INSTALLATION
-After installing this module, you should append C<perl-gcpanp> to your F</etc/portage/categories> file.
+Before installing this module, you should append C<perl-gcpanp> to your F</etc/portage/categories> file.
+
+You have two ways for installing this module :
+
+=over 4
+
+=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>.
+
+=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> :
+
+ $ cd /tmp
+ $ wget http://search.cpan.org/CPAN/authors/id/K/KA/KANE/CPANPLUS-0.88.tar.gz
+ $ wget http://search.cpan.org/CPAN/authors/id/V/VP/VPIT/CPANPLUS-Dist-Gentoo-0.08.tar.gz
+
+Log in as root and unpack them in e.g. your home directory :
+
+ # cd
+ # tar xzf /tmp/CPANPLUS-0.88.tar.gz
+ # tar xzf /tmp/CPANPLUS-Dist-Gentoo-0.08.tar.gz
+
+Set up environment variables so that the toolchain is temporarily available :
+
+ # export OLDPATH=$PATH
+ # export PATH=/root/CPANPLUS-Dist-Gentoo-0.08/bin:$PATH
+ # export PERL5LIB=/root/CPANPLUS-Dist-Gentoo-0.08/blib/lib:/root/CPANPLUS-0.88/lib:/root/CPANPLUS-0.88/inc/bundle
+
+Make sure you don't have an old C<.cpanplus> configuration visible :
+
+ # [ -d /root/.cpanplus ] && mv /root/.cpanplus{,.bak}
+
+Bootstrap L<CPANPLUS> :
+
+ # cd /root/CPANPLUS-Dist-Gentoo-0.08
+ # samples/g-cpanp CPANPLUS
+
+Reset the environment :
+
+ # export PATH=$OLDPATH
+ # unset PERL5LIB OLDPATH
+
+Emerge L<CPANPLUS> with the ebuilds you've just generated :
+
+ # emerge -tv CPANPLUS
+
+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 :
+
+ # FEATURES="-protect-owned" emerge podlators
+ # FEATURES="-protect-owned" emerge ExtUtils-MakeMaker
+
+You may need to run each of these commands two times for them to succeed.
+
+At this point, you can bootstrap L<CPANPLUS::Dist::Gentoo> using the system L<CPANPLUS> :
+
+ # PERL5LIB=/root/CPANPLUS-Dist-Gentoo-0.08/blib/lib samples/g-cpanp CPANPLUS::Dist::Gentoo
+ # emerge -tv CPANPLUS-Dist-Gentoo
+
+=back
=head1 METHODS
my $OK = sub { $stat->prepared(1); 1 };
my $FAIL = sub { $stat->prepared(0); $self->_abort(@_) if @_; 0 };
+ my $SKIP = sub { $stat->prepared(1); $stat->created(1); $self->_skip(@_) if @_; 1 };
my $keywords = delete $opts{keywords};
if (defined $keywords) {
1 while chomp $header;
$header .= "\n\n";
} else {
- $header = '';
+ my $year = (localtime)[5] + 1900;
+ $header = <<" DEF_HEADER";
+# Copyright 1999-$year Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# \$Header: \$
+ DEF_HEADER
}
$stat->header($header);
);
$stat->ebuild_file($file);
- if (-e $file) {
- my $skip = 1;
- if ($stat->force and not $forced{$file}) {
- if (-w $file) {
- 1 while unlink $file;
- $forced{$file} = 1;
- $skip = 0;
- } else {
- $self->_skip("Can't force rewriting of $file");
+ if ($stat->force) {
+ # Always generate an ebuild in our category when forcing
+ if ($forced{$file}) {
+ $stat->dist($file);
+ return $SKIP->('Ebuild already forced for', $stat->distribution);
+ }
+ ++$forced{$file};
+ if (-e $file) {
+ unless (-w $file) {
+ $stat->dist($file);
+ return $SKIP->("Can't force rewriting of $file");
}
- } else {
- $self->_skip('Ebuild already generated for', $stat->distribution);
+ 1 while unlink $file;
}
- if ($skip) {
- $stat->prepared(1);
- $stat->created(1);
- $stat->dist($file);
- return 1;
+ } else {
+ if (my @match = $self->_cpan2portage($name, $version)) {
+ $stat->dist($match[1]);
+ return $SKIP->('Ebuild already generated for', $stat->distribution);
}
}
my $OK = sub {
$stat->created(1);
- $stat->dist($file);
+ $stat->dist($file) if defined $file;
1;
};
$stat->created(0);
$stat->dist(undef);
$self->_abort(@_) if @_;
- if ($file and -f $file) {
+ if (defined $file and -f $file) {
1 while unlink $file;
}
0;
if ($stat->created) {
$self->_skip($stat->distribution, 'was already created');
+ $file = $stat->dist; # Keep the existing one.
return $OK->();
}
my $stat = $self->status;
my $file = $stat->ebuild_file;
- unless ($file and -e $file) {
+ unless (defined $file and -e $file) {
return $self->_abort('The ebuild file is invalid or does not exist');
}
$self->_notify('Adding Manifest entry for', $stat->distribution);
- return $self->_run([ 'ebuild', $stat->ebuild_file, 'manifest' ], 0);
+ return $self->_run([ 'ebuild', $file, 'manifest' ], 0);
}
=head2 C<ebuild_source>
my @deps;
for (@{$stat->deps}) {
my $dep = $self->_cpan2portage(@$_);
- return unless defined $dep;
+ unless (defined $dep) {
+ $self->_abort(
+ "Couldn't find an appropriate ebuild for $_->[0] in the portage tree"
+ );
+ return;
+ }
push @deps, $dep;
}
$d .= "SLOT=\"0\"\n";
$d .= 'LICENSE="|| ( ' . join(' ', sort @{$stat->license}) . " )\"\n";
$d .= 'KEYWORDS="' . join(' ', sort @{$stat->keywords}) . "\"\n";
- $d .= 'DEPEND="' . join("\n", @deps) . "\"\n";
+ $d .= 'RDEPEND="' . join("\n", @deps) . "\"\n";
+ $d .= "DEPEND=\"\${RDEPEND}\"\n";
$d .= "SRC_TEST=\"do\"\n";
$d .= $stat->footer;
"$atom-*.ebuild",
) or next;
+ my $last = reduce {
+ CPANPLUS::Dist::Gentoo::Maps::version_gcmp($b->[1], $a->[1]) >= 0 ? $b : $a
+ } map [ $_, /\Q$atom\E-v?([\d._pr-]+).*?\.ebuild$/ ? $1 : 0 ], @ebuilds;
+
+ my $dep;
if (defined $ver) { # implies that $version is defined
- for (@ebuilds) {
- my ($eb_ver) = /\Q$atom\E-v?([\d._pr-]+).*?\.ebuild$/;
- return ">=$category/$atom-$ver"
- if defined $eb_ver
- and CPANPLUS::Dist::Gentoo::Maps::version_gcmp($eb_ver, $ver) >= 0;
- }
+ next unless
+ CPANPLUS::Dist::Gentoo::Maps::version_gcmp($last->[1], $ver) >= 0;
+ $dep = ">=$category/$atom-$ver";
} else {
- return "$category/$atom";
+ $dep = "$category/$atom";
}
+ return wantarray ? ($dep, $last->[0]) : $dep;
}
}
- $self->_abort(
- "Couldn't find an appropriate ebuild for $name in the portage tree"
- );
-
return;
}
L<CPANPLUS>, L<IPC::Cmd> (core modules since 5.9.5), L<Parse::CPAN::Meta> (since 5.10.1).
-L<Cwd>, L<Carp> (since perl 5), L<File::Path> (5.001), L<File::Copy> (5.002), L<File::Spec> (5.00405).
+L<Cwd>, L<Carp> (since perl 5), L<File::Path> (5.001), L<File::Copy> (5.002), L<File::Spec> (5.00405), L<List::Util> (5.007003).
=head1 SEE ALSO