]> granicus.if.org Git - postgresql/blob - src/tools/msvc/VSObjectFactory.pm
Fix initialization of fake LSN for unlogged relations
[postgresql] / src / tools / msvc / VSObjectFactory.pm
1 package VSObjectFactory;
2
3 #
4 # Package that creates Visual Studio wrapper objects for msvc build
5 #
6 # src/tools/msvc/VSObjectFactory.pm
7 #
8
9 use Carp;
10 use strict;
11 use warnings;
12
13 use Exporter;
14 use Project;
15 use Solution;
16 use MSBuildProject;
17
18 our (@ISA, @EXPORT);
19 @ISA    = qw(Exporter);
20 @EXPORT = qw(CreateSolution CreateProject DetermineVisualStudioVersion);
21
22 no warnings qw(redefine);    ## no critic
23
24 sub CreateSolution
25 {
26         my $visualStudioVersion = shift;
27
28         if (!defined($visualStudioVersion))
29         {
30                 $visualStudioVersion = DetermineVisualStudioVersion();
31         }
32
33         if ($visualStudioVersion eq '12.00')
34         {
35                 return new VS2013Solution(@_);
36         }
37         elsif ($visualStudioVersion eq '14.00')
38         {
39                 return new VS2015Solution(@_);
40         }
41
42         # The version of nmake bundled in Visual Studio 2017 is greater
43         # than 14.10 and less than 14.20.  And the version number is
44         # actually 15.00.
45         elsif (
46                 ($visualStudioVersion ge '14.10' && $visualStudioVersion lt '14.20')
47                 || $visualStudioVersion eq '15.00')
48         {
49                 return new VS2017Solution(@_);
50         }
51
52         # The version of nmake bundled in Visual Studio 2019 is greater
53         # than 14.20 and less than 14.30.  And the version number is
54         # actually 16.00.
55         elsif (
56                 ($visualStudioVersion ge '14.20' && $visualStudioVersion lt '14.30')
57                 || $visualStudioVersion eq '16.00')
58         {
59                 return new VS2019Solution(@_);
60         }
61         else
62         {
63                 croak
64                   "The requested Visual Studio version $visualStudioVersion is not supported.";
65         }
66 }
67
68 sub CreateProject
69 {
70         my $visualStudioVersion = shift;
71
72         if (!defined($visualStudioVersion))
73         {
74                 $visualStudioVersion = DetermineVisualStudioVersion();
75         }
76
77         if ($visualStudioVersion eq '12.00')
78         {
79                 return new VC2013Project(@_);
80         }
81         elsif ($visualStudioVersion eq '14.00')
82         {
83                 return new VC2015Project(@_);
84         }
85
86         # The version of nmake bundled in Visual Studio 2017 is greater
87         # than 14.10 and less than 14.20.  And the version number is
88         # actually 15.00.
89         elsif (
90                 ($visualStudioVersion ge '14.10' && $visualStudioVersion lt '14.20')
91                 || $visualStudioVersion eq '15.00')
92         {
93                 return new VC2017Project(@_);
94         }
95
96         # The version of nmake bundled in Visual Studio 2019 is greater
97         # than 14.20 and less than 14.30.  And the version number is
98         # actually 16.00.
99         elsif (
100                 ($visualStudioVersion ge '14.20' && $visualStudioVersion lt '14.30')
101                 || $visualStudioVersion eq '16.00')
102         {
103                 return new VC2019Project(@_);
104         }
105         else
106         {
107                 croak
108                   "The requested Visual Studio version $visualStudioVersion is not supported.";
109         }
110 }
111
112 sub DetermineVisualStudioVersion
113 {
114
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)
123         {
124                 return _GetVisualStudioVersion($1, $2);
125         }
126
127         croak
128           "Unable to determine Visual Studio version: The nmake version could not be determined.";
129 }
130
131 sub _GetVisualStudioVersion
132 {
133         my ($major, $minor) = @_;
134
135         # The major visual studio that is supported has nmake
136         # version <= 14.30, so stick with it as the latest version
137         # if bumping on something even newer.
138         if ($major >= 14 && $minor >= 30)
139         {
140                 carp
141                   "The determined version of Visual Studio is newer than the latest supported version. Returning the latest supported version instead.";
142                 return '14.20';
143         }
144         elsif ($major < 12)
145         {
146                 croak
147                   "Unable to determine Visual Studio version: Visual Studio versions before 12.0 aren't supported.";
148         }
149         return "$major.$minor";
150 }
151
152 1;