On Wed, 30 Dec 2020 at 10:03, David Rowley <[email protected]> wrote:
>
> On Wed, 23 Dec 2020 at 18:46, Michael Paquier <[email protected]> wrote:
> > I have tested your patch, and this is causing compilation failures for
> > hstore_plpython, jsonb_plpython and ltree_plpython. So
> > AddTransformModule is missing something here when compiling with
> > Python.
>
> Oh thanks for finding that. That was due to some incorrect Perl code
> I'd written to add the includes from one project into another. Fixed
> by:
I accidentally attached the wrong patch before. Now attaching the correct one.
David
diff --git a/contrib/ltree/crc32.c b/contrib/ltree/crc32.c
index 8fed3346e8..b035706c05 100644
--- a/contrib/ltree/crc32.c
+++ b/contrib/ltree/crc32.c
@@ -9,7 +9,15 @@
#include "postgres.h"
-#ifdef LOWER_NODE
+/*
+ * Below we ignore the fact that LOWER_NODE is defined when compiling with
+ * MSVC. The reason for this is that earlier versions of the MSVC build
+ * scripts failed to define LOWER_NODE. More recent version of the MSVC
+ * build scripts parse makefiles which results in LOWER_NODE now being
+ * defined. We check for _MSC_VER here so as not to break pg_upgrade when
+ * upgrading from versions MSVC versions where LOWER_NODE was not defined.
+ */
+#if defined(LOWER_NODE) && !defined(_MSC_VER)
#include <ctype.h>
#define TOLOWER(x) tolower((unsigned char) (x))
#else
diff --git a/contrib/ltree/ltree.h b/contrib/ltree/ltree.h
index dc68a0c212..8c10384503 100644
--- a/contrib/ltree/ltree.h
+++ b/contrib/ltree/ltree.h
@@ -90,7 +90,15 @@ typedef struct
#define LQL_NOT 0x10 /* level has '!' (NOT) prefix */
#define LQL_COUNT 0x20 /* level is non-'*' and has repeat
counts */
-#ifdef LOWER_NODE
+/*
+ * Below we ignore the fact that LOWER_NODE is defined when compiling with
+ * MSVC. The reason for this is that earlier versions of the MSVC build
+ * scripts failed to define LOWER_NODE. More recent version of the MSVC
+ * build scripts parse makefiles which results in LOWER_NODE now being
+ * defined. We check for _MSC_VER here so as not to break pg_upgrade when
+ * upgrading from versions MSVC versions where LOWER_NODE was not defined.
+ */
+#if defined(LOWER_NODE) && !defined(_MSC_VER)
#define FLG_CANLOOKSIGN(x) ( ( (x) & ( LQL_NOT | LVAR_ANYEND | LVAR_SUBLEXEME
) ) == 0 )
#else
#define FLG_CANLOOKSIGN(x) ( ( (x) & ( LQL_NOT | LVAR_ANYEND | LVAR_SUBLEXEME
| LVAR_INCASE ) ) == 0 )
diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index ebb169e201..2cf3fee65d 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -109,15 +109,13 @@ sub AddDefine
sub WriteReferences
{
my ($self, $f) = @_;
-
- my @references = @{ $self->{references} };
-
- if (scalar(@references))
+ # Add referenced projects, if any exist.
+ if (scalar(keys % { $self->{references} }) > 0)
{
print $f <<EOF;
<ItemGroup>
EOF
- foreach my $ref (@references)
+ foreach my $ref (values % { $self->{references} } )
{
print $f <<EOF;
<ProjectReference Include="$ref->{name}$ref->{filenameExtension}">
@@ -310,11 +308,12 @@ sub WriteItemDefinitionGroup
my $targetmachine =
$self->{platform} eq 'Win32' ? 'MachineX86' : 'MachineX64';
- my $includes = $self->{includes};
- unless ($includes eq '' or $includes =~ /;$/)
+ my $includes = "";
+ foreach my $inc (keys %{ $self->{includes} } )
{
- $includes .= ';';
+ $includes .= $inc . ";";
}
+
print $f <<EOF;
<ItemDefinitionGroup
Condition="'\$(Configuration)|\$(Platform)'=='$cfgname|$self->{platform}'">
<ClCompile>
diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm
index f92c14030d..e43978ca17 100644
--- a/src/tools/msvc/Mkvcbuild.pm
+++ b/src/tools/msvc/Mkvcbuild.pm
@@ -32,16 +32,13 @@ my $libpq;
my @unlink_on_exit;
# Set of variables for modules in contrib/ and src/test/modules/
-my $contrib_defines = { 'refint' => 'REFINT_VERBOSE' };
-my @contrib_uselibpq = ('dblink', 'oid2name', 'postgres_fdw', 'vacuumlo');
-my @contrib_uselibpgport = ('oid2name', 'pg_standby', 'vacuumlo');
-my @contrib_uselibpgcommon = ('oid2name', 'pg_standby', 'vacuumlo');
+my $contrib_defines = {};
+my @contrib_uselibpq = ();
+my @contrib_uselibpgport = ('pg_standby');
+my @contrib_uselibpgcommon = ('pg_standby');
my $contrib_extralibs = undef;
-my $contrib_extraincludes = { 'dblink' => ['src/backend'] };
-my $contrib_extrasource = {
- 'cube' => [ 'contrib/cube/cubescan.l', 'contrib/cube/cubeparse.y' ],
- 'seg' => [ 'contrib/seg/segscan.l', 'contrib/seg/segparse.y' ],
-};
+my $contrib_extraincludes = {};
+my $contrib_extrasource = {};
my @contrib_excludes = (
'bool_plperl', 'commit_ts',
'hstore_plperl', 'hstore_plpython',
@@ -925,8 +922,12 @@ sub AddTransformModule
# Add PL dependencies
$p->AddIncludeDir($pl_src);
$p->AddReference($pl_proj);
- $p->AddIncludeDir($pl_proj->{includes});
- foreach my $pl_lib (@{ $pl_proj->{libraries} })
+ foreach my $inc (keys %{ $pl_proj->{includes} } )
+ {
+ $p->AddIncludeDir($inc);
+ }
+
+ foreach my $pl_lib (keys %{ $pl_proj->{libraries} } )
{
$p->AddLibrary($pl_lib);
}
@@ -935,8 +936,11 @@ sub AddTransformModule
if ($type_proj)
{
$p->AddIncludeDir($type_src);
- $p->AddIncludeDir($type_proj->{includes});
- foreach my $type_lib (@{ $type_proj->{libraries} })
+ foreach my $inc (keys %{ $type_proj->{includes} } )
+ {
+ $p->AddIncludeDir($inc);
+ }
+ foreach my $type_lib (keys %{ $type_proj->{libraries} } )
{
$p->AddLibrary($type_lib);
}
@@ -952,6 +956,7 @@ sub AddContrib
my $subdir = shift;
my $n = shift;
my $mf = Project::read_file("$subdir/$n/Makefile");
+ my @projects;
if ($mf =~ /^MODULE_big\s*=\s*(.*)$/mg)
{
@@ -959,6 +964,7 @@ sub AddContrib
my $proj = $solution->AddProject($dn, 'dll', 'contrib',
"$subdir/$n");
$proj->AddReference($postgres);
AdjustContribProj($proj);
+ push @projects, $proj;
}
elsif ($mf =~ /^MODULES\s*=\s*(.*)$/mg)
{
@@ -970,18 +976,90 @@ sub AddContrib
$proj->AddFile("$subdir/$n/$filename");
$proj->AddReference($postgres);
AdjustContribProj($proj);
+ push @projects, $proj;
}
}
elsif ($mf =~ /^PROGRAM\s*=\s*(.*)$/mg)
{
my $proj = $solution->AddProject($1, 'exe', 'contrib',
"$subdir/$n");
AdjustContribProj($proj);
+ push @projects, $proj;
}
else
{
croak "Could not determine contrib module type for $n\n";
}
+ # Process custom compiler flags
+ if ($mf =~ /^PG_CPPFLAGS\s*=\s*(.*)$/mg || $mf =~
/^override\s*CPPFLAGS\s*(?:[\+\:])?=\s*(.*)$/mg)
+ {
+ foreach my $flag (split /\s+/, $1)
+ {
+ if ($flag =~ /^-D(.*)$/)
+ {
+ foreach my $proj (@projects)
+ {
+ $proj->AddDefine($1);
+ }
+ }
+ elsif ($flag =~ /^-I(.*)$/)
+ {
+ foreach my $proj (@projects)
+ {
+ if ($1 eq '$(libpq_srcdir)')
+ {
+
$proj->AddIncludeDir('src\interfaces\libpq');
+ $proj->AddReference($libpq);
+ }
+ }
+ }
+ }
+ }
+
+ if ($mf =~ /^SHLIB_LINK_INTERNAL\s*=\s*(.*)$/mg)
+ {
+ foreach my $lib (split /\s+/, $1)
+ {
+ if ($lib eq '$(libpq)')
+ {
+ foreach my $proj (@projects)
+ {
+
$proj->AddIncludeDir('src\interfaces\libpq');
+ $proj->AddReference($libpq);
+ }
+ }
+ }
+ }
+
+ if ($mf =~ /^PG_LIBS_INTERNAL\s*=\s*(.*)$/mg)
+ {
+ foreach my $lib (split /\s+/, $1)
+ {
+ if ($lib eq '$(libpq_pgport)')
+ {
+ foreach my $proj (@projects)
+ {
+ $proj->AddReference($libpgport);
+ $proj->AddReference($libpgcommon);
+ }
+ }
+ }
+ }
+
+ foreach my $line (split /\n/, $mf)
+ {
+ if ($line =~ /^[A-Za-z0-9_]*\.o:\s(.*)/)
+ {
+ foreach my $file (split /\s+/, $1)
+ {
+ foreach my $proj (@projects)
+ {
+
$proj->AddFileConditional("$subdir/$n/$file");
+ }
+ }
+ }
+ }
+
# Are there any output data files to build?
GenerateContribSqlFiles($n, $mf);
return;
diff --git a/src/tools/msvc/Project.pm b/src/tools/msvc/Project.pm
index 20f79b382b..ad9e4b6dcc 100644
--- a/src/tools/msvc/Project.pm
+++ b/src/tools/msvc/Project.pm
@@ -24,10 +24,10 @@ sub _new
type => $type,
guid => $^O eq "MSWin32" ? Win32::GuidGen() :
'FAKE',
files => {},
- references => [],
- libraries => [],
+ references => {},
+ libraries => {},
suffixlib => [],
- includes => '',
+ includes => {},
prefixincludes => '',
defines => ';',
solution => $solution,
@@ -42,12 +42,25 @@ sub _new
sub AddFile
{
- my ($self, $filename) = @_;
+ my ($self, $filename, $alwaysAddOriginal) = @_;
+ FindAndAddAdditionalFiles($self, $filename);
+ # Add the original file regardless to the return value of
+ # FindAndAddAdditionalFiles
$self->{files}->{$filename} = 1;
return;
}
+sub AddFileConditional
+{
+ my ($self, $filename) = @_;
+ if (FindAndAddAdditionalFiles($self, $filename) != 1)
+ {
+ $self->{files}->{$filename} = 1;
+ }
+ return;
+}
+
sub AddFiles
{
my $self = shift;
@@ -55,11 +68,39 @@ sub AddFiles
while (my $f = shift)
{
- $self->{files}->{ $dir . "/" . $f } = 1;
+ AddFile($self, $dir . "/" . $f, 1);
}
return;
}
+# Handle makefile rules for when file to be added to the project
+# does not exist. Returns 1 when the original file add should be
+# skipped.
+sub FindAndAddAdditionalFiles
+{
+ my $self = shift;
+ my $fname = shift;
+ $fname =~ /(.*)(\.[^.]+)$/;
+ my $filenoext = $1;
+ my $fileext = $2;
+
+ # For .c files, check if either a .l or .y file of the same name
+ # exists and add that too.
+ if ($fileext eq ".c")
+ {
+ for my $ext (".l", ".y")
+ {
+ my $file = $filenoext . $ext;
+ if (-e $file)
+ {
+ AddFileConditional($self, $file);
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
+
sub ReplaceFile
{
my ($self, $filename, $newname) = @_;
@@ -74,14 +115,14 @@ sub ReplaceFile
if ($file eq $filename)
{
delete $self->{files}{$file};
- $self->{files}{$newname} = 1;
+ AddFile($self, $newname);
return;
}
}
elsif ($file =~ m/($re)/)
{
delete $self->{files}{$file};
- $self->{files}{"$newname/$filename"} = 1;
+ AddFile($self, "$newname/$filename");
return;
}
}
@@ -121,7 +162,8 @@ sub AddReference
while (my $ref = shift)
{
- push @{ $self->{references} }, $ref;
+ my $name = $ref->{name};
+ $self->{references}->{$name} = $ref;
$self->AddLibrary(
"__CFGNAME__/" . $ref->{name} . "/" . $ref->{name} .
".lib");
}
@@ -138,7 +180,7 @@ sub AddLibrary
$lib = '"' . $lib . """;
}
- push @{ $self->{libraries} }, $lib;
+ $self->{libraries}->{$lib} = 1;
if ($dbgsuffix)
{
push @{ $self->{suffixlib} }, $lib;
@@ -148,13 +190,12 @@ sub AddLibrary
sub AddIncludeDir
{
- my ($self, $inc) = @_;
+ my ($self, $incstr) = @_;
- if ($self->{includes} ne '')
+ foreach my $inc (split(/;/, $incstr))
{
- $self->{includes} .= ';';
+ $self->{includes}->{$inc} = 1;
}
- $self->{includes} .= $inc;
return;
}
@@ -256,11 +297,11 @@ sub AddDir
if ($f =~ /^\$\(top_builddir\)\/(.*)/)
{
$f = $1;
- $self->{files}->{$f} = 1;
+ AddFile($self, $f);
}
else
{
- $self->{files}->{"$reldir/$f"} = 1;
+ AddFile($self, "$reldir/$f");
}
}
$mf =~ s{OBJS[^=]*=\s*(.*)$}{}m;
@@ -397,7 +438,7 @@ sub GetAdditionalLinkerDependencies
my ($self, $cfgname, $separator) = @_;
my $libcfg = (uc $cfgname eq "RELEASE") ? "MD" : "MDd";
my $libs = '';
- foreach my $lib (@{ $self->{libraries} })
+ foreach my $lib (keys %{ $self->{libraries} })
{
my $xlib = $lib;
foreach my $slib (@{ $self->{suffixlib} })