This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Improve cl version detection
authorSteve Hay <steve.m.hay@googlemail.com>
Wed, 15 Nov 2017 14:07:42 +0000 (14:07 +0000)
committerSteve Hay <steve.m.hay@googlemail.com>
Wed, 15 Nov 2017 14:07:42 +0000 (14:07 +0000)
Drop the use of the word "Version" so it works on non-English systems.
Instead, simply look for a number of the form X.Y (or X.Y.Z etc) with word
boundaries around it. Thus, we can find numbers like 12.00.8804 or
19.00.24213.1, but not accidentally pick up things like x86 or 1984-1998.

Also, drop the "--version" argument since it doesn't really exist and
causes warnings/errors to be output. A bare "cl" command suffices to get a
usage message including the version number to be output.

Finally, the Windows version detection can be similarly improved.

This fixes perl #132421.

win32/config_sh.PL

index 8d6f738..2afd655 100644 (file)
@@ -84,18 +84,13 @@ $opt{version_patchlevel_string} = "version $opt{PERL_VERSION} subversion $opt{PE
 $opt{version_patchlevel_string} .= " patch $opt{PERL_PATCHLEVEL}" if exists $opt{PERL_PATCHLEVEL};
 
 my $ver = `ver 2>nul`;
 $opt{version_patchlevel_string} .= " patch $opt{PERL_PATCHLEVEL}" if exists $opt{PERL_PATCHLEVEL};
 
 my $ver = `ver 2>nul`;
-if ($ver =~ /Version (\d+\.\d+)/) {
-    $opt{osvers} = $1;
-}
-else {
-    $opt{osvers} = '4.0';
-}
+$opt{osvers} = $ver =~ /\b(\d+(?:\.\d+)+)\b/ ? $1 : '4.0';
 
 if (exists $opt{cc}) {
     # cl version detection borrowed from Test::Smoke's configsmoke.pl
     if ($opt{cc} =~ /\b(?:cl|icl)/) { #MSVC can come as clarm.exe, icl=Intel C
 
 if (exists $opt{cc}) {
     # cl version detection borrowed from Test::Smoke's configsmoke.pl
     if ($opt{cc} =~ /\b(?:cl|icl)/) { #MSVC can come as clarm.exe, icl=Intel C
-        my $output = `$opt{cc} --version 2>&1`;
-        $opt{ccversion} = $output =~ /^.*Version\s+([\d.]+)/ ? $1 : '?';
+        my $output = `$opt{cc} 2>&1`;
+        $opt{ccversion} = $output =~ /\b(\d+(?:\.\d+)+)\b/ ? $1 : '?';
     }
     elsif ($opt{cc} =~ /\bgcc\b/) {
         chomp($opt{gccversion} = `$opt{cc} -dumpversion`);
     }
     elsif ($opt{cc} =~ /\bgcc\b/) {
         chomp($opt{gccversion} = `$opt{cc} -dumpversion`);
@@ -274,7 +269,7 @@ if ($opt{cc} =~ /\bcl/ and $opt{ccversion} =~ /^(\d+)/) {
        $opt{sGMTIME_max} = 32535291599;
        $opt{sLOCALTIME_max} = 32535244799;
     }
        $opt{sGMTIME_max} = 32535291599;
        $opt{sLOCALTIME_max} = 32535244799;
     }
-    if($ccversion < 13) { #VC6
+    if ($ccversion < 13) { #VC6
        $opt{ar} ='lib';
     }
     if ($ccversion >= 19) { # VC14
        $opt{ar} ='lib';
     }
     if ($ccversion >= 19) { # VC14
@@ -287,9 +282,9 @@ if ($opt{cc} =~ /\bcl/ and $opt{ccversion} =~ /^(\d+)/) {
 }
 #find out which MSVC this ICC is using
 elsif ($opt{cc} =~ /\bicl/) {
 }
 #find out which MSVC this ICC is using
 elsif ($opt{cc} =~ /\bicl/) {
-    my $output = `cl --version 2>&1`;
-    my $num_ver = $output =~ /^.*Version\s+([\d.]+)/ ? $1 : '?';
-    if($num_ver =~ /^(\d+)/ && $1 >= 14) {
+    my $output = `cl 2>&1`;
+    my $num_ver = $output =~ /\b(\d+(?:\.\d+)+)\b/ ? $1 : '?';
+    if ($num_ver =~ /^(\d+)/ && $1 >= 14) {
        $opt{sGMTIME_max} = 32535291599;
        $opt{sLOCALTIME_max} = 32535244799;
     }
        $opt{sGMTIME_max} = 32535291599;
        $opt{sLOCALTIME_max} = 32535244799;
     }