diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2015-02-18 20:24:30 -0500 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2015-02-18 20:24:30 -0500 |
commit | d30292b8c45a1d909ff7d84bd6787c8827134fc3 (patch) | |
tree | 67c7738176b926e0f6051ac8b3ae37144d8ec452 | |
parent | 9c7dd350199fa030ccbd5538e1b8e13a9603fda4 (diff) | |
download | postgresql-d30292b8c45a1d909ff7d84bd6787c8827134fc3.tar.gz postgresql-d30292b8c45a1d909ff7d84bd6787c8827134fc3.zip |
Fix Perl coding error in msvc build system
Code like
open(P, "cl /? 2>&1 |") || die "cl command not found";
does not actually catch any errors, because the exit status of the
command before the pipe is ignored. The fix is to look at $?.
This also gave the opportunity to clean up the logic of this code a bit.
-rw-r--r-- | src/tools/msvc/Solution.pm | 14 | ||||
-rw-r--r-- | src/tools/msvc/VSObjectFactory.pm | 28 |
2 files changed, 10 insertions, 32 deletions
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index 39e41f67383..714585f3fed 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -71,17 +71,9 @@ sub DeterminePlatform my $self = shift; # 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>) - { - if (/^\/favor:<.+AMD64/) - { - $self->{platform} = 'x64'; - last; - } - } - close(P); + my $output = `cl /? 2>&1`; + $? >> 8 == 0 or die "cl command not found"; + $self->{platform} = ($output =~ /^\/favor:<.+AMD64/m) ? 'x64' : 'Win32'; print "Detected hardware platform: $self->{platform}\n"; } diff --git a/src/tools/msvc/VSObjectFactory.pm b/src/tools/msvc/VSObjectFactory.pm index d255becfe8b..b83af4026eb 100644 --- a/src/tools/msvc/VSObjectFactory.pm +++ b/src/tools/msvc/VSObjectFactory.pm @@ -92,30 +92,16 @@ sub CreateProject sub DetermineVisualStudioVersion { - my $nmakeVersion = shift; - - if (!defined($nmakeVersion)) - { - -# Determine version of nmake command, to set proper version of visual studio -# we use nmake as it has existed for a long time and still exists in current visual studio versions - open(P, "nmake /? 2>&1 |") - || croak -"Unable to determine Visual Studio version: The nmake command wasn't found."; - while (<P>) - { - chomp; - if (/(\d+)\.(\d+)\.\d+(\.\d+)?$/) - { - return _GetVisualStudioVersion($1, $2); - } - } - close(P); - } - elsif ($nmakeVersion =~ /(\d+)\.(\d+)\.\d+(\.\d+)?$/) + # To determine version of Visual Studio we use nmake as it has + # existed for a long time and still exists in current Visual + # Studio versions. + my $output = `nmake /? 2>&1`; + $? >> 8 == 0 or croak "Unable to determine Visual Studio version: The nmake command wasn't found."; + if ($output =~ /(\d+)\.(\d+)\.\d+(\.\d+)?$/m) { return _GetVisualStudioVersion($1, $2); } + croak "Unable to determine Visual Studio version: The nmake version could not be determined."; } |