Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 73c8596

Browse files
committed
Allow running src/tools/msvc/mkvcbuild.pl under not Windows
This to allow verifying the MSVC build file generation without having to have Windows. To do this, we avoid Windows-specific Perl modules and don't run the "cl" compiler or "nmake". The resulting build files won't actually be completely correct, but it's useful enough. Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Julien Rouhaud <rjuju123@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/d73b2c7b-f081-8357-8422-7564d55f1aac%402ndquadrant.com
1 parent f4d5936 commit 73c8596

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

src/tools/msvc/Mkvcbuild.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package Mkvcbuild;
66
# src/tools/msvc/Mkvcbuild.pm
77
#
88
use Carp;
9-
use Win32;
9+
use if ($^O eq "MSWin32"), 'Win32';
1010
use strict;
1111
use warnings;
1212
use Project;
@@ -648,9 +648,11 @@ sub mkvcbuild
648648
# 'Can't spawn "conftest.exe"'; suppress that.
649649
no warnings;
650650

651+
no strict 'subs';
652+
651653
# Disable error dialog boxes like we do in the postmaster.
652654
# Here, we run code that triggers relevant errors.
653-
use Win32API::File qw(SetErrorMode :SEM_);
655+
use if ($^O eq "MSWin32"), 'Win32API::File', qw(SetErrorMode :SEM_);
654656
my $oldmode = SetErrorMode(
655657
SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
656658
system(".\\$exe");

src/tools/msvc/Project.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ sub _new
2222
my $self = {
2323
name => $name,
2424
type => $type,
25-
guid => Win32::GuidGen(),
25+
guid => $^O eq "MSWin32" ? Win32::GuidGen() : 'FAKE',
2626
files => {},
2727
references => [],
2828
libraries => [],

src/tools/msvc/Solution.pm

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,17 @@ sub DeterminePlatform
6060
{
6161
my $self = shift;
6262

63-
# Examine CL help output to determine if we are in 32 or 64-bit mode.
64-
my $output = `cl /? 2>&1`;
65-
$? >> 8 == 0 or die "cl command not found";
66-
$self->{platform} = ($output =~ /^\/favor:<.+AMD64/m) ? 'x64' : 'Win32';
63+
if ($^O eq "MSWin32")
64+
{
65+
# Examine CL help output to determine if we are in 32 or 64-bit mode.
66+
my $output = `cl /? 2>&1`;
67+
$? >> 8 == 0 or die "cl command not found";
68+
$self->{platform} = ($output =~ /^\/favor:<.+AMD64/m) ? 'x64' : 'Win32';
69+
}
70+
else
71+
{
72+
$self->{platform} = 'FAKE';
73+
}
6774
print "Detected hardware platform: $self->{platform}\n";
6875
return;
6976
}
@@ -1061,7 +1068,7 @@ EOF
10611068
}
10621069
if ($fld ne "")
10631070
{
1064-
$flduid{$fld} = Win32::GuidGen();
1071+
$flduid{$fld} = $^O eq "MSWin32" ? Win32::GuidGen() : 'FAKE';
10651072
print $sln <<EOF;
10661073
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "$fld", "$fld", "$flduid{$fld}"
10671074
EndProject

src/tools/msvc/VSObjectFactory.pm

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,28 @@ sub CreateProject
111111

112112
sub DetermineVisualStudioVersion
113113
{
114+
if ($^O eq "MSWin32")
115+
{
116+
# To determine version of Visual Studio we use nmake as it has
117+
# existed for a long time and still exists in current Visual
118+
# Studio versions.
119+
my $output = `nmake /? 2>&1`;
120+
$? >> 8 == 0
121+
or croak
122+
"Unable to determine Visual Studio version: The nmake command wasn't found.";
123+
if ($output =~ /(\d+)\.(\d+)\.\d+(\.\d+)?$/m)
124+
{
125+
return _GetVisualStudioVersion($1, $2);
126+
}
114127

115-
# To determine version of Visual Studio we use nmake as it has
116-
# existed for a long time and still exists in current Visual
117-
# Studio versions.
118-
my $output = `nmake /? 2>&1`;
119-
$? >> 8 == 0
120-
or croak
121-
"Unable to determine Visual Studio version: The nmake command wasn't found.";
122-
if ($output =~ /(\d+)\.(\d+)\.\d+(\.\d+)?$/m)
128+
croak
129+
"Unable to determine Visual Studio version: The nmake version could not be determined.";
130+
}
131+
else
123132
{
124-
return _GetVisualStudioVersion($1, $2);
133+
# fake version
134+
return '16.00';
125135
}
126-
127-
croak
128-
"Unable to determine Visual Studio version: The nmake version could not be determined.";
129136
}
130137

131138
sub _GetVisualStudioVersion

0 commit comments

Comments
 (0)