Skip to content

Commit

Permalink
Add sharedir support
Browse files Browse the repository at this point in the history
  • Loading branch information
Leont committed Apr 19, 2015
1 parent 3a3a7c8 commit 2f795f4
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 2 deletions.
32 changes: 31 additions & 1 deletion lib/ExtUtils/MM_Any.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,7 @@ sub special_targets {
my $make_frag = <<'MAKE_FRAG';
.SUFFIXES : .xs .c .C .cpp .i .s .cxx .cc $(OBJ_EXT)
.PHONY: all config static dynamic test linkext manifest blibdirs clean realclean disttest distdir
.PHONY: all config static dynamic test linkext manifest blibdirs clean realclean disttest distdir sharedir
MAKE_FRAG

Expand Down Expand Up @@ -2950,6 +2950,36 @@ sub postamble {
"";
}

sub sharedir {
my ($self, %share) = @_;
return '' unless %share;

my %files;
_sharedir_find_files(\%files, $share{dist}, File::Spec->catdir('$(INST_LIB)', qw(auto share dist), '$(DISTNAME)'), \%share) if $share{dist};
for my $module (keys %{ $share{module} || {} }) {
my $destination = File::Spec->catdir('$(INST_LIB)', qw(auto share module), $module);
_sharedir_find_files(\%files, $share{module}{$module}, $destination, \%share);
}
my $pm_to_blib = $self->oneliner(q{pm_to_blib({@ARGV}, '$(INST_LIB)')}, ['-MExtUtils::Install']);
return "\npure_all :: sharedir\n\nsharedir : \n" . join '', map { "\t\$(NOECHO) $_\n" } $self->split_command($pm_to_blib, %files);
}

sub _sharedir_find_files {
my ($files, $source, $sink, $options) = @_;
File::Find::find({
wanted => sub {
if (-d) {
$File::Find::prune = 1 if $options->{skip_dotdir} && /^\./;
return;
}
return if $options->{skip_dotfile} && /^\./;
$files->{$_} = File::Spec->catfile($sink, $_);
},
no_chdir => 1,
}, $source);
return;
}

=begin private
=head3 _PREREQ_PRINT
Expand Down
13 changes: 12 additions & 1 deletion lib/ExtUtils/MakeMaker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ my %Special_Sigs = (
macro => 'HASH',
postamble => 'HASH',
realclean => 'HASH',
sharedir => 'HASH',
test => 'HASH',
tool_autosplit => 'HASH',
);
Expand Down Expand Up @@ -345,7 +346,7 @@ sub full_setup {
makemakerdflt
dist macro depend cflags const_loadlibs const_cccmd
post_constants
post_constants sharedir
pasthru
Expand Down Expand Up @@ -2945,6 +2946,16 @@ Anything put here will be passed to MY::postamble() if you have one.
{FILES => '$(INST_ARCHAUTODIR)/*.xyz'}
=item sharedir
This sets the sharedirs to install.
{dist => 'share', module => { Foo => 'foo', ... }}
The C<dist> key sets the source for the dist specific sharedir content. The
C<module> key is a hash mapping module names to their specific sharedir. The
keys C<skip_dotdir> and C<skip_dotfile> will make it skip dot-directories
=item test
Specify the targets for testing.
Expand Down
99 changes: 99 additions & 0 deletions t/sharedir.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
use strict;
use warnings;

use Test::More tests => 6;
use File::Temp 'tempdir';

use File::Spec::Functions qw/catfile catdir/;
use File::Path 'mkpath';
use Cwd 'cwd';

use IPC::Open3;
use Symbol 'gensym';
use Env qw(@PERL5LIB $PERL_MM_OPT);

# ABSTRACT: Test basic behaviour

my $install = tempdir();
my $pwd = cwd;

# Make sure install target is prepped.
unshift @PERL5LIB, $install, catdir($pwd, 'lib');
$PERL_MM_OPT = "INSTALL_BASE=$install";

# Prep the source tree
my $source = tempdir();

mkdir catdir($source, 'lib');
spew(catfile($source, 'lib', 'TestDist.pm'), "package TestDist;\n\$VERSION = '1.000';\n1;\n");

my $share = catdir($source, 'share');
my $dotdir = catdir($share, qw/dots .dotdir/);

mkpath($dotdir);
spew(catfile($dotdir, 'normalfile'), 'This is a normal file');
spew(catfile($dotdir, '.dotfile'), 'This is a dotfile');
spew(catfile($share, 'dots', '.dotfile'), 'This is a dotfile');
spew(catfile($share, 'normalfile'), 'This is a normal file');

spew(catfile($source, 'Makefile.PL'), <<'MAKEFILE');
use strict;
use warnings;
use ExtUtils::MakeMaker;
my %Args = (
ABSTRACT => "Test Module",
DISTNAME => "TestDist",
NAME => "TestDist",
PREREQ_PM => {},
sharedir => {
dist => 'share',
},
);
WriteMakefile(%Args);
MAKEFILE

chdir $source;
END { chdir $pwd }

sub run_ok {
my (@command) = @_;
my $desc = join ' ', @command;
local $Test::Builder::Level = $Test::Builder::Level + 1;

my ($inh, $outh, $errh) = (undef, undef, gensym);
my $pid = open3($inh, $outh, $errh, @command) or do {
fail "Command $desc: $!";
return;
};
close $inh;

my $out = do { local $/; <$outh> };
my $err = do { local $/; <$errh> };

waitpid $pid, 0 or die 'Couldn\'t waitpid';
return cmp_ok( $?, '==', 0, "Command $desc" ) || note explain { 'stdout' => $out, 'stderr' => $err, exit => $? }
}

# Testing happens here:
SKIP: {
run_ok($^X, 'Makefile.PL');
run_ok('make');
run_ok('make', 'install');

my $dir = catdir($install, qw/lib perl5 auto share dist TestDist share/);
ok(-d $dir, 'Sharedir has been created');
ok(-e catfile($dir, 'normalfile'), 'File in sharedir has been created');
ok(-e catfile($dir, qw/dots .dotdir .dotfile/), 'A dotfile in a dotdir installed');
}

sub spew {
my ($filename, $content) = @_;
open my $fh, '>', $filename or die "Couldn't open $filename: $!";
print $fh $content or die "Couldn't write to $filename: $!";
close $fh or die "Couldn't close $filename: $!";
return;
}

0 comments on commit 2f795f4

Please sign in to comment.