📄 mm.pm
字号:
# qq[\$OUTPUT_AUTOFLUSH++,do(q($makefile_pl))] # ) # . $mmflags; # my $flush = OPT_AUTOFLUSH; # my $cmd = "$perl $flush $makefile_pl $mmflags"; my $run_perl = $conf->get_program('perlwrapper'); my $cmd = "$perl $run_perl $makefile_pl $mmflags"; ### set ENV var to tell underlying code this is what we're ### executing. my $captured; my $rv = do { my $env = ENV_CPANPLUS_IS_EXECUTING; local $ENV{$env} = $makefile_pl; scalar run( command => $cmd, buffer => \$captured, verbose => $run_verbose, # may be interactive ); }; unless( $rv ) { error( loc( "Could not run '%1 %2': %3 -- cannot continue", $perl, MAKEFILE_PL->(), $captured ) ); $dist->status->makefile(0); $fail++; last RUN; } ### put the output on the stack, don't print it msg( $captured, 0 ); } ### so, nasty feature in Module::Build, that when a Makefile.PL ### is a disguised Build.PL, it generates a Build file, not a ### Makefile. this breaks everything :( see rt bug #19741 if( not -e MAKEFILE->( $dir ) and -e BUILD_PL->( $dir ) ) { error(loc( "We just ran '%1' without errors, but no '%2' is ". "present. However, there is a '%3' file, so this may ". "be related to bug #19741 in %4, which describes a ". "fake '%5' which generates a '%6' file instead of a '%7'. ". "You could try to work around this issue by setting '%8' ". "to false and trying again. This will attempt to use the ". "'%9' instead.", "$^X ".MAKEFILE_PL->(), MAKEFILE->(), BUILD_PL->(), 'Module::Build', MAKEFILE_PL->(), 'Build', MAKEFILE->(), 'prefer_makefile', BUILD_PL->() )); $fail++, last RUN; } ### if we got here, we managed to make a 'makefile' ### $dist->status->makefile( MAKEFILE->($dir) ); ### start resolving prereqs ### my $prereqs = $self->status->prereqs; ### a hashref of prereqs on success, undef on failure ### $prereqs ||= $dist->_find_prereqs( verbose => $verbose, file => $dist->status->makefile ); unless( $prereqs ) { error( loc( "Unable to scan '%1' for prereqs", $dist->status->makefile ) ); $fail++; last RUN; } } unless( $cb->_chdir( dir => $orig ) ) { error( loc( "Could not chdir back to start dir '%1'", $orig ) ); } ### save where we wrote this stuff -- same as extract dir in normal ### installer circumstances $dist->status->distdir( $self->status->extract ); return $dist->status->prepared( $fail ? 0 : 1);}=pod=head2 $href = $dist->_find_prereqs( file => '/path/to/Makefile', [verbose => BOOL])Parses a C<Makefile> for C<PREREQ_PM> entries and distills from thatany prerequisites mentioned in the C<Makefile>Returns a hash with module-version pairs on success and false onfailure.=cutsub _find_prereqs { my $dist = shift; my $self = $dist->parent; my $cb = $self->parent; my $conf = $cb->configure_object; my %hash = @_; my ($verbose, $file); my $tmpl = { verbose => { default => $conf->get_conf('verbose'), store => \$verbose }, file => { required => 1, allow => FILE_READABLE, store => \$file }, }; my $args = check( $tmpl, \%hash ) or return; my $fh = FileHandle->new(); unless( $fh->open( $file ) ) { error( loc( "Cannot open '%1': %2", $file, $! ) ); return; } my %p; while( <$fh> ) { my ($found) = m|^[\#]\s+PREREQ_PM\s+=>\s+(.+)|; next unless $found; while( $found =~ m/(?:\s)([\w\:]+)=>(?:q\[(.*?)\],?|undef)/g ) { if( defined $p{$1} ) { msg(loc("Warning: PREREQ_PM mentions '%1' more than once. " . "Last mention wins.", $1 ), $verbose ); } $p{$1} = $cb->_version_to_number(version => $2); } last; } my $href = $cb->_callbacks->filter_prereqs->( $cb, \%p ); $self->status->prereqs( $href ); ### just to make sure it's not the same reference ### return { %$href }; } =pod=head2 $bool = $dist->create([perl => '/path/to/perl', make => '/path/to/make', makeflags => 'EXTRA=FLAGS', prereq_target => TARGET, skiptest => BOOL, force => BOOL, verbose => BOOL])C<create> creates the files necessary for installation. This means it will run C<make> and C<make test>. This will also scan for and attempt to satisfy any prerequisites the module may have. If you set C<skiptest> to true, it will skip the C<make test> stage.If you set C<force> to true, it will go over all the stages of the C<make> process again, ignoring any previously cached results. It will also ignore a bad return value from C<make test> and still allow the operation to return true.Returns true on success and false on failure.You may then call C<< $dist->install >> on the object to actuallyinstall it.=cutsub create { ### just in case you already did a create call for this module object ### just via a different dist object my $dist = shift; my $self = $dist->parent; ### we're also the cpan_dist, since we don't need to have anything ### prepared $dist = $self->status->dist_cpan if $self->status->dist_cpan; $self->status->dist_cpan( $dist ) unless $self->status->dist_cpan; my $cb = $self->parent; my $conf = $cb->configure_object; my %hash = @_; my $dir; unless( $dir = $self->status->extract ) { error( loc( "No dir found to operate on!" ) ); return; } my $args; my( $force, $verbose, $make, $makeflags, $skiptest, $prereq_target, $perl, $mmflags, $prereq_format, $prereq_build); { local $Params::Check::ALLOW_UNKNOWN = 1; my $tmpl = { perl => { default => $^X, store => \$perl }, force => { default => $conf->get_conf('force'), store => \$force }, verbose => { default => $conf->get_conf('verbose'), store => \$verbose }, make => { default => $conf->get_program('make'), store => \$make }, makeflags => { default => $conf->get_conf('makeflags'), store => \$makeflags }, skiptest => { default => $conf->get_conf('skiptest'), store => \$skiptest }, prereq_target => { default => '', store => \$prereq_target }, ### don't set the default prereq format to 'makemaker' -- wrong! prereq_format => { #default => $self->status->installer_type, default => '', store => \$prereq_format }, prereq_build => { default => 0, store => \$prereq_build }, }; $args = check( $tmpl, \%hash ) or return; } ### maybe we already ran a create on this object? ### return 1 if $dist->status->created && !$force; ### store the arguments, so ->install can use them in recursive loops ### $dist->status->_create_args( $args ); unless( $dist->status->prepared ) { error( loc( "You have not successfully prepared a '%2' distribution ". "yet -- cannot create yet", __PACKAGE__ ) ); return; } ### chdir to work directory ### my $orig = cwd(); unless( $cb->_chdir( dir => $dir ) ) { error( loc( "Could not chdir to build directory '%1'", $dir ) ); return; } my $fail; my $prereq_fail; my $test_fail; RUN: { ### this will set the directory back to the start ### dir, so we must chdir /again/ my $ok = $dist->_resolve_prereqs( format => $prereq_format, verbose => $verbose, prereqs => $self->status->prereqs, target => $prereq_target, force => $force, prereq_build => $prereq_build, ); unless( $cb->_chdir( dir => $dir ) ) { error( loc( "Could not chdir to build directory '%1'", $dir ) ); return; } unless( $ok ) { #### use $dist->flush to reset the cache ### error( loc( "Unable to satisfy prerequisites for '%1' " . "-- aborting install", $self->module ) ); $dist->status->make(0); $fail++; $prereq_fail++; last RUN; } ### end of prereq resolving ### my $captured; ### 'make' section ### if( -d BLIB->($dir) && (-M BLIB->($dir) < -M $dir) && !$force ) { msg(loc("Already ran '%1' for this module [%2] -- " . "not running again unless you force", $make, $self->module ), $verbose ); } else { unless(scalar run( command => [$make, $makeflags], buffer => \$captured, verbose => $verbose ) ) { error( loc( "MAKE failed: %1 %2", $!, $captured ) ); $dist->status->make(0); $fail++; last RUN; } ### put the output on the stack, don't print it msg( $captured, 0 ); $dist->status->make(1); ### add this directory to your lib ### $self->add_to_includepath(); ### dont bail out here, there's a conditional later on #last RUN if $skiptest; } ### 'make test' section ### unless( $skiptest ) { ### turn off our PERL5OPT so no modules from CPANPLUS::inc get ### included in make test -- it should build without ### also, modules that run in taint mode break if we leave ### our code ref in perl5opt ### XXX CPANPLUS::inc functionality is now obsolete. #local $ENV{PERL5OPT} = CPANPLUS::inc->original_perl5opt || ''; ### you can turn off running this verbose by changing ### the config setting below, although it is really not ### recommended my $run_verbose = $verbose || $conf->get_conf('allow_build_interactivity') || 0; ### XXX need to add makeflags here too? ### yes, but they should really be split out -- see bug #4143 if( scalar run( command => [$make, 'test', $makeflags], buffer => \$captured, verbose => $run_verbose, ) ) { ### tests might pass because it doesn't have any tests defined ### log this occasion non-verbosely, so our test reporter can ### pick up on this if ( NO_TESTS_DEFINED->( $captured ) ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -