Skip to content

Commit f2221ea

Browse files
committed
Add sharedir support
1 parent c932f50 commit f2221ea

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
@@ -1851,7 +1851,7 @@ sub special_targets {
18511851
my $make_frag = <<'MAKE_FRAG';
18521852
.SUFFIXES : .xs .c .C .cpp .i .s .cxx .cc $(OBJ_EXT)
18531853
1854-
.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
1854+
.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
18551855
18561856
MAKE_FRAG
18571857

@@ -2968,6 +2968,36 @@ sub postamble {
29682968
"";
29692969
}
29702970

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

lib/ExtUtils/MakeMaker.pm

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ my %Special_Sigs = (
128128
macro => 'HASH',
129129
postamble => 'HASH',
130130
realclean => 'HASH',
131+
sharedir => 'HASH',
131132
test => 'HASH',
132133
tool_autosplit => 'HASH',
133134
);
@@ -350,7 +351,7 @@ sub full_setup {
350351
makemakerdflt
351352
352353
dist macro depend cflags const_loadlibs const_cccmd
353-
post_constants
354+
post_constants sharedir
354355
355356
pasthru
356357
@@ -3048,6 +3049,16 @@ L<MY::postamble()|ExtUtils::MM_Any/postamble (o)> if you have one.
30483049
30493050
{FILES => '$(INST_ARCHAUTODIR)/*.xyz'}
30503051
3052+
=item sharedir
3053+
3054+
This sets the sharedirs to install.
3055+
3056+
{dist => 'share', module => { Foo => 'foo', ... }}
3057+
3058+
The C<dist> key sets the source for the dist specific sharedir content. The
3059+
C<module> key is a hash mapping module names to their specific sharedir. The
3060+
keys C<skip_dotdir> and C<skip_dotfile> will make it skip dot-directories
3061+
30513062
=item test
30523063
30533064
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)