1 ################################################################################
3 # devtools.pl -- various utility functions
5 # NOTE: This will only be called by the overarching (modern) perl
7 ################################################################################
9 # Version 3.x, Copyright (C) 2004-2013, Marcus Holland-Moritz.
10 # Version 2.x, Copyright (C) 2001, Paul Marquess.
11 # Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
13 # This program is free software; you can redistribute it and/or
14 # modify it under the same terms as Perl itself.
16 ################################################################################
19 require "./parts/inc/inctools";
21 eval "use Term::ANSIColor";
22 $@ and eval "sub colored { pop; @_ }";
30 s/^(.*)/colored("($0) ", 'bold blue').colored($1, 'blue')/eg for @out;
37 return $opt{verbose} ? ('--verbose') : ();
42 my $opt = ref $_[0] ? shift @_ : {};
43 my($prog, @args) = @_;
44 my $sysstr = join ' ', map { "'$_'" } $prog, @args;
45 $sysstr .= " >$opt->{'out'}" if exists $opt->{'out'};
46 $sysstr .= " 2>$opt->{'err'}" if exists $opt->{'err'};
47 verbose("running $sysstr\n");
48 my $rv = system $sysstr;
49 verbose("$prog => exit code $rv\n");
55 my $opt = ref $_[0] ? shift @_ : {};
56 runtool($opt, $^X, @_);
64 runtool({ 'out' => 'tmp.out', 'err' => 'tmp.err' }, $prog, @args);
66 my $out = IO::File->new("tmp.out") or die "tmp.out: $!\n";
67 my $err = IO::File->new("tmp.err") or die "tmp.err: $!\n";
73 didnotrun => 0, # Note that currently this will always be 0
74 # This must have been used in earlier versions
77 unlink "tmp.out", "tmp.err";
79 $? & 128 and $rval{core} = 1;
80 $? & 127 and $rval{signal} = $? & 127;
87 return "$^X $0 @argvcopy";
92 verbose(ident_str() . "\n");
101 print "\a\n$q [y/n] ";
103 while ($a !~ /^\s*([yn])\s*$/i);
109 print "\nSorry, cannot continue.\n\n";
115 quit_now unless &ask;
120 my($start, $i, $n) = @_;
121 return "--:--:--" if $i < 3;
122 my $elapsed = tv_interval($start);
123 my $h = int($elapsed*($n-$i)/$i);
124 my $s = $h % 60; $h /= 60;
125 my $m = $h % 60; $h /= 60;
126 return sprintf "%02d:%02d:%02d", $h, $m, $s;
129 sub get_and_sort_perls($)
134 $starting = int_parse_version($opt->{'debug-start'})
135 if $opt->{'debug-start'};
137 # Uses the opt structure parameter to find the perl versions to use this
138 # run, and returns an array with a hash representing blead in the 0th
139 # element and the oldest in the final one. Each entry looks like
141 # 'version' => '5.031002',
142 # 'file' => '5031002',
143 # 'path' => '/home/khw/devel/bin/perl5.31.2'
146 # Get blead and all other perls
147 my @perls = $opt->{blead};
148 for my $dir (split ",", $opt->{install}) {
149 push @perls, grep !/-RC\d+/, glob "$dir/bin/perl5.*";
152 # Normalize version numbers into 5.xxxyyy, and convert each element
153 # describing the perl to be a hash with keys 'version' and 'path'
154 for (my $i = 0; $i < @perls; $i++) {
155 my $version = `$perls[$i] -e 'print \$]'`;
156 my $file = int_parse_version($version);
157 $version = format_version($version);
159 # Make this entry a hash with its version, file name, and path
160 $perls[$i] = { version => $version,
166 # Sort in descending order. We start processing the most recent perl
168 @perls = sort { $b->{file} <=> $a->{file} } @perls;
170 # Override blead's version if specified.
171 if (exists $opt->{'blead-version'}) {
172 $perls[0]{version} = format_version($opt->{'blead-version'});
177 # blead's todo is its version plus 1. Otherwise, each todo is the
178 # previous one's. Also get rid of duplicate versions.
179 $perls[0]{todo} = $perls[0]{file} + 1;
180 $seen{$perls[0]{file}} = 1;
181 for my $i (1 .. $#perls) {
182 last unless defined $perls[$i];
183 if ( exists $seen{$perls[$i]{file}}
184 || ($starting && $perls[$i]{file} gt $starting)
186 splice @perls, $i, 1;
190 $seen{$perls[$i]{file}} = 1;
191 $perls[$i]{todo} = $perls[$i-1]{file};