Skip to content
This repository has been archived by the owner on Mar 7, 2019. It is now read-only.

Commit

Permalink
added handling of the 'blib scheme'
Browse files Browse the repository at this point in the history
This involved logically changing some of the install behaviors if the blib scheme used by some CPANtesters is detected. Notably that the files are targeted to the blib directory and not the final destination.
This behavior can be prevented by setting ALIEN_BLIB=0 explicity before running ACTION_build
  • Loading branch information
jberger committed Mar 2, 2013
1 parent 6187875 commit fb2b6b4
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/Alien/Base/Authoring.pod
Expand Up @@ -25,7 +25,7 @@ L<Alien::Base::ModuleBuild> provides a base class, utility methods and configura

This is just like you would do for L<Module::Build>, except that there will be a few additional configuration parameters (see L<Alien::Base::ModuleBuild::API>).

L<Alien::Base::ModuleBuild> adds the additional build action C<alien>. This action need never be run directly, the usual C<build> action (usually seen as C<./Build>) will call it for you. The C<alien> action is responsible for finding, downloading, extracting and building the external libary (the commands specified in builder parameter C<alien_build_commands>).
L<Alien::Base::ModuleBuild> adds the additional build actions C<alien_code> and C<alien_install>. These actions need never be run directly, the usual C<build> action (usually seen as C<./Build>) and C<install> (C<./Build install>) will call them for you. The C<alien_code> action is responsible for finding, downloading, extracting and building the external libary (the commands specified in builder parameter C<alien_build_commands>). The C<alien_install> action is responsible for installing the library into its final destination.

The C<./Build test> command will invoke any library tests specified in C<alien_test_commands>, though none are defined by default. Finally C<./Build install> will invoke whatever C<alien_install_commands> were specified.

Expand Down
77 changes: 68 additions & 9 deletions lib/Alien/Base/ModuleBuild.pm
Expand Up @@ -15,7 +15,7 @@ use File::Basename qw/fileparse/;
use Carp;
use Archive::Extract;
use Sort::Versions;
use List::MoreUtils qw/uniq/;
use List::MoreUtils qw/uniq first_index/;
use ExtUtils::Installed;

use Alien::Base::PkgConfig;
Expand Down Expand Up @@ -182,11 +182,24 @@ END

sub ACTION_code {
my $self = shift;
$self->depends_on('alien') unless $self->notes('ACTION_alien_completed');
$self->SUPER::ACTION_code;
$self->notes( 'alien_blib_scheme' => $self->alien_detect_blib_scheme );

# PLEASE NOTE, BOTH BRANCHES CALL SUPER::ACTION_code !!!!!!!
if ( $self->notes('ACTION_alien_completed') ) {

$self->SUPER::ACTION_code;

} else {

$self->depends_on('alien_code');
$self->SUPER::ACTION_code;

# copy the compiled files into blib if running under blib scheme
$self->depends_on('alien_install') if $self->notes('alien_blib_scheme');
}
}

sub ACTION_alien {
sub ACTION_alien_code {
my $self = shift;
$self->alien_init_temp_dir;

Expand Down Expand Up @@ -264,6 +277,7 @@ sub ACTION_alien {

# prevent building multiple times (on M::B::dispatch)
$self->notes( 'ACTION_alien_completed' => 1 );

return;
}

Expand All @@ -280,6 +294,12 @@ sub ACTION_test {
sub ACTION_install {
my $self = shift;
$self->SUPER::ACTION_install;
$self->depends_on('alien_install');
}

sub ACTION_alien_install {
my $self = shift;

return if $self->config_data( 'install_type' ) eq 'system';

{
Expand All @@ -296,7 +316,7 @@ sub ACTION_install {

{
local $CWD = $self->config_data( 'working_directory' );
print "Installing library ... ";
print "Installing library to $CWD ... ";
$self->alien_do_commands('install') or die "Failed\n";
print "Done\n";
}
Expand All @@ -307,10 +327,18 @@ sub ACTION_install {

# to refresh config_data
$self->SUPER::ACTION_config_data;
$self->SUPER::ACTION_install;

# refresh the packlist
$self->alien_refresh_packlist( $self->alien_library_destination );
if ( $self->notes( 'alien_blib_scheme') ) {
# reinstall config_data to blib
$self->process_files_by_extension('pm');

} else {
# reinstall config_data
$self->SUPER::ACTION_install;

# refresh the packlist
$self->alien_refresh_packlist( $self->alien_library_destination );
}
}

#######################
Expand Down Expand Up @@ -385,12 +413,43 @@ sub alien_validate_repo {

sub alien_library_destination {
my $self = shift;
my $lib_dir = $self->install_destination('lib');

# send the library into the blib if running under the blib scheme
my $lib_dir =
$self->notes('alien_blib_scheme')
? File::Spec->catdir( $self->base_dir, $self->blib, 'lib' )
: $self->install_destination('lib');

my $dist_name = $self->dist_name;
my $dest = File::Spec->catdir( $lib_dir, qw/auto share dist/, $dist_name );
return $dest;
}

# CPAN testers often run tests without installing modules, but rather add
# blib dirs to @INC, this is a problem, so here we try to deal with it
sub alien_detect_blib_scheme {
my $self = shift;

return $ENV{ALIEN_BLIB} if defined $ENV{ALIEN_BLIB};

# check to see if Alien::Base::ModuleBuild is running from blib.
# if so it is likely that this is the blib scheme

(undef, my $dir, undef) = File::Spec->splitpath( __FILE__ );
my @dirs = File::Spec->splitdir($dir);

my $index = first_index { $_ eq 'blib' } @dirs;
return 0 if $index == -1;

if ( $dirs[$index+1] eq 'lib' ) {
print q{'blib' scheme is detected. Setting ALIEN_BLIB=1. If this has been done in error, please set ALIEN_BLIB and restart build process to disambiguate.};
return 1;
}

carp q{'blib' scheme is suspected, but uncertain. Please set ALIEN_BLIB and restart build process to disambiguate. Setting ALIEN_BLIB=1 for now.};
return 1;
}

###################
# Build Methods #
###################
Expand Down
4 changes: 4 additions & 0 deletions lib/Alien/Base/ModuleBuild/API.pod
Expand Up @@ -146,6 +146,10 @@ Setting the either to a true value will output a little more info from within th

Setting either to a true value will cause the builder to ignore a system-wide installation and build a local version of the library.

=item $ENV{ALIEN_BLIB}

Setting this to true indicates that you don't intend to actually install your Alien::Base subclass, but rather use it from the built F<blib> directory. This behavior is mostly to support automated testing from CPANtesters and should be automagically determined. If by chance you happen to trip the behavior accidentally, setting this environment variable to false (0) before building should prevent problems.

=back

=head2 CONFIG DATA
Expand Down

0 comments on commit fb2b6b4

Please sign in to comment.