summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut2020-02-21 19:50:56 +0000
committerPeter Eisentraut2020-02-21 19:57:43 +0000
commit73c8596488fd5fd619991f56dae5d22f551b06d9 (patch)
tree5769a86820cac42dcc79687d6b75fe463580b417
parentf4d59369d2ddf0ad7850112752ec42fd115825d4 (diff)
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 <[email protected]> Reviewed-by: Julien Rouhaud <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/d73b2c7b-f081-8357-8422-7564d55f1aac%402ndquadrant.com
-rw-r--r--src/tools/msvc/Mkvcbuild.pm6
-rw-r--r--src/tools/msvc/Project.pm2
-rw-r--r--src/tools/msvc/Solution.pm17
-rw-r--r--src/tools/msvc/VSObjectFactory.pm31
4 files changed, 36 insertions, 20 deletions
diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm
index 2e87d81172..d6fc1b7d54 100644
--- a/src/tools/msvc/Mkvcbuild.pm
+++ b/src/tools/msvc/Mkvcbuild.pm
@@ -6,7 +6,7 @@ package Mkvcbuild;
# src/tools/msvc/Mkvcbuild.pm
#
use Carp;
-use Win32;
+use if ($^O eq "MSWin32"), 'Win32';
use strict;
use warnings;
use Project;
@@ -648,9 +648,11 @@ sub mkvcbuild
# 'Can't spawn "conftest.exe"'; suppress that.
no warnings;
+ no strict 'subs';
+
# Disable error dialog boxes like we do in the postmaster.
# 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(
SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
system(".\\$exe");
diff --git a/src/tools/msvc/Project.pm b/src/tools/msvc/Project.pm
index 7d25704e2c..d90a996d46 100644
--- a/src/tools/msvc/Project.pm
+++ b/src/tools/msvc/Project.pm
@@ -22,7 +22,7 @@ sub _new
my $self = {
name => $name,
type => $type,
- guid => Win32::GuidGen(),
+ guid => $^O eq "MSWin32" ? Win32::GuidGen() : 'FAKE',
files => {},
references => [],
libraries => [],
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index a6b8b92c18..39470a869e 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -60,10 +60,17 @@ sub DeterminePlatform
{
my $self = shift;
- # Examine CL help output to determine if we are in 32 or 64-bit mode.
- my $output = `cl /? 2>&1`;
- $? >> 8 == 0 or die "cl command not found";
- $self->{platform} = ($output =~ /^\/favor:<.+AMD64/m) ? 'x64' : 'Win32';
+ if ($^O eq "MSWin32")
+ {
+ # Examine CL help output to determine if we are in 32 or 64-bit mode.
+ my $output = `cl /? 2>&1`;
+ $? >> 8 == 0 or die "cl command not found";
+ $self->{platform} = ($output =~ /^\/favor:<.+AMD64/m) ? 'x64' : 'Win32';
+ }
+ else
+ {
+ $self->{platform} = 'FAKE';
+ }
print "Detected hardware platform: $self->{platform}\n";
return;
}
@@ -1061,7 +1068,7 @@ EOF
}
if ($fld ne "")
{
- $flduid{$fld} = Win32::GuidGen();
+ $flduid{$fld} = $^O eq "MSWin32" ? Win32::GuidGen() : 'FAKE';
print $sln <<EOF;
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "$fld", "$fld", "$flduid{$fld}"
EndProject
diff --git a/src/tools/msvc/VSObjectFactory.pm b/src/tools/msvc/VSObjectFactory.pm
index 610dc61286..e6983b241f 100644
--- a/src/tools/msvc/VSObjectFactory.pm
+++ b/src/tools/msvc/VSObjectFactory.pm
@@ -111,21 +111,28 @@ sub CreateProject
sub DetermineVisualStudioVersion
{
+ if ($^O eq "MSWin32")
+ {
+ # 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);
+ }
- # 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)
+ croak
+ "Unable to determine Visual Studio version: The nmake version could not be determined.";
+ }
+ else
{
- return _GetVisualStudioVersion($1, $2);
+ # fake version
+ return '16.00';
}
-
- croak
- "Unable to determine Visual Studio version: The nmake version could not be determined.";
}
sub _GetVisualStudioVersion