Skip to content

Commit 500977e

Browse files
committed
Add sharedir support
1 parent 694b7c7 commit 500977e

File tree

3 files changed

+142
-2
lines changed

3 files changed

+142
-2
lines changed

lib/ExtUtils/MM_Any.pm

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1852,7 +1852,7 @@ sub special_targets {
18521852
my $make_frag = <<'MAKE_FRAG';
18531853
.SUFFIXES : .xs .c .C .cpp .i .s .cxx .cc $(OBJ_EXT)
18541854
1855-
.PHONY: all config static dynamic test linkext manifest blibdirs clean realclean disttest distdir pure_all subdirs clean_subdirs makemakerdflt manifypods realclean_subdirs subdirs_dynamic subdirs_pure_nolink subdirs_static subdirs-test_dynamic subdirs-test_static test_dynamic test_static
1855+
.PHONY: all config static dynamic test linkext manifest blibdirs clean realclean disttest distdir pure_all subdirs clean_subdirs makemakerdflt manifypods realclean_subdirs subdirs_dynamic subdirs_pure_nolink subdirs_static subdirs-test_dynamic subdirs-test_static test_dynamic test_static sharedir
18561856
18571857
MAKE_FRAG
18581858

@@ -2969,6 +2969,36 @@ sub postamble {
29692969
"";
29702970
}
29712971

2972+
sub sharedir {
2973+
my ($self, %share) = @_;
2974+
return '' unless %share;
2975+
2976+
my %files;
2977+
_sharedir_find_files(\%files, $share{dist}, File::Spec->catdir('$(INST_LIB)', qw(auto share dist), '$(DISTNAME)'), \%share) if $share{dist};
2978+
for my $module (keys %{ $share{module} || {} }) {
2979+
my $destination = File::Spec->catdir('$(INST_LIB)', qw(auto share module), $module);
2980+
_sharedir_find_files(\%files, $share{module}{$module}, $destination, \%share);
2981+
}
2982+
my $pm_to_blib = $self->oneliner(q{pm_to_blib({@ARGV}, '$(INST_LIB)')}, ['-MExtUtils::Install']);
2983+
return "\npure_all :: sharedir\n\nsharedir : \n" . join '', map { "\t\$(NOECHO) $_\n" } $self->split_command($pm_to_blib, %files);
2984+
}
2985+
2986+
sub _sharedir_find_files {
2987+
my ($files, $source, $sink, $options) = @_;
2988+
File::Find::find({
2989+
wanted => sub {
2990+
if (-d) {
2991+
$File::Find::prune = 1 if $options->{skip_dotdir} && /^\./;
2992+
return;
2993+
}
2994+
return if $options->{skip_dotfile} && /^\./;
2995+
$files->{$_} = File::Spec->catfile($sink, $_);
2996+
},
2997+
no_chdir => 1,
2998+
}, $source);
2999+
return;
3000+
}
3001+
29723002
=begin private
29733003
29743004
=head3 _PREREQ_PRINT

lib/ExtUtils/MakeMaker.pm

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ my %Special_Sigs = (
129129
macro => 'HASH',
130130
postamble => 'HASH',
131131
realclean => 'HASH',
132+
sharedir => 'HASH',
132133
test => 'HASH',
133134
tool_autosplit => 'HASH',
134135
);
@@ -351,7 +352,7 @@ sub full_setup {
351352
makemakerdflt
352353
353354
dist macro depend cflags const_loadlibs const_cccmd
354-
post_constants
355+
post_constants sharedir
355356
356357
pasthru
357358
@@ -3033,6 +3034,16 @@ L<MY::postamble()|ExtUtils::MM_Any/postamble (o)> if you have one.
30333034
30343035
{FILES => '$(INST_ARCHAUTODIR)/*.xyz'}
30353036
3037+
=item sharedir
3038+
3039+
This sets the sharedirs to install.
3040+
3041+
{dist => 'share', module => { Foo => 'foo', ... }}
3042+
3043+
The C<dist> key sets the source for the dist specific sharedir content. The
3044+
C<module> key is a hash mapping module names to their specific sharedir. The
3045+
keys C<skip_dotdir> and C<skip_dotfile> will make it skip dot-directories
3046+
30363047
=item test
30373048
30383049
Specify the targets for testing.

t/sharedir.t

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
use strict;
2+
use warnings;
3+
4+
use Test::More tests => 6;
5+
use File::Temp 'tempdir';
6+
7+
use File::Spec::Functions qw/catfile catdir/;
8+
use File::Path 'mkpath';
9+
use Cwd 'cwd';
10+
11+
use IPC::Open3;
12+
use Symbol 'gensym';
13+
use Env qw(@PERL5LIB $PERL_MM_OPT);
14+
15+
# ABSTRACT: Test basic behaviour
16+
17+
my $install = tempdir();
18+
my $pwd = cwd;
19+
20+
# Make sure install target is prepped.
21+
unshift @PERL5LIB, $install, catdir($pwd, 'lib');
22+
$PERL_MM_OPT = "INSTALL_BASE=$install";
23+
24+
# Prep the source tree
25+
my $source = tempdir();
26+
27+
mkdir catdir($source, 'lib');
28+
spew(catfile($source, 'lib', 'TestDist.pm'), "package TestDist;\n\$VERSION = '1.000';\n1;\n");
29+
30+
my $share = catdir($source, 'share');
31+
my $dotdir = catdir($share, qw/dots .dotdir/);
32+
33+
mkpath($dotdir);
34+
spew(catfile($dotdir, 'normalfile'), 'This is a normal file');
35+
spew(catfile($dotdir, '.dotfile'), 'This is a dotfile');
36+
spew(catfile($share, 'dots', '.dotfile'), 'This is a dotfile');
37+
spew(catfile($share, 'normalfile'), 'This is a normal file');
38+
39+
spew(catfile($source, 'Makefile.PL'), <<'MAKEFILE');
40+
use strict;
41+
use warnings;
42+
43+
use ExtUtils::MakeMaker;
44+
45+
my %Args = (
46+
ABSTRACT => "Test Module",
47+
DISTNAME => "TestDist",
48+
NAME => "TestDist",
49+
PREREQ_PM => {},
50+
sharedir => {
51+
dist => 'share',
52+
},
53+
);
54+
55+
WriteMakefile(%Args);
56+
57+
MAKEFILE
58+
59+
chdir $source;
60+
END { chdir $pwd }
61+
62+
sub run_ok {
63+
my (@command) = @_;
64+
my $desc = join ' ', @command;
65+
local $Test::Builder::Level = $Test::Builder::Level + 1;
66+
67+
my ($inh, $outh, $errh) = (undef, undef, gensym);
68+
my $pid = open3($inh, $outh, $errh, @command) or do {
69+
fail "Command $desc: $!";
70+
return;
71+
};
72+
close $inh;
73+
74+
my $out = do { local $/; <$outh> };
75+
my $err = do { local $/; <$errh> };
76+
77+
waitpid $pid, 0 or die 'Couldn\'t waitpid';
78+
return cmp_ok( $?, '==', 0, "Command $desc" ) || note explain { 'stdout' => $out, 'stderr' => $err, exit => $? }
79+
}
80+
81+
# Testing happens here:
82+
SKIP: {
83+
run_ok($^X, 'Makefile.PL');
84+
run_ok('make');
85+
run_ok('make', 'install');
86+
87+
my $dir = catdir($install, qw/lib perl5 auto share dist TestDist share/);
88+
ok(-d $dir, 'Sharedir has been created');
89+
ok(-e catfile($dir, 'normalfile'), 'File in sharedir has been created');
90+
ok(-e catfile($dir, qw/dots .dotdir .dotfile/), 'A dotfile in a dotdir installed');
91+
}
92+
93+
sub spew {
94+
my ($filename, $content) = @_;
95+
open my $fh, '>', $filename or die "Couldn't open $filename: $!";
96+
print $fh $content or die "Couldn't write to $filename: $!";
97+
close $fh or die "Couldn't close $filename: $!";
98+
return;
99+
}

0 commit comments

Comments
 (0)