Remove some special cases from MSVC build scripts
authorDavid Rowley
Mon, 9 Aug 2021 07:45:26 +0000 (19:45 +1200)
committerDavid Rowley
Mon, 9 Aug 2021 07:45:26 +0000 (19:45 +1200)
Here we add additional parsing of Makefiles to determine when to add
references to libpgport and libpgcommon.  We also remove the need for
adding the current contrib_extrasource by adding sine very basic logic to
implement the Makefile rules which add .l and .y files when they exist for
a given .o file in the Makefile.

This is just some very basic additional parsing of Makefiles to try to
keep things more consistent between builds using make and MSVC builds.
This happens to work with how our current Makefiles are laid out, but it
could easily be broken in the future if someone chooses do something in
the Makefile that we don't have parsing support for.  We will cross that
bridge when we come to it.

Author: David Rowley
Discussion: https://postgr.es/m/CAApHDvoPULi5JW3933NxgwxOmu9Ncvpcyt87UhEHAUX16QqmpA@mail.gmail.com

src/tools/msvc/Mkvcbuild.pm
src/tools/msvc/Project.pm

index aab559e3ef932ebe822d6ad6488cd51c7ccd3fcc..3cb46832abf7c20fd53dc195d7a5094af900739d 100644 (file)
@@ -36,16 +36,12 @@ my @unlink_on_exit;
 
 # Set of variables for modules in contrib/ and src/test/modules/
 my $contrib_defines = {};
-my @contrib_uselibpq =
-  ('dblink', 'oid2name', 'postgres_fdw', 'vacuumlo', 'libpq_pipeline');
-my @contrib_uselibpgport   = ('libpq_pipeline', 'oid2name', 'vacuumlo');
-my @contrib_uselibpgcommon = ('libpq_pipeline', 'oid2name', 'vacuumlo');
+my @contrib_uselibpq = ();
+my @contrib_uselibpgport   = ();
+my @contrib_uselibpgcommon = ();
 my $contrib_extralibs     = { 'libpq_pipeline' => ['ws2_32.lib'] };
-my $contrib_extraincludes = {};
-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',
@@ -1010,6 +1006,61 @@ sub AddContrib
                    $proj->AddDefine($1);
                }
            }
+           elsif ($flag =~ /^-I(.*)$/)
+           {
+               if ($1 eq '$(libpq_srcdir)')
+               {
+                   foreach my $proj (@projects)
+                   {
+                       $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->AddDependantFiles("$subdir/$n/$file");
+               }
+           }
        }
    }
 
index f1c93a3fa3224018066c67df3cd0109a4721f43c..aec922279df46b28aeec064d8600d6a5afe672c3 100644 (file)
@@ -47,10 +47,19 @@ sub AddFile
 {
    my ($self, $filename) = @_;
 
+   $self->FindAndAddAdditionalFiles($filename);
    $self->{files}->{$filename} = 1;
    return;
 }
 
+sub AddDependantFiles
+{
+   my ($self, $filename) = @_;
+
+   $self->FindAndAddAdditionalFiles($filename);
+   return;
+}
+
 sub AddFiles
 {
    my $self = shift;
@@ -63,6 +72,34 @@ sub AddFiles
    return;
 }
 
+# Handle Makefile rules by searching for other files which exist with the same
+# name but a different file extension and add those files too.
+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")
+   {
+       my $file = $filenoext . ".l";
+       if (-e $file)
+       {
+           $self->AddFile($file);
+       }
+
+       $file = $filenoext . ".y";
+       if (-e $file)
+       {
+           $self->AddFile($file);
+       }
+   }
+}
+
 sub ReplaceFile
 {
    my ($self, $filename, $newname) = @_;