#
# devtools.pl -- various utility functions
#
+# NOTE: This will only be called by the overarching (modern) perl
+#
################################################################################
#
# Version 3.x, Copyright (C) 2004-2013, Marcus Holland-Moritz.
################################################################################
use IO::File;
+require "./parts/inc/inctools";
eval "use Term::ANSIColor";
$@ and eval "sub colored { pop; @_ }";
status => $? >> 8,
stdout => [<$out>],
stderr => [<$err>],
- didnotrun => 0,
+ didnotrun => 0, # Note that currently this will always be 0
+ # This must have been used in earlier versions
);
unlink "tmp.out", "tmp.err";
return sprintf "%02d:%02d:%02d", $h, $m, $s;
}
+sub get_and_sort_perls($)
+{
+ my $opt = shift;
+
+ my $starting;
+ $starting = int_parse_version($opt->{'debug-start'})
+ if $opt->{'debug-start'};
+
+ # Uses the opt structure parameter to find the perl versions to use this
+ # run, and returns an array with a hash representing blead in the 0th
+ # element and the oldest in the final one. Each entry looks like
+ # {
+ # 'version' => '5.031002',
+ # 'file' => '5031002',
+ # 'path' => '/home/khw/devel/bin/perl5.31.2'
+ # },
+ #
+ # Get blead and all other perls
+ my @perls = $opt->{blead};
+ for my $dir (split ",", $opt->{install}) {
+ push @perls, grep !/-RC\d+/, glob "$dir/bin/perl5.*";
+ }
+
+ # Normalize version numbers into 5.xxxyyy, and convert each element
+ # describing the perl to be a hash with keys 'version' and 'path'
+ for (my $i = 0; $i < @perls; $i++) {
+ my $version = `$perls[$i] -e 'print \$]'`;
+ my $file = int_parse_version($version);
+ $version = format_version($version);
+
+ # Make this entry a hash with its version, file name, and path
+ $perls[$i] = { version => $version,
+ file => $file,
+ path => $perls[$i],
+ };
+ }
+
+ # Sort in descending order. We start processing the most recent perl
+ # first.
+ @perls = sort { $b->{file} <=> $a->{file} } @perls;
+
+ # Override blead's version if specified.
+ if (exists $opt->{'blead-version'}) {
+ $perls[0]{version} = format_version($opt->{'blead-version'});
+ }
+
+ my %seen;
+
+ # blead's todo is its version plus 1. Otherwise, each todo is the
+ # previous one's. Also get rid of duplicate versions.
+ $perls[0]{todo} = $perls[0]{file} + 1;
+ $seen{$perls[0]{file}} = 1;
+ for my $i (1 .. $#perls) {
+ last unless defined $perls[$i];
+ if ( exists $seen{$perls[$i]{file}}
+ || ($starting && $perls[$i]{file} gt $starting)
+ ) {
+ splice @perls, $i, 1;
+ redo;
+ }
+
+ $seen{$perls[$i]{file}} = 1;
+ $perls[$i]{todo} = $perls[$i-1]{file};
+ }
+
+ return \@perls;
+}
+
1;