agora inbox for [email protected]  
help / color / mirror / Atom feed
[PATCH v13 04/20] meson: prereq: Extend gendef.pl in preparation for meson
5+ messages / 2 participants
[nested] [flat]

* [PATCH v13 04/20] meson: prereq: Extend gendef.pl in preparation for meson
@ 2022-08-09 07:29 Andres Freund <[email protected]>
  0 siblings, 0 replies; 5+ messages in thread

From: Andres Freund @ 2022-08-09 07:29 UTC (permalink / raw)

The main issue with using gendef.pl as is for meson is that with meson the
filenames are a bit longer, exceeding the max commandline length when calling
dumpbin with all objects. It's easier to pass a library in anyway.

The .def file location, input and temporary file location need to be tunable
as well.

This also fixes a bug in gendef.pl: The logic when to regenerate was broken
and never avoid regenerating.

Author: Andres Freund <[email protected]>
Reviewed-By: Peter Eisentraut <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Discussion: https://postgr.es/m/[email protected]
---
 src/tools/msvc/MSBuildProject.pm |  4 +-
 src/tools/msvc/gendef.pl         | 67 ++++++++++++++++++++++----------
 2 files changed, 49 insertions(+), 22 deletions(-)

diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index 594729ceb7d..58590fdac29 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -312,6 +312,8 @@ sub WriteItemDefinitionGroup
 
 	my $targetmachine =
 	  $self->{platform} eq 'Win32' ? 'MachineX86' : 'MachineX64';
+	my $arch =
+	  $self->{platform} eq 'Win32' ? 'x86' : 'x86_64';
 
 	my $includes = join ';', @{ $self->{includes} }, "";
 
@@ -380,7 +382,7 @@ EOF
 		print $f <<EOF;
     <PreLinkEvent>
       <Message>Generate DEF file</Message>
-      <Command>perl src\\tools\\msvc\\gendef.pl $cfgname\\$self->{name} $self->{platform}</Command>
+      <Command>perl src\\tools\\msvc\\gendef.pl --arch $arch --deffile $cfgname\\$self->{name}\\$self->{name}.def $cfgname\\$self->{name}</Command>
     </PreLinkEvent>
 EOF
 	}
diff --git a/src/tools/msvc/gendef.pl b/src/tools/msvc/gendef.pl
index b4af3dea81b..d6bed1ce151 100644
--- a/src/tools/msvc/gendef.pl
+++ b/src/tools/msvc/gendef.pl
@@ -3,7 +3,8 @@
 
 use strict;
 use warnings;
-use List::Util qw(max);
+use List::Util qw(min);
+use Getopt::Long;
 
 my @def;
 
@@ -112,7 +113,7 @@ sub extract_syms
 
 sub writedef
 {
-	my ($deffile, $platform, $def) = @_;
+	my ($deffile, $arch, $def) = @_;
 	open(my $fh, '>', $deffile) || die "Could not write to $deffile\n";
 	print $fh "EXPORTS\n";
 	foreach my $f (sort keys %{$def})
@@ -121,7 +122,7 @@ sub writedef
 
 		# Strip the leading underscore for win32, but not x64
 		$f =~ s/^_//
-		  unless ($platform eq "x64");
+		  unless ($arch eq "x86_64");
 
 		# Emit just the name if it's a function symbol, or emit the name
 		# decorated with the DATA option for variables.
@@ -141,40 +142,64 @@ sub writedef
 
 sub usage
 {
-	die(    "Usage: gendef.pl <modulepath> <platform>\n"
-		  . "    modulepath: path to dir with obj files, no trailing slash"
-		  . "    platform: Win32 | x64");
+	die("Usage: gendef.pl --arch <arch> --deffile <deffile> --tempdir <tempdir> files-or-directories\n"
+		  . "    arch: x86 | x86_64\n"
+		  . "    deffile: path of the generated file\n"
+		  . "    tempdir: directory for temporary files\n"
+		  . "    files or directories: object files or directory containing object files\n"
+	);
 }
 
-usage()
-  unless scalar(@ARGV) == 2
-  && ( ($ARGV[0] =~ /\\([^\\]+$)/)
-	&& ($ARGV[1] eq 'Win32' || $ARGV[1] eq 'x64'));
-my $defname  = uc $1;
-my $deffile  = "$ARGV[0]/$defname.def";
-my $platform = $ARGV[1];
+my $arch;
+my $deffile;
+my $tempdir = '.';
+
+GetOptions(
+	'arch:s'    => \$arch,
+	'deffile:s' => \$deffile,
+	'tempdir:s' => \$tempdir,) or usage();
+
+usage("arch: $arch")
+  unless ($arch eq 'x86' || $arch eq 'x86_64');
+
+my @files;
+
+foreach my $in (@ARGV)
+{
+	if (-d $in)
+	{
+		push @files, glob "$in/*.obj";
+	}
+	else
+	{
+		push @files, $in;
+	}
+}
 
 # if the def file exists and is newer than all input object files, skip
 # its creation
 if (-f $deffile
-	&& (-M $deffile > max(map { -M } <$ARGV[0]/*.obj>)))
+	&& (-M $deffile < min(map { -M } @files)))
 {
-	print "Not re-generating $defname.DEF, file already exists.\n";
+	print "Not re-generating $deffile, file already exists.\n";
 	exit(0);
 }
 
-print "Generating $defname.DEF from directory $ARGV[0], platform $platform\n";
+print "Generating $deffile in tempdir $tempdir\n";
 
 my %def = ();
 
-my $symfile = "$ARGV[0]/all.sym";
-my $tmpfile = "$ARGV[0]/tmp.sym";
-system("dumpbin /symbols /out:$tmpfile $ARGV[0]/*.obj >NUL")
-  && die "Could not call dumpbin";
+my $symfile = "$tempdir/all.sym";
+my $tmpfile = "$tempdir/tmp.sym";
+mkdir($tempdir) unless -d $tempdir;
+
+my $cmd = "dumpbin /nologo /symbols /out:$tmpfile " . join(' ', @files);
+
+system($cmd) && die "Could not call dumpbin";
 rename($tmpfile, $symfile);
 extract_syms($symfile, \%def);
 print "\n";
 
-writedef($deffile, $platform, \%def);
+writedef($deffile, $arch, \%def);
 
 print "Generated " . scalar(keys(%def)) . " symbols\n";
-- 
2.37.3.542.gdd3f6c4cae


--4uoxke3bx6ymzqvl
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v13-0005-meson-prereq-Add-src-tools-gen_export.pl.patch"



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* [PATCH v11 3/9] meson: prereq: Extend gendef.pl in preparation for meson
@ 2022-08-09 07:29 Andres Freund <[email protected]>
  0 siblings, 0 replies; 5+ messages in thread

From: Andres Freund @ 2022-08-09 07:29 UTC (permalink / raw)

The main issue with using gendef.pl as is for meson is that with meson the
filenames are a bit longer, exceeding the max commandline length when calling
dumpbin with all objects. It's easier to pass a library in anyway.

The .def file location, input and temporary file location need to be tunable
as well.

This also fixes a bug in gendef.pl: The logic when to regenerate was broken
and never avoid regenerating.

Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:
---
 src/tools/msvc/MSBuildProject.pm |  4 +-
 src/tools/msvc/gendef.pl         | 72 ++++++++++++++++++++++----------
 2 files changed, 54 insertions(+), 22 deletions(-)

diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index 62acdda3a19..3581fa4a123 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -312,6 +312,8 @@ sub WriteItemDefinitionGroup
 
 	my $targetmachine =
 	  $self->{platform} eq 'Win32' ? 'MachineX86' : 'MachineX64';
+	my $arch =
+	  $self->{platform} eq 'Win32' ? 'x86' : 'x86_64';
 
 	my $includes = join ';', @{ $self->{includes} }, "";
 
@@ -381,7 +383,7 @@ EOF
 		print $f <<EOF;
     <PreLinkEvent>
       <Message>Generate DEF file</Message>
-      <Command>perl src\\tools\\msvc\\gendef.pl $cfgname\\$self->{name} $self->{platform}</Command>
+      <Command>perl src\\tools\\msvc\\gendef.pl --arch $arch --deffile $cfgname\\$self->{name}\\$self->{name}.def $cfgname\\$self->{name}</Command>
     </PreLinkEvent>
 EOF
 	}
diff --git a/src/tools/msvc/gendef.pl b/src/tools/msvc/gendef.pl
index b8c514a8311..1e25c0e4d38 100644
--- a/src/tools/msvc/gendef.pl
+++ b/src/tools/msvc/gendef.pl
@@ -4,7 +4,8 @@
 use strict;
 use warnings;
 use 5.8.0;
-use List::Util qw(max);
+use List::Util qw(min);
+use Getopt::Long;
 
 my @def;
 
@@ -113,7 +114,7 @@ sub extract_syms
 
 sub writedef
 {
-	my ($deffile, $platform, $def) = @_;
+	my ($deffile, $arch, $def) = @_;
 	open(my $fh, '>', $deffile) || die "Could not write to $deffile\n";
 	print $fh "EXPORTS\n";
 	foreach my $f (sort keys %{$def})
@@ -122,7 +123,7 @@ sub writedef
 
 		# Strip the leading underscore for win32, but not x64
 		$f =~ s/^_//
-		  unless ($platform eq "x64");
+		  unless ($arch eq "x86_64");
 
 		# Emit just the name if it's a function symbol, or emit the name
 		# decorated with the DATA option for variables.
@@ -142,40 +143,69 @@ sub writedef
 
 sub usage
 {
-	die(    "Usage: gendef.pl <modulepath> <platform>\n"
-		  . "    modulepath: path to dir with obj files, no trailing slash"
-		  . "    platform: Win32 | x64");
+	my $add = shift;
+
+	die(    "Usage: gendef.pl --arch <arch> --deffile <deffile> --tempdir <tempdir> files or directories\n"
+		  . "    arch: x86 | x86_64\n"
+		  . "    outfile: \n"
+		  . "    tempdir: directory for temporary objects\n"
+		  . "    $add\n"
+	  );
 }
 
-usage()
-  unless scalar(@ARGV) == 2
-  && ( ($ARGV[0] =~ /\\([^\\]+$)/)
-	&& ($ARGV[1] eq 'Win32' || $ARGV[1] eq 'x64'));
-my $defname  = uc $1;
-my $deffile  = "$ARGV[0]/$defname.def";
-my $platform = $ARGV[1];
+my $arch;
+my $deffile;
+my $tempdir = '.';
+
+GetOptions(
+	'arch:s'   => \$arch,
+	'deffile:s'    => \$deffile,
+	'tempdir:s' => \$tempdir,
+  ) or die 'bluebeard';
+
+usage("arch: $arch") unless
+  ($arch eq 'x86' || $arch eq 'x86_64');
+
+print join(' ', @ARGV)."\n";
+
+my @files;
+
+foreach my $in (@ARGV)
+{
+	if (-d $in)
+	{
+		push @files, <$in/*.obj>;
+	}
+	else
+	{
+		push @files, $in;
+	}
+}
 
 # if the def file exists and is newer than all input object files, skip
 # its creation
 if (-f $deffile
-	&& (-M $deffile > max(map { -M } <$ARGV[0]/*.obj>)))
+	&& (-M $deffile < min(map { -M } @files)))
 {
-	print "Not re-generating $defname.DEF, file already exists.\n";
+	print "Not re-generating $deffile, file already exists.\n";
 	exit(0);
 }
 
-print "Generating $defname.DEF from directory $ARGV[0], platform $platform\n";
+print STDERR "Generating $deffile in tempdir $tempdir\n";
 
 my %def = ();
 
-my $symfile = "$ARGV[0]/all.sym";
-my $tmpfile = "$ARGV[0]/tmp.sym";
-system("dumpbin /symbols /out:$tmpfile $ARGV[0]/*.obj >NUL")
-  && die "Could not call dumpbin";
+my $symfile = "$tempdir/all.sym";
+my $tmpfile = "$tempdir/tmp.sym";
+mkdir($tempdir) unless -d $tempdir;
+
+my $cmd = "dumpbin /symbols /out:$tmpfile ".join(' ', @files);
+
+system($cmd) && die "Could not call dumpbin";
 rename($tmpfile, $symfile);
 extract_syms($symfile, \%def);
 print "\n";
 
-writedef($deffile, $platform, \%def);
+writedef($deffile, $arch, \%def);
 
 print "Generated " . scalar(keys(%def)) . " symbols\n";
-- 
2.37.0.3.g30cc8d0f14


--epod4qqm5dwbci5r
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v11-0004-meson-prereq-Add-src-tools-gen_export.pl.patch"



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* [PATCH v12 03/15] meson: prereq: Extend gendef.pl in preparation for meson
@ 2022-08-09 07:29 Andres Freund <[email protected]>
  0 siblings, 0 replies; 5+ messages in thread

From: Andres Freund @ 2022-08-09 07:29 UTC (permalink / raw)

The main issue with using gendef.pl as is for meson is that with meson the
filenames are a bit longer, exceeding the max commandline length when calling
dumpbin with all objects. It's easier to pass a library in anyway.

The .def file location, input and temporary file location need to be tunable
as well.

This also fixes a bug in gendef.pl: The logic when to regenerate was broken
and never avoid regenerating.

Author: Andres Freund <[email protected]>
Reviewed-By: Peter Eisentraut <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Discussion: https://postgr.es/m/[email protected]
---
 src/tools/msvc/MSBuildProject.pm |  4 +-
 src/tools/msvc/gendef.pl         | 72 ++++++++++++++++++++++----------
 2 files changed, 54 insertions(+), 22 deletions(-)

diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index 62acdda3a19..3581fa4a123 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -312,6 +312,8 @@ sub WriteItemDefinitionGroup
 
 	my $targetmachine =
 	  $self->{platform} eq 'Win32' ? 'MachineX86' : 'MachineX64';
+	my $arch =
+	  $self->{platform} eq 'Win32' ? 'x86' : 'x86_64';
 
 	my $includes = join ';', @{ $self->{includes} }, "";
 
@@ -381,7 +383,7 @@ EOF
 		print $f <<EOF;
     <PreLinkEvent>
       <Message>Generate DEF file</Message>
-      <Command>perl src\\tools\\msvc\\gendef.pl $cfgname\\$self->{name} $self->{platform}</Command>
+      <Command>perl src\\tools\\msvc\\gendef.pl --arch $arch --deffile $cfgname\\$self->{name}\\$self->{name}.def $cfgname\\$self->{name}</Command>
     </PreLinkEvent>
 EOF
 	}
diff --git a/src/tools/msvc/gendef.pl b/src/tools/msvc/gendef.pl
index b8c514a8311..cfbdef9007d 100644
--- a/src/tools/msvc/gendef.pl
+++ b/src/tools/msvc/gendef.pl
@@ -4,7 +4,8 @@
 use strict;
 use warnings;
 use 5.8.0;
-use List::Util qw(max);
+use List::Util qw(min);
+use Getopt::Long;
 
 my @def;
 
@@ -113,7 +114,7 @@ sub extract_syms
 
 sub writedef
 {
-	my ($deffile, $platform, $def) = @_;
+	my ($deffile, $arch, $def) = @_;
 	open(my $fh, '>', $deffile) || die "Could not write to $deffile\n";
 	print $fh "EXPORTS\n";
 	foreach my $f (sort keys %{$def})
@@ -122,7 +123,7 @@ sub writedef
 
 		# Strip the leading underscore for win32, but not x64
 		$f =~ s/^_//
-		  unless ($platform eq "x64");
+		  unless ($arch eq "x86_64");
 
 		# Emit just the name if it's a function symbol, or emit the name
 		# decorated with the DATA option for variables.
@@ -142,40 +143,69 @@ sub writedef
 
 sub usage
 {
-	die(    "Usage: gendef.pl <modulepath> <platform>\n"
-		  . "    modulepath: path to dir with obj files, no trailing slash"
-		  . "    platform: Win32 | x64");
+	my $add = shift;
+
+	die(    "Usage: gendef.pl --arch <arch> --deffile <deffile> --tempdir <tempdir> files or directories\n"
+		  . "    arch: x86 | x86_64\n"
+		  . "    outfile: \n"
+		  . "    tempdir: directory for temporary objects\n"
+		  . "    $add\n"
+	  );
 }
 
-usage()
-  unless scalar(@ARGV) == 2
-  && ( ($ARGV[0] =~ /\\([^\\]+$)/)
-	&& ($ARGV[1] eq 'Win32' || $ARGV[1] eq 'x64'));
-my $defname  = uc $1;
-my $deffile  = "$ARGV[0]/$defname.def";
-my $platform = $ARGV[1];
+my $arch;
+my $deffile;
+my $tempdir = '.';
+
+GetOptions(
+	'arch:s'   => \$arch,
+	'deffile:s'    => \$deffile,
+	'tempdir:s' => \$tempdir,
+  ) or usage();
+
+usage("arch: $arch") unless
+  ($arch eq 'x86' || $arch eq 'x86_64');
+
+print join(' ', @ARGV)."\n";
+
+my @files;
+
+foreach my $in (@ARGV)
+{
+	if (-d $in)
+	{
+		push @files, glob "$in/*.obj";
+	}
+	else
+	{
+		push @files, $in;
+	}
+}
 
 # if the def file exists and is newer than all input object files, skip
 # its creation
 if (-f $deffile
-	&& (-M $deffile > max(map { -M } <$ARGV[0]/*.obj>)))
+	&& (-M $deffile < min(map { -M } @files)))
 {
-	print "Not re-generating $defname.DEF, file already exists.\n";
+	print "Not re-generating $deffile, file already exists.\n";
 	exit(0);
 }
 
-print "Generating $defname.DEF from directory $ARGV[0], platform $platform\n";
+print STDERR "Generating $deffile in tempdir $tempdir\n";
 
 my %def = ();
 
-my $symfile = "$ARGV[0]/all.sym";
-my $tmpfile = "$ARGV[0]/tmp.sym";
-system("dumpbin /symbols /out:$tmpfile $ARGV[0]/*.obj >NUL")
-  && die "Could not call dumpbin";
+my $symfile = "$tempdir/all.sym";
+my $tmpfile = "$tempdir/tmp.sym";
+mkdir($tempdir) unless -d $tempdir;
+
+my $cmd = "dumpbin /symbols /out:$tmpfile ".join(' ', @files);
+
+system($cmd) && die "Could not call dumpbin";
 rename($tmpfile, $symfile);
 extract_syms($symfile, \%def);
 print "\n";
 
-writedef($deffile, $platform, \%def);
+writedef($deffile, $arch, \%def);
 
 print "Generated " . scalar(keys(%def)) . " symbols\n";
-- 
2.37.0.3.g30cc8d0f14


--3jz64y4qgcz5d4ku
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v12-0004-meson-prereq-Add-src-tools-gen_export.pl.patch"



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* [PATCH v13 04/20] meson: prereq: Extend gendef.pl in preparation for meson
@ 2022-08-09 07:29 Andres Freund <[email protected]>
  0 siblings, 0 replies; 5+ messages in thread

From: Andres Freund @ 2022-08-09 07:29 UTC (permalink / raw)

The main issue with using gendef.pl as is for meson is that with meson the
filenames are a bit longer, exceeding the max commandline length when calling
dumpbin with all objects. It's easier to pass a library in anyway.

The .def file location, input and temporary file location need to be tunable
as well.

This also fixes a bug in gendef.pl: The logic when to regenerate was broken
and never avoid regenerating.

Author: Andres Freund <[email protected]>
Reviewed-By: Peter Eisentraut <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Discussion: https://postgr.es/m/[email protected]
---
 src/tools/msvc/MSBuildProject.pm |  4 +-
 src/tools/msvc/gendef.pl         | 67 ++++++++++++++++++++++----------
 2 files changed, 49 insertions(+), 22 deletions(-)

diff --git a/src/tools/msvc/MSBuildProject.pm b/src/tools/msvc/MSBuildProject.pm
index 594729ceb7d..58590fdac29 100644
--- a/src/tools/msvc/MSBuildProject.pm
+++ b/src/tools/msvc/MSBuildProject.pm
@@ -312,6 +312,8 @@ sub WriteItemDefinitionGroup
 
 	my $targetmachine =
 	  $self->{platform} eq 'Win32' ? 'MachineX86' : 'MachineX64';
+	my $arch =
+	  $self->{platform} eq 'Win32' ? 'x86' : 'x86_64';
 
 	my $includes = join ';', @{ $self->{includes} }, "";
 
@@ -380,7 +382,7 @@ EOF
 		print $f <<EOF;
     <PreLinkEvent>
       <Message>Generate DEF file</Message>
-      <Command>perl src\\tools\\msvc\\gendef.pl $cfgname\\$self->{name} $self->{platform}</Command>
+      <Command>perl src\\tools\\msvc\\gendef.pl --arch $arch --deffile $cfgname\\$self->{name}\\$self->{name}.def $cfgname\\$self->{name}</Command>
     </PreLinkEvent>
 EOF
 	}
diff --git a/src/tools/msvc/gendef.pl b/src/tools/msvc/gendef.pl
index b4af3dea81b..d6bed1ce151 100644
--- a/src/tools/msvc/gendef.pl
+++ b/src/tools/msvc/gendef.pl
@@ -3,7 +3,8 @@
 
 use strict;
 use warnings;
-use List::Util qw(max);
+use List::Util qw(min);
+use Getopt::Long;
 
 my @def;
 
@@ -112,7 +113,7 @@ sub extract_syms
 
 sub writedef
 {
-	my ($deffile, $platform, $def) = @_;
+	my ($deffile, $arch, $def) = @_;
 	open(my $fh, '>', $deffile) || die "Could not write to $deffile\n";
 	print $fh "EXPORTS\n";
 	foreach my $f (sort keys %{$def})
@@ -121,7 +122,7 @@ sub writedef
 
 		# Strip the leading underscore for win32, but not x64
 		$f =~ s/^_//
-		  unless ($platform eq "x64");
+		  unless ($arch eq "x86_64");
 
 		# Emit just the name if it's a function symbol, or emit the name
 		# decorated with the DATA option for variables.
@@ -141,40 +142,64 @@ sub writedef
 
 sub usage
 {
-	die(    "Usage: gendef.pl <modulepath> <platform>\n"
-		  . "    modulepath: path to dir with obj files, no trailing slash"
-		  . "    platform: Win32 | x64");
+	die("Usage: gendef.pl --arch <arch> --deffile <deffile> --tempdir <tempdir> files-or-directories\n"
+		  . "    arch: x86 | x86_64\n"
+		  . "    deffile: path of the generated file\n"
+		  . "    tempdir: directory for temporary files\n"
+		  . "    files or directories: object files or directory containing object files\n"
+	);
 }
 
-usage()
-  unless scalar(@ARGV) == 2
-  && ( ($ARGV[0] =~ /\\([^\\]+$)/)
-	&& ($ARGV[1] eq 'Win32' || $ARGV[1] eq 'x64'));
-my $defname  = uc $1;
-my $deffile  = "$ARGV[0]/$defname.def";
-my $platform = $ARGV[1];
+my $arch;
+my $deffile;
+my $tempdir = '.';
+
+GetOptions(
+	'arch:s'    => \$arch,
+	'deffile:s' => \$deffile,
+	'tempdir:s' => \$tempdir,) or usage();
+
+usage("arch: $arch")
+  unless ($arch eq 'x86' || $arch eq 'x86_64');
+
+my @files;
+
+foreach my $in (@ARGV)
+{
+	if (-d $in)
+	{
+		push @files, glob "$in/*.obj";
+	}
+	else
+	{
+		push @files, $in;
+	}
+}
 
 # if the def file exists and is newer than all input object files, skip
 # its creation
 if (-f $deffile
-	&& (-M $deffile > max(map { -M } <$ARGV[0]/*.obj>)))
+	&& (-M $deffile < min(map { -M } @files)))
 {
-	print "Not re-generating $defname.DEF, file already exists.\n";
+	print "Not re-generating $deffile, file already exists.\n";
 	exit(0);
 }
 
-print "Generating $defname.DEF from directory $ARGV[0], platform $platform\n";
+print "Generating $deffile in tempdir $tempdir\n";
 
 my %def = ();
 
-my $symfile = "$ARGV[0]/all.sym";
-my $tmpfile = "$ARGV[0]/tmp.sym";
-system("dumpbin /symbols /out:$tmpfile $ARGV[0]/*.obj >NUL")
-  && die "Could not call dumpbin";
+my $symfile = "$tempdir/all.sym";
+my $tmpfile = "$tempdir/tmp.sym";
+mkdir($tempdir) unless -d $tempdir;
+
+my $cmd = "dumpbin /nologo /symbols /out:$tmpfile " . join(' ', @files);
+
+system($cmd) && die "Could not call dumpbin";
 rename($tmpfile, $symfile);
 extract_syms($symfile, \%def);
 print "\n";
 
-writedef($deffile, $platform, \%def);
+writedef($deffile, $arch, \%def);
 
 print "Generated " . scalar(keys(%def)) . " symbols\n";
-- 
2.37.3.542.gdd3f6c4cae


--4uoxke3bx6ymzqvl
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
	filename="v13-0005-meson-prereq-Add-src-tools-gen_export.pl.patch"



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* [PATCH v4 1/3] Refactor match_previous_words() to remove direct use of rl_completion_matches()
@ 2025-06-05 00:38 Yugo Nagata <[email protected]>
  0 siblings, 0 replies; 5+ messages in thread

From: Yugo Nagata @ 2025-06-05 00:38 UTC (permalink / raw)

Most tab completions in match_previous_words() use COMPLETE_WITH* macros,
which wrap rl_completion_matches(). However, some direct calls to
rl_completion_matches() still remained.

This commit replaces the remaining direct calls with the new macro,
COMPLETE_WITH_FILES or COMPLETE_WITH_GENERATOR, for improved consistency and
readability.
---
 src/bin/psql/tab-complete.in.c | 38 ++++++++++++++++------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 37524364290..1b4855edab6 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -443,6 +443,16 @@ do { \
 	matches = rl_completion_matches(text, complete_from_schema_query); \
 } while (0)
 
+#define COMPLETE_WITH_FILES(escape, force_quote) \
+do { \
+	completion_charp = escape; \
+	completion_force_quote = force_quote; \
+	matches = rl_completion_matches(text, complete_from_files); \
+} while (0)
+
+#define COMPLETE_WITH_GENERATOR(function) \
+	matches = rl_completion_matches(text, function)
+
 /*
  * Assembly instructions for schema queries
  *
@@ -2179,7 +2189,7 @@ match_previous_words(int pattern_id,
 			/* for INDEX and TABLE/SEQUENCE, respectively */
 						  "UNIQUE", "UNLOGGED");
 		else
-			matches = rl_completion_matches(text, create_command_generator);
+			COMPLETE_WITH_GENERATOR(create_command_generator);
 	}
 	/* complete with something you can create or replace */
 	else if (TailMatches("CREATE", "OR", "REPLACE"))
@@ -2189,7 +2199,7 @@ match_previous_words(int pattern_id,
 /* DROP, but not DROP embedded in other commands */
 	/* complete with something you can drop */
 	else if (Matches("DROP"))
-		matches = rl_completion_matches(text, drop_command_generator);
+		COMPLETE_WITH_GENERATOR(drop_command_generator);
 
 /* ALTER */
 
@@ -2200,7 +2210,7 @@ match_previous_words(int pattern_id,
 
 	/* ALTER something */
 	else if (Matches("ALTER"))
-		matches = rl_completion_matches(text, alter_command_generator);
+		COMPLETE_WITH_GENERATOR(alter_command_generator);
 	/* ALTER TABLE,INDEX,MATERIALIZED VIEW ALL IN TABLESPACE xxx */
 	else if (TailMatches("ALL", "IN", "TABLESPACE", MatchAny))
 		COMPLETE_WITH("SET TABLESPACE", "OWNED BY");
@@ -3308,17 +3318,9 @@ match_previous_words(int pattern_id,
 		COMPLETE_WITH("FROM", "TO");
 	/* Complete COPY <sth> FROM|TO with filename */
 	else if (Matches("COPY", MatchAny, "FROM|TO"))
-	{
-		completion_charp = "";
-		completion_force_quote = true;	/* COPY requires quoted filename */
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("", true);	/* COPY requires quoted filename */
 	else if (Matches("\\copy", MatchAny, "FROM|TO"))
-	{
-		completion_charp = "";
-		completion_force_quote = false;
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("", false);
 
 	/* Complete COPY <sth> TO <sth> */
 	else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny))
@@ -5417,9 +5419,9 @@ match_previous_words(int pattern_id,
 	else if (TailMatchesCS("\\h|\\help", MatchAny))
 	{
 		if (TailMatches("DROP"))
-			matches = rl_completion_matches(text, drop_command_generator);
+			COMPLETE_WITH_GENERATOR(drop_command_generator);
 		else if (TailMatches("ALTER"))
-			matches = rl_completion_matches(text, alter_command_generator);
+			COMPLETE_WITH_GENERATOR(alter_command_generator);
 
 		/*
 		 * CREATE is recognized by tail match elsewhere, so doesn't need to be
@@ -5519,11 +5521,7 @@ match_previous_words(int pattern_id,
 	else if (TailMatchesCS("\\cd|\\e|\\edit|\\g|\\gx|\\i|\\include|"
 						   "\\ir|\\include_relative|\\o|\\out|"
 						   "\\s|\\w|\\write|\\lo_import"))
-	{
-		completion_charp = "\\";
-		completion_force_quote = false;
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("\\", false);
 
 	/* gen_tabcomplete.pl ends special processing here */
 	/* END GEN_TABCOMPLETE */
-- 
2.43.0


--Multipart=_Thu__17_Jul_2025_10_57_36_+0900_dz7Bjsed2AEN=CJ+--





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2025-06-05 00:38 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-08-09 07:29 [PATCH v13 04/20] meson: prereq: Extend gendef.pl in preparation for meson Andres Freund <[email protected]>
2022-08-09 07:29 [PATCH v11 3/9] meson: prereq: Extend gendef.pl in preparation for meson Andres Freund <[email protected]>
2022-08-09 07:29 [PATCH v12 03/15] meson: prereq: Extend gendef.pl in preparation for meson Andres Freund <[email protected]>
2022-08-09 07:29 [PATCH v13 04/20] meson: prereq: Extend gendef.pl in preparation for meson Andres Freund <[email protected]>
2025-06-05 00:38 [PATCH v4 1/3] Refactor match_previous_words() to remove direct use of rl_completion_matches() Yugo Nagata <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox