From 293861b9234e45fb1a3018959caaab2086bc6fbd Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Wed, 8 Jul 2020 09:58:04 +0000 Subject: [PATCH] Generalize to accept Perl 7 Most of this commit was from Nicolas Rochelmagne --- parts/apicheck.pl | 8 +++++++- parts/inc/inctools | 26 +++++++++++++++----------- parts/inc/ppphtest | 4 ++-- parts/ppptools.pl | 2 +- t/ppphtest.t | 4 ++-- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/parts/apicheck.pl b/parts/apicheck.pl index 268ada46..1def2487 100644 --- a/parts/apicheck.pl +++ b/parts/apicheck.pl @@ -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 < $five \\ + || ( PERL_REVISION == $five \\ + && ( PERL_VERSION > $ver \\ + || ( PERL_VERSION == $ver \\ + && PERL_SUBVERSION >= $sub))) /* TODO */ +EOT } my $final = $varargs diff --git a/parts/inc/inctools b/parts/inc/inctools index fe6a7079..8c639881 100644 --- a/parts/inc/inctools +++ b/parts/inc/inctools @@ -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 @@ -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; @@ -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; } diff --git a/parts/inc/ppphtest b/parts/inc/ppphtest index 9b13279f..2ebaa116 100644 --- a/parts/inc/ppphtest +++ b/parts/inc/ppphtest @@ -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); diff --git a/parts/ppptools.pl b/parts/ppptools.pl index c73e2b01..868e5054 100644 --- a/parts/ppptools.pl +++ b/parts/ppptools.pl @@ -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)"; } diff --git a/t/ppphtest.t b/t/ppphtest.t index 70a1b443..8e2f8a67 100644 --- a/t/ppphtest.t +++ b/t/ppphtest.t @@ -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);