From: Vincent Pit Date: Wed, 7 Jan 2009 17:52:13 +0000 (+0100) Subject: For each CPAN dependency, search in which category we should search for the correspon... X-Git-Tag: v0.05~4 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=49b98e4e449f39ffddf4278def568afb5c20d6db;p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git For each CPAN dependency, search in which category we should search for the corresponding portage dependency (including virtuals). This ensures that we only state in DEPEND atoms that really exists in the portage tree. version is required. --- diff --git a/Makefile.PL b/Makefile.PL index 7101df2..e0f3ad6 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -32,7 +32,8 @@ WriteMakefile( 'File::Copy' => 0, 'File::Path' => 0, 'File::Spec::Functions' => 0, - 'IPC::Cmd' => 0 + 'IPC::Cmd' => 0, + 'version' => 0, }, dist => { PREOP => 'pod2text lib/CPANPLUS/Dist/Gentoo.pm > $(DISTVNAME)/README; ' diff --git a/lib/CPANPLUS/Dist/Gentoo.pm b/lib/CPANPLUS/Dist/Gentoo.pm index 8e1809c..72450d7 100644 --- a/lib/CPANPLUS/Dist/Gentoo.pm +++ b/lib/CPANPLUS/Dist/Gentoo.pm @@ -9,6 +9,7 @@ use File::Path qw/mkpath/; use File::Spec::Functions qw/catdir catfile/; use IPC::Cmd qw/run can_run/; +use version; use CPANPLUS::Error; @@ -41,7 +42,7 @@ our $VERSION = '0.04'; This module is a CPANPLUS backend that recursively generates Gentoo ebuilds for a given package in the specified overlay (defaults to F), updates the manifest, and even emerges it (together with its dependencies) if the user requires it. You need write permissions on the directory where Gentoo fetches its source files (usually F). The valid C for the generated ebuilds are by default those given in C, but you can specify your own with the C dist-option. -The generated ebuilds are placed into the C category. They favour depending on C, C or C (in that order) rather than C. +The generated ebuilds are placed into the C category. They favour depending on a C, on C, C or C (in that order) rather than C. =head1 INSTALLATION @@ -58,6 +59,7 @@ use constant CATEGORY => 'perl-gcpanp'; my $overlays; my $default_keywords; my $default_distdir; +my $main_portdir; sub _unquote { my $s = shift; @@ -88,6 +90,9 @@ sub format_available { if (/^DISTDIR=(.*)$/m) { $default_distdir = abs_path(_unquote($1)); } + if (/^PORTDIR=(.*)$/m) { + $main_portdir = abs_path(_unquote($1)); + } } } else { error $errmsg; @@ -338,7 +343,7 @@ sub prepare { $version = $obj->package_version; } } - push @depends, [ $obj , $version ]; + push @depends, [ $obj->package_name, $version ]; } } $stat->deps(\@depends); @@ -389,21 +394,10 @@ sub create { $d .= "SLOT=\"0\"\n"; $d .= 'LICENSE="|| ( ' . join(' ', sort @{$stat->license}) . " )\"\n"; $d .= 'KEYWORDS="' . join(' ', sort @{$stat->keywords}) . "\"\n"; - $d .= 'DEPEND="' . join "\n", + $d .= 'DEPEND="' . join("\n", 'dev-lang/perl', - map { - my $a = $_->[0]->package_name; - $a = $gentooism{$a} || $a; - my $x = ''; - if (defined $_->[1]) { - $x = '>='; - $a .= '-' . $_->[1]; - } - '|| ( ' . join(' ', map "$x$_/$a", - qw/perl-core dev-perl perl-gcpan/, CATEGORY) - . ' )'; - } @{$stat->deps}; - $d .= "\"\n"; + map $self->_cpan2portage(@$_), @{$stat->deps} + ) . "\"\n"; $d .= "SRC_TEST=\"do\"\n"; $d .= $stat->footer; @@ -434,6 +428,41 @@ sub create { return 1; } +sub _cpan2portage { + my ($self, $name, $version) = @_; + + $name = $gentooism{$name} || $name; + my $ver; + $ver = eval { version->new($version) } if defined $version; + + my @portdirs = ($main_portdir, @{$self->status->portdir_overlay}); + + for my $category (qw/virtual perl-core dev-perl perl-gcpan/, CATEGORY) { + my $atom = ($category eq 'virtual' ? 'perl-' : '') . $name; + + for my $portdir (@portdirs) { + my @ebuilds = glob catfile($portdir, $category, $atom,"$atom-*.ebuild"); + next unless @ebuilds; + + if (defined $version) { + for (@ebuilds) { + next unless /\Q$atom\E-v?([\d._]+).*?\.ebuild$/; + my $eb_ver = eval { version->new($1) }; + next unless defined $eb_ver and $eb_ver >= $ver; + return ">=$category/$atom-$version"; + } + } else { + return "$category/$atom"; + } + + } + + } + + error "Couldn't find an appropriate ebuild for $name in the portage tree -- skipping"; + return ''; +} + sub install { my $self = shift; my $stat = $self->status; @@ -490,7 +519,7 @@ sub _run { Gentoo (L). -L, L (core modules since 5.9.5). +L, L (core modules since 5.9.5), L (since 5.009). L (since perl 5) L (5.001), L (5.002), L (5.00504). diff --git a/samples/g-cpanp b/samples/g-cpanp index 2249336..b18fdbd 100755 --- a/samples/g-cpanp +++ b/samples/g-cpanp @@ -5,8 +5,8 @@ HEADER="# Copyright 1999-2008 Gentoo Foundation # For debugging only : # PERL5LIB=blib/lib \ -exec cpan2dist --format=CPANPLUS::Dist::Gentoo \ - --dist-opts manifest=yes \ - --dist-opts header="$HEADER" \ - --skiptest --verbose \ +exec cpan2dist --format=CPANPLUS::Dist::Gentoo \ + --dist-opts manifest=yes \ + --dist-opts header="$HEADER" \ + --skiptest --verbose --buildprereq \ $@