Commit 73c85964 authored by Peter Eisentraut's avatar Peter Eisentraut

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: default avatarMichael Paquier <michael@paquier.xyz>
Reviewed-by: default avatarJulien Rouhaud <rjuju123@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/d73b2c7b-f081-8357-8422-7564d55f1aac%402ndquadrant.com
parent f4d59369
...@@ -6,7 +6,7 @@ package Mkvcbuild; ...@@ -6,7 +6,7 @@ package Mkvcbuild;
# src/tools/msvc/Mkvcbuild.pm # src/tools/msvc/Mkvcbuild.pm
# #
use Carp; use Carp;
use Win32; use if ($^O eq "MSWin32"), 'Win32';
use strict; use strict;
use warnings; use warnings;
use Project; use Project;
...@@ -648,9 +648,11 @@ sub mkvcbuild ...@@ -648,9 +648,11 @@ sub mkvcbuild
# 'Can't spawn "conftest.exe"'; suppress that. # 'Can't spawn "conftest.exe"'; suppress that.
no warnings; no warnings;
no strict 'subs';
# Disable error dialog boxes like we do in the postmaster. # Disable error dialog boxes like we do in the postmaster.
# Here, we run code that triggers relevant errors. # Here, we run code that triggers relevant errors.
use Win32API::File qw(SetErrorMode :SEM_); use if ($^O eq "MSWin32"), 'Win32API::File', qw(SetErrorMode :SEM_);
my $oldmode = SetErrorMode( my $oldmode = SetErrorMode(
SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
system(".\\$exe"); system(".\\$exe");
......
...@@ -22,7 +22,7 @@ sub _new ...@@ -22,7 +22,7 @@ sub _new
my $self = { my $self = {
name => $name, name => $name,
type => $type, type => $type,
guid => Win32::GuidGen(), guid => $^O eq "MSWin32" ? Win32::GuidGen() : 'FAKE',
files => {}, files => {},
references => [], references => [],
libraries => [], libraries => [],
......
...@@ -60,10 +60,17 @@ sub DeterminePlatform ...@@ -60,10 +60,17 @@ sub DeterminePlatform
{ {
my $self = shift; my $self = shift;
if ($^O eq "MSWin32")
{
# Examine CL help output to determine if we are in 32 or 64-bit mode. # Examine CL help output to determine if we are in 32 or 64-bit mode.
my $output = `cl /? 2>&1`; my $output = `cl /? 2>&1`;
$? >> 8 == 0 or die "cl command not found"; $? >> 8 == 0 or die "cl command not found";
$self->{platform} = ($output =~ /^\/favor:<.+AMD64/m) ? 'x64' : 'Win32'; $self->{platform} = ($output =~ /^\/favor:<.+AMD64/m) ? 'x64' : 'Win32';
}
else
{
$self->{platform} = 'FAKE';
}
print "Detected hardware platform: $self->{platform}\n"; print "Detected hardware platform: $self->{platform}\n";
return; return;
} }
...@@ -1061,7 +1068,7 @@ EOF ...@@ -1061,7 +1068,7 @@ EOF
} }
if ($fld ne "") if ($fld ne "")
{ {
$flduid{$fld} = Win32::GuidGen(); $flduid{$fld} = $^O eq "MSWin32" ? Win32::GuidGen() : 'FAKE';
print $sln <<EOF; print $sln <<EOF;
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "$fld", "$fld", "$flduid{$fld}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "$fld", "$fld", "$flduid{$fld}"
EndProject EndProject
......
...@@ -111,7 +111,8 @@ sub CreateProject ...@@ -111,7 +111,8 @@ sub CreateProject
sub DetermineVisualStudioVersion sub DetermineVisualStudioVersion
{ {
if ($^O eq "MSWin32")
{
# To determine version of Visual Studio we use nmake as it has # To determine version of Visual Studio we use nmake as it has
# existed for a long time and still exists in current Visual # existed for a long time and still exists in current Visual
# Studio versions. # Studio versions.
...@@ -126,6 +127,12 @@ sub DetermineVisualStudioVersion ...@@ -126,6 +127,12 @@ sub DetermineVisualStudioVersion
croak croak
"Unable to determine Visual Studio version: The nmake version could not be determined."; "Unable to determine Visual Studio version: The nmake version could not be determined.";
}
else
{
# fake version
return '16.00';
}
} }
sub _GetVisualStudioVersion sub _GetVisualStudioVersion
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment