Re: [Module-build-general] Article on perl.com
Status: Beta
Brought to you by:
kwilliams
|
From: Dave R. <au...@ur...> - 2003-02-13 18:49:01
|
On Thu, 13 Feb 2003, Andreas J. Koenig wrote: > Please send me your patch to CPAN.pm that supports Build.PL. I cannot > promise that I can work on it (tuits, tuits!), but I'll at least > consider doing it. Doh, I forgot the patch. Also, I wanted to point out that it is smart enough to try to install Module::Build if it sees a Build.PL file in the distro. /*======================= House Absolute Consulting www.houseabsolute.com =======================*/ Only in .: cpan-patch diff -ur ../CPAN-1.59_54-old/lib/CPAN.pm ./lib/CPAN.pm --- ../CPAN-1.59_54-old/lib/CPAN.pm 2001-11-18 11:48:02.000000000 -0600 +++ ./lib/CPAN.pm 2001-11-18 13:00:26.000000000 -0600 @@ -3852,17 +3852,40 @@ my($mpl) = MM->catfile($packagedir,"Makefile.PL"); my($mpl_exists) = -f $mpl; - unless ($mpl_exists) { + my($bpl) = MM->catfile($packagedir,"Build.PL"); + my($bpl_exists) = -f $bpl; + unless ($mpl_exists or $bpl_exists) { # NFS has been reported to have racing problems after the # renaming of a directory in some environments. # This trick helps. sleep 1; - my $mpldh = DirHandle->new($packagedir) + my $dh = DirHandle->new($packagedir) or Carp::croak("Couldn't opendir $packagedir: $!"); - $mpl_exists = grep /^Makefile\.PL$/, $mpldh->read; - $mpldh->close; + foreach ($dh->read) { + $mpl_exists = /^Makefile\.PL$/; + $bpl_exists = /^Build\.PL$/; + } + $dh->close; } - unless ($mpl_exists) { + + # If this is a module that uses Module::Build then we need to + # install Module::Build. However, Module::Build uses _itself_ to + # install so to avoid a recursive prereq follow of doom, we + # explicitly do not try to install Module::Build when already + # install Module::Build. - Dave Rolsky + if ($bpl_exists and not grep { $_ eq "Module::Build" } $self->containsmods) { + my $nmo = $CPAN::META->instance("CPAN::Module","Module::Build"); + + unless ($nmo->inst_file and $nmo->uptodate) { + $CPAN::Frontend->myprint("The module you are installing requires the Module::Build package. +Either you do not have this module installed or you do not have the latest version. +It is recommended that you install the latest version now or +else it may not be possible to install this module"); + $self->follow_prereqs("Module::Build"); + } + } + + unless ($mpl_exists or $bpl_exists) { $self->debug(sprintf("makefilepl[%s]anycwd[%s]", $mpl, CPAN::anycwd(), @@ -3873,7 +3896,7 @@ $self->{'configure'} = $configure; } elsif (-f MM->catfile($packagedir,"Makefile")) { $CPAN::Frontend->myprint(qq{ -Package comes with a Makefile and without a Makefile.PL. +Package comes with a Makefile and without a Makefile.PL or Build.PL. We\'ll try to build it with that Makefile then. }); $self->{writemakefile} = "YES"; @@ -3886,9 +3909,9 @@ } $cf =~ s|[/\\:]||g; # risk of filesystem damage $cf = "unknown" unless length($cf); - $CPAN::Frontend->myprint(qq{Package seems to come without Makefile.PL. - (The test -f "$mpl" returned false.) - Writing one on our own (setting NAME to $cf)\a\n}); + $CPAN::Frontend->myprint(qq{Package seems to come without Makefile.PL or Build.PL. + (The tests -f "$mpl" and -f "$bpl" returned false.) + Writing a Makefile.PL on our own (setting NAME to $cf)\a\n}); $self->{had_no_makefile_pl}++; sleep 3; @@ -3899,7 +3922,7 @@ or Carp::croak("Could not open >$mpl: $!"); $fh->print( qq{# This Makefile.PL has been autogenerated by the module CPAN.pm -# because there was no Makefile.PL supplied. +# because there was no Makefile.PL or Build.PL supplied. # Autogenerated on: }.scalar localtime().qq{ use ExtUtils::MakeMaker; @@ -3907,9 +3930,14 @@ }); $fh->close; + + $mpl_exists = 1; } } + $self->{makescript} = $mpl_exists ? "Makefile.PL" : $bpl_exists ? "Build.PL" : ""; + $self->{maketype} = $mpl_exists ? 'make' : $bpl_exists ? "Module::Build" : ""; + return $self; } @@ -4370,7 +4398,7 @@ # $switch = "-MExtUtils::MakeMaker ". # "-Mops=:default,:filesys_read,:filesys_open,require,chdir" # if $] > 5.00310; - $system = "$perl $switch Makefile.PL $CPAN::Config->{makepl_arg}"; + $system = "$perl $switch $self->{makescript} $CPAN::Config->{makepl_arg}"; } unless (exists $self->{writemakefile}) { local($SIG{ALRM}) = sub { die "inactivity_timeout reached\n" }; @@ -4407,16 +4435,17 @@ } else { $ret = system($system); if ($ret != 0) { - $self->{writemakefile} = "NO Makefile.PL returned status $ret"; + $self->{writemakefile} = "NO $self->{makescript} returned status $ret"; return; } } - if (-f "Makefile") { + if (($self->{maketype} eq "make" && -f "Makefile") || + ($self->{maketype} eq "Module::Build" && -f "Build")) { $self->{writemakefile} = "YES"; delete $self->{make_clean}; # if cleaned before, enable next } else { $self->{writemakefile} = - qq{NO Makefile.PL refused to write a Makefile.}; + qq{NO $self->{makescript} refused to write a Makefile.}; # It's probably worth to record the reason, so let's retry # local $/; # my $fh = IO::File->new("$system |"); # STDERR? STDIN? @@ -4430,7 +4459,11 @@ if (my @prereq = $self->unsat_prereq){ return 1 if $self->follow_prereqs(@prereq); # signal success to the queuerunner } - $system = join " ", $CPAN::Config->{'make'}, $CPAN::Config->{make_arg}; + if ($self->{maketype} eq 'make') { + $system = join " ", $CPAN::Config->{'make'}, $CPAN::Config->{make_arg}; + } else { + $system = join " ", $self->perl, File::Spec->catfile( File::Spec->curdir, "Build" ), $CPAN::Config->{make_arg}; + } if (system($system) == 0) { $CPAN::Frontend->myprint(" $system -- OK\n"); $self->{'make'} = "YES"; @@ -4532,6 +4565,7 @@ # but we must have run it my $build_dir = $self->{build_dir} or die "Panic: no build_dir?"; my $makefile = File::Spec->catfile($build_dir,"Makefile"); + my $buildprereq = File::Spec->catfile($build_dir,"_build","prereq"); my(%p) = (); my $fh; if (-f $makefile @@ -4560,6 +4594,16 @@ } last; } + } elsif (-f $buildprereq + and + $fh = FileHandle->new("<$buildprereq")) { + while (<$fh>) { + my ($mod,$ver) = split /\s*=\s*/; + if ( defined $p{$mod} ) { + warn "Warning: PREREQ_PM mentions $mod more than once, last mention wins"; + } + $p{$mod} = $ver; + } } $self->{prereq_pm_detected}++; return $self->{prereq_pm} = \%p; @@ -4606,7 +4650,12 @@ return; } - my $system = join " ", $CPAN::Config->{'make'}, "test"; + my $system; + if ($self->{maketype} eq "make") { + $system = join " ", $CPAN::Config->{'make'}, "test"; + } elsif ($self->{maketype} eq "Module::Build") { + $system = join " ", $self->perl, File::Spec->catfile( File::Spec->curdir, "Build" ), "test"; + } if (system($system) == 0) { $CPAN::Frontend->myprint(" $system -- OK\n"); $self->{make_test} = "YES"; @@ -4637,7 +4686,12 @@ return; } - my $system = join " ", $CPAN::Config->{'make'}, "clean"; + my $system; + if ($self->{maketype} eq "make") { + $system = join " ", $CPAN::Config->{'make'}, "clean"; + } elsif ($self->{maketype} eq "Module::Build") { + $system = join " ", $self->perl, File::Spec->catfile( File::Spec->curdir, "Build" ), "clean"; + } if (system($system) == 0) { $CPAN::Frontend->myprint(" $system -- OK\n"); @@ -4712,8 +4766,14 @@ return; } - my $system = join(" ", $CPAN::Config->{'make'}, - "install", $CPAN::Config->{make_install_arg}); + my $system; + if ($self->{maketype} eq "make") { + $system = join(" ", $CPAN::Config->{'make'}, + "install", $CPAN::Config->{make_install_arg}); + } elsif ($self->{maketype} eq "Module::Build") { + $system = join(" ", $self->perl, File::Spec->catfile( File::Spec->curdir, "Build" ), + "install", $CPAN::Config->{make_install_arg}); + } my($stderr) = $^O =~ /Win/i ? "" : " 2>&1 "; my($pipe) = FileHandle->new("$system $stderr |"); my($makeout) = ""; |