From: Vincent Pit Date: Fri, 4 Sep 2009 17:04:28 +0000 (+0200) Subject: Check in prepare() if there isn't an ebuild available yet X-Git-Tag: v0.08~3 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git;a=commitdiff_plain;h=3e56111c31afdf423151f775d2e7afd08bc16958 Check in prepare() if there isn't an ebuild available yet Unless under --force, when an ebuild in this category is always generated. --- diff --git a/Makefile.PL b/Makefile.PL index 9cb62fc..a20116d 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -33,6 +33,7 @@ WriteMakefile( 'Carp' => 0, 'CPANPLUS' => 0, 'Cwd' => 0, + 'List::Util' => 0, 'File::Copy' => 0, 'File::Path' => 0, 'File::Spec' => 0, diff --git a/lib/CPANPLUS/Dist/Gentoo.pm b/lib/CPANPLUS/Dist/Gentoo.pm index 70fc27b..49105e8 100644 --- a/lib/CPANPLUS/Dist/Gentoo.pm +++ b/lib/CPANPLUS/Dist/Gentoo.pm @@ -4,6 +4,7 @@ use strict; use warnings; use Cwd qw/abs_path/; +use List::Util qw/reduce/; use File::Copy (); use File::Path (); use File::Spec; @@ -146,6 +147,7 @@ sub prepare { 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) { @@ -227,24 +229,24 @@ sub prepare { ); $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); } } @@ -439,7 +441,12 @@ sub 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; } @@ -482,25 +489,24 @@ sub _cpan2portage { "$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; }