use warnings;
use Cwd qw/abs_path/;
+use List::Util qw/reduce/;
use File::Copy ();
use File::Path ();
use File::Spec;
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) {
);
$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 @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;
}
"$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;
}