Permalink
Browse files

Remove dependency on ExtUtils::CBuilder

  • Loading branch information...
1 parent bc09bd7 commit b87ba4fb9430af67c8da91eeef3b71da9782e7b4 @Leont committed Jun 19, 2012
Showing with 31 additions and 3 deletions.
  1. +31 −3 lib/Devel/FindPerl.pm
View
@@ -6,6 +6,7 @@ use Exporter 5.57 'import';
our @EXPORT_OK = qw/find_perl_interpreter/;
use Capture::Tiny 'capture';
+use Carp;
use Cwd;
use ExtUtils::Config;
use File::Spec;
@@ -34,9 +35,7 @@ sub find_perl_interpreter {
# perl, we can keep moving up the directory tree until we find our
# binary. We wouldn't do this under any other circumstances.
- # CBuilder is also in the core, so it should be available here
- require ExtUtils::CBuilder;
- my $perl_src = Cwd::realpath(ExtUtils::CBuilder->perl_src);
+ my $perl_src = Cwd::realpath(_perl_src());
if (defined($perl_src) && length($perl_src)) {
my $uninstperl = File::Spec->rel2abs(File::Spec->catfile($perl_src, $perl_basename));
push @potential_perls, $uninstperl;
@@ -67,6 +66,35 @@ sub find_perl_interpreter {
die "Can't locate the perl binary used to run this script in (@paths)\n";
}
+# if building perl, perl's main source directory
+sub _perl_src {
+ # N.B. makemaker actually searches regardless of PERL_CORE, but
+ # only squawks at not finding it if PERL_CORE is set
+
+ return unless $ENV{PERL_CORE};
+
+ my $Updir = File::Spec->updir;
+ my $dir = File::Spec->curdir;
+
+ # Try up to 10 levels upwards
+ for (0..10) {
+ if (
+ -f File::Spec->catfile($dir,"config_h.SH")
+ &&
+ -f File::Spec->catfile($dir,"perl.h")
+ &&
+ -f File::Spec->catfile($dir,"lib","Exporter.pm")
+ ) {
+ return Cwd::realpath( $dir );
+ }
+
+ $dir = File::Spec->catdir($dir, $Updir);
+ }
+
+ carp "PERL_CORE is set but I can't find your perl source!\n";
+ return; # return empty string if $ENV{PERL_CORE} but can't find dir ???
+}
+
sub _perl_is_same {
my $perl = shift;

0 comments on commit b87ba4f

Please sign in to comment.