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

DESTDIR support #65

Merged
merged 8 commits into from Sep 9, 2014
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 29 additions & 4 deletions lib/Alien/Base/ModuleBuild.pm
Expand Up @@ -323,8 +323,11 @@ sub ACTION_alien_install {

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

my $destdir = $self->destdir;

{
my $target = $self->alien_library_destination;
$target = File::Spec->catdir($destdir, $target) if defined $destdir;
local $CWD = $target;

# The only form of introspection that exists is to see that the README file
Expand All @@ -337,13 +340,17 @@ sub ACTION_alien_install {

{
local $CWD = $self->config_data( 'working_directory' );
local $ENV{DESTDIR} = $ENV{DESTDIR};
$ENV{DESTDIR} = $destdir if defined $destdir;
print "Installing library to $CWD ... ";
$self->alien_do_commands('install') or die "Failed\n";
print "Done\n";
}

if ( $self->alien_isolate_dynamic ) {
local $CWD = $self->alien_library_destination;
my $target = $self->alien_library_destination;
$target = File::Spec->catdir($destdir, $target) if defined $destdir;
local $CWD = $target;
print "Isolating dynamic libraries ... ";
mkdir 'dynamic' unless -d 'dynamic';
foreach my $dir (qw( bin lib )) {
Expand Down Expand Up @@ -718,7 +725,7 @@ sub alien_find_lib_paths {
my @files =
map { File::Spec->abs2rel( $_, $dir ) } # make relative to $dir
grep { ! -d }
@{ $self->rscan_dir( $dir, $file_pattern ) };
@{ $self->_rscan_destdir( $dir, $file_pattern ) };

my (@so_files, @lib_paths, @inc_paths);
for (@files) {
Expand Down Expand Up @@ -756,12 +763,20 @@ sub alien_refresh_packlist {
my $self = shift;
my $dir = shift || croak "Must specify a directory to include in packlist";

my $inst = ExtUtils::Installed->new;
return unless $self->create_packlist;

my %installed_args;
$installed_args{extra_libs} = [map { File::Spec->catdir($self->destdir, $_) } @INC]
if defined $self->destdir;

my $inst = ExtUtils::Installed->new( %installed_args );
my $packlist = $inst->packlist( $self->module_name );
print "Using " . $packlist->packlist_file . "\n";

my $changed = 0;
my $files = $self->rscan_dir($dir);
my $files = $self->_rscan_destdir($dir);
$files = [ map { File::Spec->catdir($self->destdir, $_) } @$files ]
if defined $self->destdir;
for my $file (@$files) {
next if $packlist->{$file};
print "Adding $file to packlist\n";
Expand All @@ -772,6 +787,16 @@ sub alien_refresh_packlist {
$packlist->write if $changed;
}

sub _rscan_destdir {
my($self, $dir, $pattern) = @_;
my $destdir = $self->destdir;
$dir = File::Spec->catdir($destdir, $dir) if defined $destdir;
$dir =~ s{\\}{/}g if $^O eq 'MSWin32';
my $files = $self->rscan_dir($dir, $pattern);
$files = [ map { s/^$destdir//; $_ } @$files ] if defined $destdir;
$files;
}

1;

__END__
Expand Down
24 changes: 12 additions & 12 deletions lib/Alien/Base/ModuleBuild/API.pod
Expand Up @@ -71,18 +71,6 @@ These parameters, if specified, augment the information found by F<pkg-config>.

A hashref or arrayref of hashrefs defining the repositories used to find and fetch library tarballs (or zipballs etc.). These attributes are used to create C<Alien::Base::ModuleBuild::Repository> objects (or more likely, subclasses thereof). Which class is created is governed by the C<protocol> attribute and the C<alien_repository_class> property below. Available attributes are:

=item alien_isolate_dynamic

[version 0.005]

If set to true, then dynamic libraries will be moved from the C<lib> directory to a separate C<dynamic> directory. This makes them available for FFI modules (see L<FFI::Raw>), while preferring static libraries when creating XS extensions.

=item alien_autoconf_with_pic

[version 0.005]

Add C<--with-pic> option to autoconf style C<configure> script when called. This is the default, and normally a good practice. Normally autoconf will ignore this and any other options that it does not recognize, but some non-autoconf C<configure> scripts may complain.

=over

=item protocol
Expand Down Expand Up @@ -119,6 +107,18 @@ This attribute is a string telling the repository validator which platform the r

=back

=item alien_isolate_dynamic

[version 0.005]

If set to true, then dynamic libraries will be moved from the C<lib> directory to a separate C<dynamic> directory. This makes them available for FFI modules (see L<FFI::Raw>), while preferring static libraries when creating XS extensions.

=item alien_autoconf_with_pic

[version 0.005]

Add C<--with-pic> option to autoconf style C<configure> script when called. This is the default, and normally a good practice. Normally autoconf will ignore this and any other options that it does not recognize, but some non-autoconf C<configure> scripts may complain.

=item alien_repository_default

[version 0.001]
Expand Down
77 changes: 69 additions & 8 deletions t/builder.t
Expand Up @@ -6,6 +6,7 @@ use Test::More;
use Alien::Base::ModuleBuild;
use File::chdir;
use File::Temp ();
use File::Path qw( rmtree );

my $dir = File::Temp->newdir;
local $CWD = "$dir";
Expand All @@ -22,8 +23,8 @@ sub builder { return Alien::Base::ModuleBuild->new( %basic, @_ ) }
# Temporary Directories #
###########################

{
unlink qw/_alien _share/;
subtest 'default temp and share' => sub {
rmtree [qw/_alien _share/], 0, 1;

my $builder = builder;

Expand All @@ -39,11 +40,11 @@ sub builder { return Alien::Base::ModuleBuild->new( %basic, @_ ) }
ok( ! -d '_alien', "Removes _alien dir");
ok( ! -d '_share', "Removes _share dir");

unlink qw/_alien _share/;
}
rmtree [qw/_alien _share/], 0, 1;
};

{
unlink qw/_test_temp _test_share/;
subtest 'override temp and share' => sub {
rmtree [qw/_test_temp _test_share/], 0, 1;

my $builder = builder(
alien_temp_dir => '_test_temp',
Expand All @@ -58,8 +59,68 @@ sub builder { return Alien::Base::ModuleBuild->new( %basic, @_ ) }
ok( ! -d '_test_temp', "Removes _test_temp dir");
ok( ! -d '_test_share', "Removes _test_share dir");

unlink qw/_test_temp _test_share/;
}
rmtree [qw/_test_temp _test_share/], 0, 1;
};

subtest 'destdir' => sub {

open my $fh, '>', 'build.pl';
print $fh <<'EOF';
use strict;
use warnings;
use File::Copy qw( copy );

my $cmd = shift;
@ARGV = grep { s/DESTDIR/$ENV{DESTDIR}/eg; $_ } @ARGV;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is modifying $_ in a grep. Might be nicer as for.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually... should that be a /e? It seems like perl-evaluating the env var isn't right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a map not grep, will update the branch.

print "% $cmd @ARGV\n";
if($cmd eq 'mkdir') { mkdir shift }
elsif($cmd eq 'touch') { open my $fh, '>', shift; close $fh; }
elsif($cmd eq 'copy') { copy shift, shift }
EOF
close $fh;

my $destdir = File::Temp->newdir;

mkdir 'src';
open $fh, '>', 'src/foo.tar.gz';
print $fh unpack("u",
q{M'XL(`%)-#E0``TO+S]=GH#$P,#`P-S55`-*&YJ8&R#0<*!@:F1@8FYB8F1J:} .
q{M*A@`.>:&#`JFM'88")06ER06`9V2GY.369R.6QTA>:@_X/00`6G`^-=+K<@L} .
q{L+BFFF1W`\#`S,2$E_HW-S<T9%`QHYB(D,,+C?Q2,@E$P<@$`7EO"E``(````}
);
close $fh;

my $builder = builder(
alien_name => 'foobarbazfakething',
alien_build_commands => [
"$^X $CWD/build.pl mkdir bin",
"$^X $CWD/build.pl touch bin/foo",
],
alien_install_commands => [
"$^X $CWD/build.pl mkdir DESTDIR/%s/bin",
"$^X $CWD/build.pl copy bin/foo DESTDIR/%s/bin/foo",
],
alien_repository => {
protocol => 'local',
location => 'src',
},
);

my $share = $builder->alien_library_destination;

$builder->depends_on('build');

$builder->destdir($destdir);
is $builder->destdir, $destdir, "destdir accessor";

$builder->depends_on('install');

my $foo_script = File::Spec->catfile($destdir, $share, 'bin', 'foo');
ok -e $foo_script, "script installed in destdir $foo_script";

unlink 'build.pl';
rmtree [qw/ _alien _share blib src /], 0, 0;
};

done_testing;