X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git;a=blobdiff_plain;f=lib%2FCPANPLUS%2FDist%2FGentoo.pm;h=d40bf881a8f6969adad3e31fe5c49e5aa98fd293;hp=7f138049d1e21dc72a317d52e20a18292c729d9a;hb=7aa1972cf85390e3b6432fe63d1120dbb5967fdd;hpb=02fbb17472e55a0862fea51d8f4e530a9af9153c diff --git a/lib/CPANPLUS/Dist/Gentoo.pm b/lib/CPANPLUS/Dist/Gentoo.pm index 7f13804..d40bf88 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; @@ -20,11 +21,11 @@ CPANPLUS::Dist::Gentoo - CPANPLUS backend generating Gentoo ebuilds. =head1 VERSION -Version 0.04 +Version 0.05 =cut -our $VERSION = '0.04'; +our $VERSION = '0.05'; =head1 SYNOPSIS @@ -39,9 +40,9 @@ our $VERSION = '0.04'; =head1 DESCRPITON -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). You also need to specify the correct keyword for your architecture if it differs from the default C. +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 @@ -56,6 +57,16 @@ All the methods are inherited from L. Please refer to its use constant CATEGORY => 'perl-gcpanp'; my $overlays; +my $default_keywords; +my $default_distdir; +my $main_portdir; + +sub _unquote { + my $s = shift; + $s =~ s/^["']*//; + $s =~ s/["']*$//; + return $s; +} sub format_available { for my $prog (qw/emerge ebuild/) { @@ -71,10 +82,16 @@ sub format_available { if ($success) { for (@{$output || []}) { if (/^PORTDIR_OVERLAY=(.*)$/m) { - my $o = $1; - $o =~ s/^["']*//; - $o =~ s/["']*$//; - $overlays = [ map abs_path($_), grep length, split /:/, $o ]; + $overlays = [ map abs_path($_), split ' ', _unquote($1) ]; + } + if (/^ACCEPT_KEYWORDS=(.*)$/m) { + $default_keywords = [ split ' ', _unquote($1) ]; + } + if (/^DISTDIR=(.*)$/m) { + $default_distdir = abs_path(_unquote($1)); + } + if (/^PORTDIR=(.*)$/m) { + $main_portdir = abs_path(_unquote($1)); } } } else { @@ -82,6 +99,9 @@ sub format_available { } } + $default_keywords = [ 'x86' ] unless defined $default_keywords; + $default_distdir = '/usr/portage/distfiles' unless defined $default_distdir; + return 1; } @@ -102,7 +122,7 @@ sub init { return 1; } -my %gentooism = ( +our %gentooism = ( 'ANSIColor' => 'Term-ANSIColor', 'Audio-CD' => 'Audio-CD-disc-cover', 'CGI-Simple' => 'Cgi-Simple', @@ -188,8 +208,11 @@ sub prepare { $stat->prepared(0); my $keywords = delete $opts{'keywords'}; - $keywords = 'x86' unless defined $keywords; - $keywords = [ split ' ', $keywords ]; + if (defined $keywords) { + $keywords = [ split ' ', $keywords ]; + } else { + $keywords = $default_keywords; + } $stat->keywords($keywords); my $manifest = delete $opts{'manifest'}; @@ -219,7 +242,7 @@ sub prepare { $stat->overlay($overlay); my $distdir = delete $opts{'distdir'}; - $distdir = (defined $distdir) ? abs_path $distdir : '/usr/portage/distfiles'; + $distdir = (defined $distdir) ? abs_path $distdir : $default_distdir; $stat->distdir($distdir); if ($stat->do_manifest && !-w $stat->distdir) { @@ -232,12 +255,11 @@ sub prepare { my $portdir_overlay; for (@$overlays) { if ($_ eq $overlay or File::Spec::Functions::abs2rel($overlay, $_) eq $cur) { - $portdir_overlay = join ':', @$overlays; + $portdir_overlay = [ @$overlays ]; last; } } - $portdir_overlay = join ':', @$overlays, $overlay - unless defined $portdir_overlay; + $portdir_overlay = [ @$overlays, $overlay ] unless $portdir_overlay; $stat->portdir_overlay($portdir_overlay); my $name = $mod->package_name; @@ -328,7 +350,7 @@ sub prepare { $version = $obj->package_version; } } - push @depends, [ $obj , $version ]; + push @depends, [ $obj->package_name, $version ]; } } $stat->deps(\@depends); @@ -381,21 +403,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; @@ -426,6 +437,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 $ver) { # implies that $version is defined + 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; @@ -461,7 +507,7 @@ sub _run { my $stat = $self->status; my ($success, $errmsg, $output) = do { - local $ENV{PORTDIR_OVERLAY} = $stat->portdir_overlay; + local $ENV{PORTDIR_OVERLAY} = join ' ', @{$stat->portdir_overlay}; local $ENV{PORTAGE_RO_DISTDIRS} = $stat->distdir; run command => $cmd, verbose => $verbose; }; @@ -482,7 +528,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). @@ -516,7 +562,7 @@ Kent Fredric, for testing and suggesting improvements. =head1 COPYRIGHT & LICENSE -Copyright 2008 Vincent Pit, all rights reserved. +Copyright 2008-2009 Vincent Pit, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.