Skip to content

Commit

Permalink
create a symlink in .build/latest for all builds
Browse files Browse the repository at this point in the history
  • Loading branch information
karenetheridge authored and rjbs committed Jun 7, 2020
1 parent 9cbfcdd commit e050407
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Revision history for {{$dist->name}}
Etheridge)
- the test generated by [MetaTests] is now an author test, not a
release test (thanks, Karen Etheridge)
- all builds now result in a .build/latest symlink (thanks again,
Karen)

6.015 2020-05-29 14:30:51-04:00 America/New_York
- add docs for "dzil release -j" (thanks, Jonas B. Nielsen)
Expand Down
32 changes: 23 additions & 9 deletions lib/Dist/Zilla/Dist/Builder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ sub build_in {
$_->after_build({ build_root => $build_root })
for $self->plugins_with(-AfterBuild);

$self->_create_build_symlinks(path('.build'), $build_root);

$self->built_in($build_root);
}

Expand Down Expand Up @@ -653,28 +655,40 @@ sub ensure_built_in_tmpdir {
my $target = path( File::Temp::tempdir(DIR => $build_root) );
$self->log("building distribution under $target for installation");

my ($latest, $previous) = $self->_create_build_symlinks($build_root, $target);

$self->build_in($target);

return ($target, $latest, $previous);
}

sub _create_build_symlinks {
my ($self, $symlink_root, $build_target) = @_;

$symlink_root->mkpath unless -d $symlink_root;

my $os_has_symlinks = eval { symlink("",""); 1 };
my $previous;
my $latest;

if( $os_has_symlinks ) {
$previous = path( $build_root, 'previous' );
$latest = path( $build_root, 'latest' );
$previous = path( $symlink_root, 'previous' );
$latest = path( $symlink_root, 'latest' );
if( -l $previous ) {
$previous->remove
or $self->log("cannot remove old .build/previous link");
or $self->log([ 'cannot remove old %s/previous link', $symlink_root ]);
}
if( -l $latest ) {
rename $latest, $previous
or $self->log("cannot move .build/latest link to .build/previous");
or $self->log([ 'cannot move %s/latest link to .build/previous', $symlink_root ]);
}
symlink $target->basename, $latest
or $self->log('cannot create link .build/latest');
}

$self->build_in($target);
my $link_dest = path($build_target)->relative(path($latest)->parent);
symlink $link_dest->stringify, $latest
or $self->log([ 'cannot create link %s/latest', $symlink_root ]);
}

return ($target, $latest, $previous);
return ($latest, $previous);
}

=method install
Expand Down

0 comments on commit e050407

Please sign in to comment.