Re: Reduce the number of special cases to build contrib modules on windows
Alvaro Herrera <alvherre@alvh.no-ip.org>
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: David Rowley <dgrowleyml@gmail.com>
Cc: Andres Freund <andres@anarazel.de>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2020-11-09T14:06:58Z
Lists: pgsql-hackers
On 2020-Nov-06, David Rowley wrote:
> +# 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;
> + my ($ext) = $fname =~ /(\.[^.]+)$/;
> +
> + # For .c files, check if a .l file of the same name exists and add that
> + # too.
> + if ($ext eq ".c")
> + {
> + my $filenoext = $fname;
> + $filenoext =~ s{\.[^.]+$}{};
I think you can make this simpler by capturing both the basename and the
extension in one go. For example,
$fname =~ /(.*)(\.[^.]+)$/;
$filenoext = $1;
$ext = $2;
so you avoid the second =~ statement.
> + if (-e "$filenoext.l")
> + {
> + AddFileConditional($self, "$filenoext.l");
> + return 1;
> + }
> + if (-e "$filenoext.y")
> + {
> + AddFileConditional($self, "$filenoext.y");
Maybe DRY like
for my $ext (".l", ".y") {
my $file = $filenoext . $ext;
AddFileConditional($self, $file) if -f $file;
return 1;
}
Note: comment says "check if a .l file" and then checks both .l and .y.
Probably want to update the comment ...
Commits
-
Remove some special cases from MSVC build scripts
- 76ad24400d73 15.0 landed
-
Adjust MSVC build scripts to parse Makefiles for defines
- 245de48455da 15.0 landed
-
Don't duplicate references and libraries in MSVC scripts
- 15f16ec6511c 15.0 landed
-
Make the includes field an array in MSVC build scripts
- 33d74c5d00e4 15.0 landed
-
Use the AddFile function consistently in MSVC build scripts
- ed1884a2fede 15.0 landed
-
Remove seemingly unneeded include directory in MSVC scripts
- 4b763ff642e1 15.0 landed