]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blobdiff - lib/CPANPLUS/Dist/Gentoo.pm
Set the default keywords with ACCEPT_KEYWORDS from emerge --info
[perl/modules/CPANPLUS-Dist-Gentoo.git] / lib / CPANPLUS / Dist / Gentoo.pm
index 5705c4afd7a414c3a8e904c378ac5a3b23678d99..de074580dc694861666a41e426a63ebb490e604e 100644 (file)
@@ -39,7 +39,7 @@ 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</usr/local/portage>), 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</usr/portage/distfiles>). You also need to specify the correct keyword for your architecture if it differs from the default C<x86>.
+This module is a CPANPLUS backend that recursively generates Gentoo ebuilds for a given package in the specified overlay (defaults to F</usr/local/portage>), 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</usr/portage/distfiles>). The valid C<KEYWORDS> for the generated ebuilds are by default those given in C<ACCEPT_KEYWORDS>, but you can specify your own with the C<keywords> dist-option.
 
 The generated ebuilds are placed into the C<perl-gcpanp> category. They favour depending on C<perl-core>, C<dev-perl> or C<perl-gcpan> (in that order) rather than C<perl-gcpanp>.
 
@@ -55,6 +55,9 @@ All the methods are inherited from L<CPANPLUS::Dist::Base>. Please refer to its
 
 use constant CATEGORY => 'perl-gcpanp';
 
+my $overlays;
+my $default_keywords;
+
 sub format_available {
  for my $prog (qw/emerge ebuild/) {
   unless (can_run($prog)) {
@@ -62,6 +65,32 @@ sub format_available {
    return 0;
   }
  }
+
+ if (IPC::Cmd->can_capture_buffer) {
+  my ($success, $errmsg, $output) = run command => [ qw/emerge --info/ ],
+                                        verbose => 0;
+  if ($success) {
+   for (@{$output || []}) {
+    if (/^PORTDIR_OVERLAY=(.*)$/m) {
+     my $o = $1;
+     $o =~ s/^["']*//;
+     $o =~ s/["']*$//;
+     $overlays = [ map abs_path($_), grep length, split /:/, $o ];
+    }
+    if (/^ACCEPT_KEYWORDS=(.*)$/m) {
+     my $k = $1;
+     $k =~ s/^["']*//;
+     $k =~ s/["']*$//;
+     $default_keywords = [ split ' ', $k ];
+    }
+   }
+  } else {
+   error $errmsg;
+  }
+ }
+
+ $default_keywords = [ 'x86' ] unless defined $default_keywords;
+
  return 1;
 }
 
@@ -72,6 +101,7 @@ sub init {
 
  $stat->mk_accessors(qw/name version author distribution desc uri src license
                         deps eb_name eb_version eb_dir eb_file fetched_arch
+                        portdir_overlay
                         overlay distdir keywords do_manifest header footer
                         force verbose/);
 
@@ -167,8 +197,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'};
@@ -207,6 +240,18 @@ sub prepare {
  }
  $stat->fetched_arch($mod->status->fetch);
 
+ my $cur = File::Spec::Functions::curdir();
+ my $portdir_overlay;
+ for (@$overlays) {
+  if ($_ eq $overlay or File::Spec::Functions::abs2rel($overlay, $_) eq $cur) {
+   $portdir_overlay = join ':', @$overlays;
+   last;
+  }
+ }
+ $portdir_overlay = join ':', @$overlays, $overlay
+                                                unless defined $portdir_overlay;
+ $stat->portdir_overlay($portdir_overlay);
+
  my $name = $mod->package_name;
  $stat->name($name);
 
@@ -235,6 +280,8 @@ sub prepare {
 
  my $file = catfile($stat->eb_dir,
                     $stat->eb_name . '-' . $stat->eb_version . '.ebuild');
+ $stat->eb_file($file);
+
  if (-e $file) {
   my $skip = 1;
   if ($stat->force) {
@@ -254,7 +301,6 @@ sub prepare {
    return 1;
   }
  }
- $stat->eb_file($file);
 
  $self->SUPER::prepare(%opts);
 
@@ -427,7 +473,7 @@ sub _run {
  my $stat = $self->status;
 
  my ($success, $errmsg, $output) = do {
-  local $ENV{PORTDIR_OVERLAY}     = $stat->overlay;
+  local $ENV{PORTDIR_OVERLAY}     = $stat->portdir_overlay;
   local $ENV{PORTAGE_RO_DISTDIRS} = $stat->distdir;
   run command => $cmd, verbose => $verbose;
  };