Skip to content

Commit

Permalink
per #toolchain advice:
Browse files Browse the repository at this point in the history
  Check META.yml for configure_requires
  Run Build.PL or Makefile.PL with X_MYMETA=YAML
  Check MYMETA.yml and META.yml for other *requires
  And fallback to Makefile PREREQ_PM scanning for old EUMM
  • Loading branch information
miyagawa committed Feb 20, 2010
1 parent fc8bfcd commit d8d068d
Showing 1 changed file with 80 additions and 32 deletions.
112 changes: 80 additions & 32 deletions cpanm
Expand Up @@ -86,6 +86,9 @@ USAGE
my $Base = $ENV{CPANMINUS_HOME} || "$ENV{HOME}/.cpanm"; my $Base = $ENV{CPANMINUS_HOME} || "$ENV{HOME}/.cpanm";
mkdir $Base, 0777 unless -e $Base; mkdir $Base, 0777 unless -e $Base;


$Base .= "/build-" . time . ".$$";
mkdir $Base, 0777;

unless (@ARGV) { unless (@ARGV) {
help(); help();
} }
Expand Down Expand Up @@ -200,54 +203,94 @@ sub search_module {
return; return;
} }


sub install_deps {
my($dir, %deps) = @_;

my @install;
while (my($mod, $ver) = each %deps) {
next if $mod eq 'perl' or $mod eq 'Config';
diag "Checking if you have $mod $ver ... ";
$ver = '' if $ver == 0;
my $test = `$^X -e ${quote}eval q{use $mod $ver (); print q{OK:}, q/$mod/->VERSION$quote}`;
if ($test =~ s/^OK://) {
diag "Yes ($test)\n";
} else {
diag "No\n";
push @install, $mod;
}
}

if (@install) {
diag "Found dependencies: ", join(", ", @install), "\n";
}

for my $mod (@install) {
install_module($mod);
}

_chdir $Base;
_chdir $dir;
}

sub build_stuff { sub build_stuff {
my($module, $dir) = @_; my($module, $dir) = @_;


if (-e 'META.yml') { if (-e 'META.yml') {
diag "Checking dependencies ...\n"; diag "Checking configure dependencies from META.yml ...\n";
my $meta = eval { (Parse::CPAN::Meta::LoadFile('META.yml'))[0] }; my $meta = parse_meta('META.yml');
my %deps = (%{$meta->{requires} || {}}, %{$meta->{build_requires} || {}}); my %deps = %{$meta->{configure_requires} || {}};

my @install;
while (my($mod, $ver) = each %deps) {
next if $mod eq 'perl' or $mod eq 'Config';
diag "Checking if you have $mod $ver ... ";
$ver = '' if $ver == 0;
my $test = `$^X -e ${quote}eval q{use $mod $ver (); print q{OK:}, q/$mod/->VERSION$quote}`;
if ($test =~ s/^OK://) {
diag "Yes ($test)\n";
} else {
diag "No\n";
push @install, $mod;
}
}


for my $mod (@install) { install_deps($dir, %deps);
install_module($mod);
}

_chdir $Base;
_chdir $dir;
} }


diag "Building $module ...\n"; diag "Building $module ...\n";


# fake AutoInstall # trick AutoInstall
$ENV{PERL5_CPAN_IS_RUNNING} = 1; $ENV{PERL5_CPAN_IS_RUNNING} = 1;


unless ($make or -e "Build.PL") { if (-e 'Build.PL') {
diag "Oops, you don't have make. Trying to build a stub Build.PL for you. Hope this works!\n"; run "$^X Build.PL";
open my $fh, ">", "Build.PL" or die $!; } elsif (-e 'Makefile.PL') {
print $fh qq{require Module::Build; Module::Build->new(module_name => "$module")->create_build_script}; $ENV{X_MYMETA} = 'YAML';
run "$^X Makefile.PL";
} }


if (-e 'Build.PL') { my %deps;
run "$^X Build.PL" && my($metayml) = grep -e $_, qw( MYMETA.yml META.yml );
if ($metayml) {
diag "Checking dependencies from $metayml ...\n";
my $meta = parse_meta($metayml);
%deps = (%{$meta->{build_requires} || {}}, %{$meta->{test_requires} || {}}, %{$meta->{requires} || {}});
}

if (-e 'Makefile') {
diag "Finding PREREQ from Makefile ...\n";
open my $mf, "<", 'Makefile';
while (<$mf>) {
if (/^\#\s+PREREQ_PM => ({.*?})/) {
no strict; # WTF bareword keys
my $prereq = eval "+$1";
%deps = (%deps, %$prereq) if $prereq;
last;
}
}
}

install_deps($dir, %deps);

unless ($make or -e "Build") {
diag "Oops, you don't have make. Trying to build a stub Build file for you. Hope this works!\n";
eval {
require Module::Build;
Module::Build->new(module_name => "$module")->create_build_script;
};
}

if (-e 'Build') {
run "$^X ./Build" && run "$^X ./Build" &&
$test->("$^X ./Build test") && $test->("$^X ./Build test") &&
$install->("$^X ./Build install"); $install->("$^X ./Build install");
} elsif ($make && -e 'Makefile.PL') { } elsif ($make && -e 'Makefile') {
run "$^X Makefile.PL" &&
run "$make" && run "$make" &&
$test->("$make test") && $test->("$make test") &&
$install->("$make install"); $install->("$make install");
Expand Down Expand Up @@ -321,6 +364,11 @@ sub init_tools {
} }
} }


sub parse_meta {
my $file = shift;
return eval { (Parse::CPAN::Meta::LoadFile($file))[0] } || {};
}

### Inline stripped Parse::CPAN::Meta ### Inline stripped Parse::CPAN::Meta
# Copyright: Adam Kennedy # Copyright: Adam Kennedy
package Parse::CPAN::Meta; package Parse::CPAN::Meta;
Expand Down

0 comments on commit d8d068d

Please sign in to comment.