Perl coding error in msvc build system? - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Perl coding error in msvc build system?
Date
Msg-id 1401849050.17288.0.camel@vanquo.pezone.net
Whole thread Raw
Responses Re: Perl coding error in msvc build system?  (Abhijit Menon-Sen <ams@2ndQuadrant.com>)
List pgsql-hackers
I'm not sure whether the following coding actually detects any errors:

Solution.pm:
   open(P, "cl /? 2>&1 |") || die "cl command not found";

VSObjectFactory.pm:
   open(P, "nmake /? 2>&1 |")         || croak   "Unable to determine Visual Studio version: The nmake command wasn't
found.";

The problem is that because of the shell special characters, the command
is run through the shell, but the shell ignores the exit status of
anything but the last command in the pipe.  And the perlopentut man page
says "In such a case, the "open" call will only indicate failure if Perl
can't even run the shell.".  I can confirm that on a *nix system.  It
might be different on Windows, but it doesn't seem so.

The whole thing could probably be written in a less complicated way
using backticks, like

--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -72,16 +72,13 @@ sub DeterminePlatform       # Examine CL help output to determine if we are in 32 or 64-bit mode.
   $self->{platform} = 'Win32';
 
-       open(P, "cl /? 2>&1 |") || die "cl command not found";
-       while (<P>)
+       my $output = `cl /? 2>&1`;
+       $? >> 8 == 0 or die "cl command not found";
+       if ($output =~ /^\/favor:<.+AMD64/)       {
-               if (/^\/favor:<.+AMD64/)
-               {
-                       $self->{platform} = 'x64';
-                       last;
-               }
+               $self->{platform} = 'x64';
+               last;       }
-       close(P);       print "Detected hardware platform: $self->{platform}\n";}






pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: idle_in_transaction_timeout
Next
From: Fujii Masao
Date:
Subject: Re: pg_stat directory and pg_stat_statements