From: Vincent Pit Date: Fri, 27 Nov 2009 00:37:39 +0000 (+0100) Subject: Strip duplicated entries in the RDEPEND list X-Git-Tag: v0.09~19 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=74685418c28730b1369e262955b9ffef57cda050;p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git Strip duplicated entries in the RDEPEND list --- diff --git a/lib/CPANPLUS/Dist/Gentoo.pm b/lib/CPANPLUS/Dist/Gentoo.pm index a753ab4..c27c5b5 100644 --- a/lib/CPANPLUS/Dist/Gentoo.pm +++ b/lib/CPANPLUS/Dist/Gentoo.pm @@ -316,8 +316,8 @@ sub prepare { 1 while unlink $file; } } else { - if (my @match = $self->_cpan2portage($name, $version)) { - $stat->dist($match[1]); + if (my $atom = $self->_cpan2portage($name, $version)) { + $stat->dist($atom->ebuild); return $SKIP->('Ebuild already generated for', $stat->distribution); } } @@ -513,17 +513,21 @@ sub ebuild_source { # dist. my @requires; for (@{$stat->requires}) { - my $dep = $self->_cpan2portage(@$_); - unless (defined $dep) { + my $atom = $self->_cpan2portage(@$_); + unless (defined $atom) { $self->_abort( "Couldn't find an appropriate ebuild for $_->[0] in the portage tree" ); return; } - push @requires, $dep; + push @requires, $atom; } - @requires = do { my %seen; sort grep !$seen{$_}++, 'dev-lang/perl',@requires }; + my $perl = CPANPLUS::Dist::Gentoo::Atom->new( + category => 'dev-lang', + name => 'perl', + ); + @requires = CPANPLUS::Dist::Gentoo::Atom->fold($perl, @requires); my $d = $stat->header; $d .= "# Generated by CPANPLUS::Dist::Gentoo version $VERSION\n\n"; @@ -535,7 +539,7 @@ 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", @requires) . "\"\n"; + $d .= 'RDEPEND="' . join("\n", sort @requires) . "\"\n"; $d .= "DEPEND=\"\${RDEPEND}\"\n"; $d .= "SRC_TEST=\"do\"\n"; $d .= $stat->footer; @@ -563,19 +567,14 @@ sub _cpan2portage { "$atom-*.ebuild", ) or next; - my $last = reduce { $a->[1] < $b->[1] ? $b : $a } - map [ $_, CPANPLUS::Dist::Gentoo::Atom->new(ebuild => $_) ], - @ebuilds; - - my $dep; - if (defined $ver) { # implies that $version is defined - next if $last < $ver; - $dep = ">=$category/$atom-$ver"; - } else { - $dep = "$category/$atom"; - } + my $atom = reduce { $a < $b ? $b : $a } # handles overloading + map CPANPLUS::Dist::Gentoo::Atom->new( + ebuild => $_, + minimum => 1, + ), @ebuilds; + next if defined $ver and $atom < $ver; - return wantarray ? ($dep, $last->[0]) : $dep; + return $atom; } } diff --git a/lib/CPANPLUS/Dist/Gentoo/Atom.pm b/lib/CPANPLUS/Dist/Gentoo/Atom.pm index b017e6b..45a68c5 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Atom.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Atom.pm @@ -49,15 +49,20 @@ sub new { } } + Carp::confess('Minimum atoms require a valid version') if not defined $version + and $args{minimum}; + bless { category => $category, name => $name, version => $name, + minimum => $args{minimum}, + ebuild => $args{ebuild}, }, $class; } BEGIN { - eval "sub $_ { \$_[0]->{$_} }" for qw/category name version/; + eval "sub $_ { \$_[0]->{$_} }" for qw/category name version minimum ebuild/; } sub cmp { @@ -82,7 +87,50 @@ sub cmp { sub as_string { my ($a) = @_; - $a->category . '/' . $a->name . '-' . $a->version; + my $atom = $a->category . '/' . $a->name; + + my $version = $a->version; + if (defined $version) { + $atom = "=$atom-$version"; + $atom = ">$atom" if $a->minimum; + } + + return $atom; +} + +sub fold { + shift unless length ref $_[0]; + + my %seen; + for my $atom (@_) { + my ($category, $name, $version) = map $atom->$_, qw/category name version/; + my $key = join '/', $category, $name; + my $cur = $seen{$key}; + + unless (defined $cur) { + $seen{$key} = $atom; + next; + } + + next unless defined $version; + + if (not defined $cur->version) { + $seen{$key} = $atom; + next; + } + + if ($atom->minimum) { + if ($cur->minmium) { + $seen{$key} = $atom < $cur ? $cur : $atom; + } else { + Carp::confess('Version mismatch') if $atom > $cur; + } + } elsif ($cur->minimum) { + Carp::confess('Version mismatch') if $cur > $atom; + } + } + + return values %seen; } 1;