1 package MakeMaker::Test::Utils;
7 use vars qw($VERSION @ISA @EXPORT);
14 @EXPORT = qw(which_perl perl_lib makefile_name makefile_backup
15 make make_run run make_macro calibrate_mtime
18 my $Is_VMS = $^O eq 'VMS';
19 my $Is_MacOS = $^O eq 'MacOS';
24 MakeMaker::Test::Utils - Utility routines for testing MakeMaker
28 use MakeMaker::Test::Utils;
30 my $perl = which_perl;
33 my $makefile = makefile_name;
34 my $makefile_back = makefile_backup;
37 my $make_run = make_run;
38 make_macro($make, $targ, %macros);
40 my $mtime = calibrate_mtime;
46 A consolidation of little utility functions used through out the
51 The following are exported by default.
57 my $perl = which_perl;
59 Returns a path to perl which is safe to use in a command line, no
60 matter where you chdir to.
68 # VMS should have 'perl' aliased properly
69 return $perl if $Is_VMS;
71 $perl .= $Config{exe_ext} unless $perl =~ m/$Config{exe_ext}$/i;
73 my $perlpath = File::Spec->rel2abs( $perl );
74 unless( $Is_MacOS || -x $perlpath ) {
75 # $^X was probably 'perl'
77 # When building in the core, *don't* go off and find
79 die "Can't find a perl to use (\$^X=$^X), (\$perlpath=$perlpath)"
82 foreach my $path (File::Spec->path) {
83 $perlpath = File::Spec->catfile($path, $perl);
95 Sets up environment variables so perl can find its libraries.
99 my $old5lib = $ENV{PERL5LIB};
100 my $had5lib = exists $ENV{PERL5LIB};
103 my $lib = $ENV{PERL_CORE} ? qq{../lib}
104 # ExtUtils-MakeMaker/t/
106 $lib = File::Spec->rel2abs($lib);
108 push @libs, $ENV{PERL5LIB} if exists $ENV{PERL5LIB};
109 $ENV{PERL5LIB} = join($Config{path_sep}, @libs);
115 $ENV{PERL5LIB} = $old5lib;
118 delete $ENV{PERL5LIB};
123 =item B<makefile_name>
125 my $makefile = makefile_name;
127 MakeMaker doesn't always generate 'Makefile'. It returns what it
133 return $Is_VMS ? 'Descrip.MMS' : 'Makefile';
136 =item B<makefile_backup>
138 my $makefile_old = makefile_backup;
140 Returns the name MakeMaker will use for a backup of the current
145 sub makefile_backup {
146 my $makefile = makefile_name;
147 return $Is_VMS ? $makefile : "$makefile.old";
154 Returns a good guess at the make to run.
159 my $make = $Config{make};
160 $make = $ENV{MAKE} if exists $ENV{MAKE};
167 my $make_run = make_run;
169 Returns the make to run as with make() plus any necessary switches.
175 $make .= ' -nologo' if $make eq 'nmake';
182 my $make_cmd = make_macro($make, $target, %macros);
184 Returns the command necessary to run $make on the given $target using
187 my $make_test_verbose = make_macro(make_run(), 'test',
190 This is important because VMS's make utilities have a completely
191 different calling convention than Unix or Windows.
193 %macros is actually a list of tuples, so the order will be preserved.
198 my($make, $target) = (shift, shift);
200 my $is_mms = $make =~ /^MM(K|S)/i;
204 while( my($key,$val) = splice(@_, 0, 2) ) {
206 $macros .= qq{/macro="$key=$val"};
209 $macros .= qq{ $key=$val};
213 return $is_mms ? "$make$macros $target" : "$make $target $macros";
216 =item B<calibrate_mtime>
218 my $mtime = calibrate_mtime;
220 When building on NFS, file modification times can often lose touch
221 with reality. This returns the mtime of a file which has just been
226 sub calibrate_mtime {
227 open(FILE, ">calibrate_mtime.tmp") || die $!;
230 my($mtime) = (stat('calibrate_mtime.tmp'))[9];
231 unlink 'calibrate_mtime.tmp';
237 my $out = run($command);
238 my @out = run($command);
240 Runs the given $command as an external program returning at least STDOUT
241 as $out. If possible it will return STDOUT and STDERR combined as you
242 would expect to see on a screen.
249 require ExtUtils::MM;
251 # Unix can handle 2>&1 and OS/2 from 5.005_54 up.
252 # This makes our failure diagnostics nicer to read.
253 if( MM->os_flavor_is('Unix') or
254 ($] > 5.00554 and MM->os_flavor_is('OS/2'))
267 Michael G Schwern <schwern@pobox.com>