This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add CPANPLUS::Dist::Build to the core
[perl5.git] / lib / CPANPLUS / Dist / Build / t / inc / conf.pl
CommitLineData
9b4bd854
JB
1### XXX copied from cpanplus's t/inc/conf.pl
2BEGIN {
3 use FindBin;
4 use File::Spec;
5
6 ### paths to our own 'lib' and 'inc' dirs
7 ### include them, relative from t/
8 my @paths = map { "$FindBin::Bin/$_" } qw[../lib inc];
9
10 ### absolute'ify the paths in @INC;
11 my @rel2abs = map { File::Spec->rel2abs( $_ ) }
12 grep { not File::Spec->file_name_is_absolute( $_ ) } @INC;
13
14 ### use require to make devel::cover happy
15 require lib;
16 for ( @paths, @rel2abs ) {
17 my $l = 'lib';
18 $l->import( $_ )
19 }
20
21 use Config;
22
23 ### and add them to the environment, so shellouts get them
24 $ENV{'PERL5LIB'} = join ':',
25 grep { defined } $ENV{'PERL5LIB'}, @paths, @rel2abs;
26
27 ### add our own path to the front of $ENV{PATH}, so that cpanp-run-perl
28 ### and friends get picked up
29 $ENV{'PATH'} = join $Config{'path_sep'},
30 grep { defined } "$FindBin::Bin/../../../bin", $ENV{'PATH'};
31
32 ### Fix up the path to perl, as we're about to chdir
33 ### but only under perlcore, or if the path contains delimiters,
34 ### meaning it's relative, but not looked up in your $PATH
35 $^X = File::Spec->rel2abs( $^X )
36 if $ENV{PERL_CORE} or ( $^X =~ m|[/\\]| );
37
38 ### chdir to our own test dir, so we know all files are relative
39 ### to this point, no matter whether run from perlcore tests or
40 ### regular CPAN installs
41 chdir "$FindBin::Bin" if -d "$FindBin::Bin"
42}
43
44BEGIN {
45 use IPC::Cmd;
46
47 ### Win32 has issues with redirecting FD's properly in IPC::Run:
48 ### Can't redirect fd #4 on Win32 at IPC/Run.pm line 2801
49 $IPC::Cmd::USE_IPC_RUN = 0 if $^O eq 'MSWin32';
50 $IPC::Cmd::USE_IPC_RUN = 0 if $^O eq 'MSWin32';
51}
52
53use strict;
54use CPANPLUS::Configure;
55
56use File::Path qw[rmtree];
57use FileHandle;
58use File::Basename qw[basename];
59
60{ ### Force the ignoring of .po files for L::M::S
61 $INC{'Locale::Maketext::Lexicon.pm'} = __FILE__;
62 $Locale::Maketext::Lexicon::VERSION = 0;
63}
64
651;
66
67__END__
68
69# prereq has to be in our package file && core!
70use constant TEST_CONF_PREREQ => 'Cwd';
71use constant TEST_CONF_MODULE => 'Foo::Bar::EU::NOXS';
72use constant TEST_CONF_INST_MODULE => 'Foo::Bar';
73use constant TEST_CONF_INVALID_MODULE => 'fnurk';
74use constant TEST_CONF_MIRROR_DIR => 'dummy-localmirror';
75
76### we might need this Some Day when we're installing into
77### our own sandbox. see t/20.t for details
78# use constant TEST_INSTALL_DIR => do {
79# my $dir = File::Spec->rel2abs( 'dummy-perl' );
80#
81# ### clean up paths if we are on win32
82# ### dirs with spaces will be.. bad :(
83# $^O eq 'MSWin32'
84# ? Win32::GetShortPathName( $dir )
85# : $dir;
86# };
87
88# use constant TEST_INSTALL_DIR_LIB
89# => File::Spec->catdir( TEST_INSTALL_DIR, 'lib' );
90# use constant TEST_INSTALL_DIR_BIN
91# => File::Spec->catdir( TEST_INSTALL_DIR, 'bin' );
92# use constant TEST_INSTALL_DIR_MAN1
93# => File::Spec->catdir( TEST_INSTALL_DIR, 'man', 'man1' );
94# use constant TEST_INSTALL_DIR_MAN3
95# => File::Spec->catdir( TEST_INSTALL_DIR, 'man', 'man3' );
96# use constant TEST_INSTALL_DIR_ARCH
97# => File::Spec->catdir( TEST_INSTALL_DIR, 'arch' );
98#
99# use constant TEST_INSTALL_EU_MM_FLAGS =>
100# ' INSTALLDIRS=site' .
101# ' INSTALLSITELIB=' . TEST_INSTALL_DIR_LIB .
102# ' INSTALLSITEARCH=' . TEST_INSTALL_DIR_ARCH . # .packlist
103# ' INSTALLARCHLIB=' . TEST_INSTALL_DIR_ARCH . # perllocal.pod
104# ' INSTALLSITEBIN=' . TEST_INSTALL_DIR_BIN .
105# ' INSTALLSCRIPT=' . TEST_INSTALL_DIR_BIN .
106# ' INSTALLSITEMAN1DIR=' . TEST_INSTALL_DIR_MAN1 .
107# ' INSTALLSITEMAN3DIR=' . TEST_INSTALL_DIR_MAN3;
108
109
110sub gimme_conf {
111 my $conf = CPANPLUS::Configure->new();
112 $conf->set_conf( hosts => [ {
113 path => 'dummy-CPAN',
114 scheme => 'file',
115 } ],
116 );
117 $conf->set_conf( base => 'dummy-cpanplus' );
118 $conf->set_conf( dist_type => '' );
119 $conf->set_conf( signature => 0 );
120
121 _clean_test_dir( [
122 $conf->get_conf('base'),
123 TEST_CONF_MIRROR_DIR,
124# TEST_INSTALL_DIR_LIB,
125# TEST_INSTALL_DIR_BIN,
126# TEST_INSTALL_DIR_MAN1,
127# TEST_INSTALL_DIR_MAN3,
128 ], 1 );
129
130 return $conf;
131};
132
133{
134 my $fh;
135 my $file = ".".basename($0).".output";
136 sub output_handle {
137 return $fh if $fh;
138
139 $fh = FileHandle->new(">$file")
140 or warn "Could not open output file '$file': $!";
141
142 $fh->autoflush(1);
143 return $fh;
144 }
145
146 sub output_file { return $file }
147}
148
149
150### clean these files if we're under perl core
151END {
152 if ( $ENV{PERL_CORE} ) {
153 close output_handle(); 1 while unlink output_file();
154
155 _clean_test_dir( [
156 gimme_conf->get_conf('base'),
157 TEST_CONF_MIRROR_DIR,
158 # TEST_INSTALL_DIR_LIB,
159 # TEST_INSTALL_DIR_BIN,
160 # TEST_INSTALL_DIR_MAN1,
161 # TEST_INSTALL_DIR_MAN3,
162 ], 1 );
163 }
164}
165
166
167
168### whenever we start a new script, we want to clean out our
169### old files from the test '.cpanplus' dir..
170sub _clean_test_dir {
171 my $dirs = shift || [];
172 my $verbose = shift || 0;
173
174 for my $dir ( @$dirs ) {
175
176 my $dh;
177 opendir $dh, $dir or die "Could not open basedir '$dir': $!";
178 while( my $file = readdir $dh ) {
179 next if $file =~ /^\./; # skip dot files
180
181 my $path = File::Spec->catfile( $dir, $file );
182
183 ### directory, rmtree it
184 if( -d $path ) {
185 print "Deleting directory '$path'\n" if $verbose;
186 eval { rmtree( $path ) };
187 warn "Could not delete '$path' while cleaning up '$dir'" if $@;
188
189 ### regular file
190 } else {
191 print "Deleting file '$path'\n" if $verbose;
192 1 while unlink $path;
193 }
194 }
195
196 close $dh;
197 }
198
199 return 1;
200}
2011;