Skip to content

Commit

Permalink
Generalize to accept Perl 7
Browse files Browse the repository at this point in the history
Most of this commit was from Nicolas Rochelmagne
  • Loading branch information
khwilliamson committed Jul 9, 2020
1 parent af7a3f0 commit 293861b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
8 changes: 7 additions & 1 deletion parts/apicheck.pl
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,13 @@
# #ifdef out if marked as todo (not known in) this version
if (exists $todo{$f->{'name'}}) {
my($five, $ver,$sub) = parse_version($todo{$f->{'name'}}{'version'});
print OUT "#if PERL_VERSION > $ver || (PERL_VERSION == $ver && PERL_SUBVERSION >= $sub) /* TODO */\n";
print OUT <<EOT;
#if PERL_REVISION > $five \\
|| ( PERL_REVISION == $five \\
&& ( PERL_VERSION > $ver \\
|| ( PERL_VERSION == $ver \\
&& PERL_SUBVERSION >= $sub))) /* TODO */
EOT
}

my $final = $varargs
Expand Down
26 changes: 15 additions & 11 deletions parts/inc/inctools
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# WARNING: Use only constructs that are legal as far back as D:P handles, as
# this is run in the perl version being tested.

# What revisions are legal, to be output as-is and converted into a pattern
# that matches them precisely
my $r_pat = "[57]";

sub format_version
{
# Given an input version that is acceptable to parse_version(), return a
Expand All @@ -23,35 +27,35 @@ sub format_version

sub parse_version
{
# Returns a triplet, (5, major, minor) from the input, treated as a string,
# which can be in any of several typical formats.
# Returns a triplet, (revision, major, minor) from the input, treated as a
# string, which can be in any of several typical formats.

my $ver = shift;
$ver = "" unless defined $ver;

my($r,$v,$s);

if ( ($r, $v, $s) = $ver =~ /^(5)(\d{3})(\d{3})$/ # 5029010, from the file
if ( ($r, $v, $s) = $ver =~ /^([0-9]+)([0-9]{3})([0-9]{3})$/ # 5029010, from the file
# names in our
# parts/base/ and
# parts/todo directories
or ($r, $v, $s) = $ver =~ /^(\d+)\.(\d+)\.(\d+)$/ # 5.25.7
or ($r, $v, $s) = $ver =~ /^(\d+)\.(\d{3})(\d{3})$/ # 5.025008, from the
# output of $]
or ($r, $v, $s) = $ver =~ /^(\d+)\.(\d{1,3})()$/ # 5.24, 5.004
or ($r, $v, $s) = $ver =~ /^(\d+)\.(00[1-5])_?(\d{2})$/ # 5.003_07
or ($r, $v, $s) = $ver =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)$/ # 5.25.7
or ($r, $v, $s) = $ver =~ /^([0-9]+)\.([0-9]{3})([0-9]{3})$/ # 5.025008, from the
# output of $]
or ($r, $v, $s) = $ver =~ /^([0-9]+)\.([0-9]{1,3})()$/ # 5.24, 5.004
or ($r, $v, $s) = $ver =~ /^([0-9]+)\.(00[1-5])_?([0-9]{2})$/ # 5.003_07
) {

$s = 0 unless $s;

die "Only Perl $r_pat are supported '$ver'\n" unless $r =~ / ^ $r_pat $ /x;
die "Invalid version number: $ver\n" if $v >= 1000 || $s >= 1000;
return (5, 0 + $v, 0 + $s);
return (0 +$r, 0 + $v, 0 + $s);
}

# For some safety, don't assume something is a version number if it has a
# literal dot as one of the three characters. This will have to be fixed
# when we reach 5.46
# when we reach x.46 (since 46 is ord('.'))
if ($ver !~ /\./ && (($r, $v, $s) = $ver =~ /^(.)(.)(.)$/)) # vstring 5.25.7
{
$r = ord $r;
Expand Down Expand Up @@ -85,7 +89,7 @@ sub format_version_line
# Returns a floating point representation of the input version

my $version = int_parse_version(shift);
$version =~ s/^5\B/5./;
$version =~ s/ ^ ( $r_pat ) \B /$1./x;
return $version;
}

Expand Down
4 changes: 2 additions & 2 deletions parts/inc/ppphtest
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,8 @@ ok($o !~ /Uses SvPVutf8_force/m);
$o = ppport(qw(--nochanges --compat-version=5.999.999));
ok($o !~ /Uses SvPVutf8_force/m);

$o = ppport(qw(--nochanges --compat-version=6.0.0));
ok($o =~ /Only Perl 5 is supported/m);
$o = ppport(qw(--nochanges --compat-version=8.0.0));
ok($o =~ /Only Perl \[57\] are supported/m);

$o = ppport(qw(--nochanges --compat-version=5.1000.999));
ok($o =~ /Invalid version number: 5.1000.999/m);
Expand Down
2 changes: 1 addition & 1 deletion parts/ppptools.pl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ sub expand_version
{
my($op, $ver) = @_;
my($r, $v, $s) = parse_version($ver);
$r == 5 or die "only Perl revision 5 is supported\n";
$r =~ / ^ [57] $ /x or die "only Perl revisions [57] are supported\n";
my $bcdver = sprintf "0x%d%03d%03d", $r, $v, $s;
return "(PERL_BCDVERSION $op $bcdver)";
}
Expand Down
4 changes: 2 additions & 2 deletions t/ppphtest.t
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,8 @@ ok($o !~ /Uses SvPVutf8_force/m);
$o = ppport(qw(--nochanges --compat-version=5.999.999));
ok($o !~ /Uses SvPVutf8_force/m);
$o = ppport(qw(--nochanges --compat-version=6.0.0));
ok($o =~ /Only Perl 5 is supported/m);
$o = ppport(qw(--nochanges --compat-version=8.0.0));
ok($o =~ /Only Perl \[57\] are supported/m);
$o = ppport(qw(--nochanges --compat-version=5.1000.999));
ok($o =~ /Invalid version number: 5.1000.999/m);
Expand Down

0 comments on commit 293861b

Please sign in to comment.