]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blobdiff - lib/CPANPLUS/Dist/Gentoo.pm
Write the ebuild only after the dependencies were handled
[perl/modules/CPANPLUS-Dist-Gentoo.git] / lib / CPANPLUS / Dist / Gentoo.pm
index 67d58324a0ae72e717fc8f083e700d03f6c7ec83..49de89288dce24c55a4f6dbf9b5da1eb899bd76e 100644 (file)
@@ -337,8 +337,23 @@ sub create {
  my $self = shift;
  my $stat = $self->status;
 
- my $OK   = sub { $stat->created(1); $stat->dist($stat->ebuild_file); 1 };
- my $FAIL = sub { $stat->created(0); $stat->dist(undef); $self->_abort(@_) if @_; 0 };
+ my $file;
+
+ my $OK   = sub {
+  $stat->created(1);
+  $stat->dist($file);
+  1;
+ };
+
+ my $FAIL = sub {
+  $stat->created(0);
+  $stat->dist(undef);
+  $self->_abort(@_) if @_;
+  if ($file and -f $file) {
+   1 while unlink $file;
+  }
+  0;
+ };
 
  unless ($stat->prepared) {
   return $FAIL->(
@@ -357,26 +372,28 @@ sub create {
   return $FAIL->("mkpath($dir): $@") if $@;
  }
 
- my $file = $stat->ebuild_file;
- open my $eb, '>', $file or return $FAIL->("open($file): $!");
- print $eb $self->ebuild_source;
- close $eb;
+ $file = $stat->ebuild_file;
+
+ # Create a placeholder ebuild to prevent recursion with circular dependencies.
+ {
+  open my $eb, '>', $file or return $FAIL->("open($file): $!");
+  print $eb "PLACEHOLDER\n";
+ }
 
  $stat->created(0);
  $stat->dist(undef);
 
  $self->SUPER::create(@_);
 
- unless ($stat->created) {
-  1 while unlink $file;
-  return $FAIL->();
- }
+ return $FAIL->() unless $stat->created;
 
if ($stat->do_manifest and not $self->update_manifest) {
-  1 while unlink $file;
-  return $FAIL->();
+ {
+  open my $eb, '>', $file or return $FAIL->("open($file): $!");
+  print $eb $self->ebuild_source;
  }
 
+ return $FAIL->() if $stat->do_manifest and not $self->update_manifest;
+
  return $OK->();
 }