Skip to content

Commit d30292b

Browse files
committed
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.
1 parent 9c7dd35 commit d30292b

File tree

2 files changed

+10
-32
lines changed

2 files changed

+10
-32
lines changed

src/tools/msvc/Solution.pm

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,9 @@ sub DeterminePlatform
7171
my $self = shift;
7272

7373
# Examine CL help output to determine if we are in 32 or 64-bit mode.
74-
$self->{platform} = 'Win32';
75-
open(P, "cl /? 2>&1 |") || die "cl command not found";
76-
while (<P>)
77-
{
78-
if (/^\/favor:<.+AMD64/)
79-
{
80-
$self->{platform} = 'x64';
81-
last;
82-
}
83-
}
84-
close(P);
74+
my $output = `cl /? 2>&1`;
75+
$? >> 8 == 0 or die "cl command not found";
76+
$self->{platform} = ($output =~ /^\/favor:<.+AMD64/m) ? 'x64' : 'Win32';
8577
print "Detected hardware platform: $self->{platform}\n";
8678
}
8779

src/tools/msvc/VSObjectFactory.pm

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,30 +92,16 @@ sub CreateProject
9292

9393
sub DetermineVisualStudioVersion
9494
{
95-
my $nmakeVersion = shift;
96-
97-
if (!defined($nmakeVersion))
98-
{
99-
100-
# Determine version of nmake command, to set proper version of visual studio
101-
# we use nmake as it has existed for a long time and still exists in current visual studio versions
102-
open(P, "nmake /? 2>&1 |")
103-
|| croak
104-
"Unable to determine Visual Studio version: The nmake command wasn't found.";
105-
while (<P>)
106-
{
107-
chomp;
108-
if (/(\d+)\.(\d+)\.\d+(\.\d+)?$/)
109-
{
110-
return _GetVisualStudioVersion($1, $2);
111-
}
112-
}
113-
close(P);
114-
}
115-
elsif ($nmakeVersion =~ /(\d+)\.(\d+)\.\d+(\.\d+)?$/)
95+
# To determine version of Visual Studio we use nmake as it has
96+
# existed for a long time and still exists in current Visual
97+
# Studio versions.
98+
my $output = `nmake /? 2>&1`;
99+
$? >> 8 == 0 or croak "Unable to determine Visual Studio version: The nmake command wasn't found.";
100+
if ($output =~ /(\d+)\.(\d+)\.\d+(\.\d+)?$/m)
116101
{
117102
return _GetVisualStudioVersion($1, $2);
118103
}
104+
119105
croak
120106
"Unable to determine Visual Studio version: The nmake version could not be determined.";
121107
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy