In perl.git, the branch alh/cpan-bisect has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/ab8b8a17aa93b2f5e5d6d0ed8fe3ff281dead77d?hp=e36bb60d86001351e4a8f548bc3b3ccaac38bc19>

- Log -----------------------------------------------------------------
commit ab8b8a17aa93b2f5e5d6d0ed8fe3ff281dead77d
Author: Matthew Horsfall (alh) <[email protected]>
Date:   Sun Apr 19 06:34:00 2015 -0400

    For bisecting, create a CPAN::MyConfig under --module or --with-module.
    
    If you bisect with --module or --with-module, older perls need a
    CPAN::MyConfig, otherwise they will stop to ask for user input. This
    commit adds the ability to automatically create one if necessary (with
    some user interaction required.)
-----------------------------------------------------------------------

Summary of changes:
 Porting/bisect-runner.pl |  6 +++++
 Porting/bisect.pl        | 57 ++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/Porting/bisect-runner.pl b/Porting/bisect-runner.pl
index ba7ab0f..879ddb3 100755
--- a/Porting/bisect-runner.pl
+++ b/Porting/bisect-runner.pl
@@ -558,6 +558,12 @@ MSCHWERN/Test-Simple-1.005000_005.tar.gz.
 
 In so far, it is not such a misnomer.
 
+Note that this and B<--with-module> will both require a CPAN::MyConfig.
+If F</home/.cpan/CPAN/MyConfig.pm> does not exist, a CPAN shell will
+be started up for you so you can configure one. Feel free to let
+CPAN pick defaults for you. Enter 'quit' when you are done, and
+then everything should be all set.
+
 =item *
 
 --with-module module1,module2,...
diff --git a/Porting/bisect.pl b/Porting/bisect.pl
index 6e52a4c..6e78247 100755
--- a/Porting/bisect.pl
+++ b/Porting/bisect.pl
@@ -10,14 +10,28 @@ Documentation for this is in bisect-runner.pl
 # The default, auto_abbrev will treat -e as an abbreviation of --end
 # Which isn't what we want.
 use Getopt::Long qw(:config pass_through no_auto_abbrev);
+use File::Spec;
+use File::Path qw(mkpath);
+
+my ($start, $end, $validate, $usage, $bad, $jobs, $make, $gold,
+    $module, $with_module);
+
+my $need_cpan_config;
 
-my ($start, $end, $validate, $usage, $bad, $jobs, $make, $gold);
 $bad = !GetOptions('start=s' => \$start, 'end=s' => \$end,
                    'jobs|j=i' => \$jobs, 'make=s' => \$make, 'gold=s' => 
\$gold,
-                   validate => \$validate, 'usage|help|?' => \$usage);
+                   validate => \$validate, 'usage|help|?' => \$usage,
+                   'module=s' => \$module, 'with-module=s' => \$with_module);
 unshift @ARGV, '--help' if $bad || $usage;
 unshift @ARGV, '--validate' if $validate;
 
+if ($module || $with_module) {
+  $need_cpan_config = 1;
+
+  unshift @ARGV, '--module', $module if defined $module;
+  unshift @ARGV, '--with-module', $with_module if defined $with_module;
+}
+
 my $runner = $0;
 $runner =~ s/bisect\.pl/bisect-runner.pl/;
 
@@ -49,6 +63,45 @@ if (!defined $jobs &&
 unshift @ARGV, '--jobs', $jobs if defined $jobs;
 unshift @ARGV, '--make', $make if defined $make;
 
+if ($need_cpan_config) {
+  # Make sure we have a CPAN::MyConfig so if we start at an old
+  # revision CPAN doesn't ask for user input to configure itself
+
+  my $cdir = File::Spec->catdir($ENV{HOME},".cpan","CPAN");
+  my $cfile = File::Spec->catfile($cdir, "MyConfig.pm");
+
+  unless (-e $cfile) {
+    printf <<EOF;
+I could not find a CPAN::MyConfig. We need to create one now so that
+you can bisect with --module or --with-module. I'll boot up the CPAN
+shell for you. Feel free to use defaults or change things as needed.
+Type 'quit' when finished.
+EOF
+    system("$^X -MCPAN -e shell");
+
+    # mkpath for older File::Spec support (5.8.8, etc)
+    eval { mkpath($cdir); };
+    die "Failed to mkdir $cdir: $@\n" if $@;
+
+    open (my $fh, '>', $cfile)
+      || die "Could not open $cfile for writing: $!\n";
+
+    my $data = `$^X -mCPAN -MData::Dumper -e 'CPAN::Config->load;
+                print Dumper(\$CPAN::Config)' 2>/dev/null`;
+
+    # Replace $VAR1 = { with $CPAN::Config = {
+    unless ($data =~ s/^.*\$VAR1\s+=\s+{/\$CPAN::Config = {/s) {
+      die "CPAN::Config does not look right, can't continue.\n",
+          "Try creating a CPAN::MyConfig manually.\n",
+          "The unrecognized output was: $data";
+    }
+
+    print $fh $data;
+    print $fh "\n1;\n";
+    close $data;
+  }
+}
+
 # We try these in this order for the start revision if none is specified.
 my @stable = map {chomp $_; $_} grep {/v5\.[0-9]+[02468]\.0$/} `git tag -l`;
 die "git tag -l didn't seem to return any tags for stable releases"

--
Perl5 Master Repository

Reply via email to