Simplify passing of configure arguments to pg_config

Started by Peter Eisentrautabout 6 years ago5 messages
#1Peter Eisentraut
peter.eisentraut@2ndquadrant.com
1 attachment(s)

Currently, configure puts the configure args into the makefiles and
then have the makefiles pass them to the build of pg_config. That looks
like an unnecessary redirection, and indeed that method was
put in place when pg_config was a shell script. We can simplify that
by having configure put the value into pg_config.h directly. This
also makes the standard build system match how the MSVC build system
already does it.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

0001-Simplify-passing-of-configure-arguments-to-pg_config.patchtext/plain; charset=UTF-8; name=0001-Simplify-passing-of-configure-arguments-to-pg_config.patch; x-mac-creator=0; x-mac-type=0Download
From 8edb9c20cbee740b5d2acb3c68f0a3f8231fb3dc Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 2 Dec 2019 13:16:39 +0100
Subject: [PATCH] Simplify passing of configure arguments to pg_config

The previous system had configure put the value into the makefiles and
then have the makefiles pass them to the build of pg_config.  That was
put in place when pg_config was a shell script.  We can simplify that
by having configure put the value into pg_config.h directly.  This
also makes the standard build system match how the MSVC build system
already does it.
---
 configure                  | 8 ++++++--
 configure.in               | 4 +++-
 src/Makefile.global.in     | 3 ---
 src/common/Makefile        | 1 -
 src/common/config_info.c   | 6 +-----
 src/include/pg_config.h.in | 3 +++
 src/tools/msvc/Solution.pm | 2 +-
 7 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/configure b/configure
index 1d88983b34..5cbe8e91d8 100755
--- a/configure
+++ b/configure
@@ -776,7 +776,6 @@ build_vendor
 build_cpu
 build
 PG_MAJORVERSION
-configure_args
 target_alias
 host_alias
 build_alias
@@ -2797,7 +2796,12 @@ ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.
 
 
 
-configure_args=$ac_configure_args
+
+ac_configure_args_escaped=`$as_echo "$ac_configure_args" | sed 's/"/\\\\"/g'`
+
+cat >>confdefs.h <<_ACEOF
+#define CONFIGURE_ARGS "$ac_configure_args_escaped"
+_ACEOF
 
 
 PG_MAJORVERSION=`expr "$PACKAGE_VERSION" : '\([0-9][0-9]*\)'`
diff --git a/configure.in b/configure.in
index a2cb20b5e3..4f2427720c 100644
--- a/configure.in
+++ b/configure.in
@@ -27,7 +27,9 @@ AC_COPYRIGHT([Copyright (c) 1996-2019, PostgreSQL Global Development Group])
 AC_CONFIG_SRCDIR([src/backend/access/common/heaptuple.c])
 AC_CONFIG_AUX_DIR(config)
 AC_PREFIX_DEFAULT(/usr/local/pgsql)
-AC_SUBST(configure_args, [$ac_configure_args])
+
+ac_configure_args_escaped=`$as_echo "$ac_configure_args" | sed 's/"/\\\\"/g'`
+AC_DEFINE_UNQUOTED(CONFIGURE_ARGS, ["$ac_configure_args_escaped"], [Arguments passed to configure])
 
 [PG_MAJORVERSION=`expr "$PACKAGE_VERSION" : '\([0-9][0-9]*\)'`]
 AC_SUBST(PG_MAJORVERSION)
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 05b66380e0..95f5a104e5 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -74,9 +74,6 @@ endif # not PGXS
 
 vpathsearch = `for f in $(addsuffix /$(1),$(subst :, ,. $(VPATH))); do test -r $$f && echo $$f && break; done`
 
-# Saved arguments from configure
-configure_args = @configure_args@
-
 
 ##########################################################################
 #
diff --git a/src/common/Makefile b/src/common/Makefile
index ffb0f6edff..fd43558830 100644
--- a/src/common/Makefile
+++ b/src/common/Makefile
@@ -31,7 +31,6 @@ include $(top_builddir)/src/Makefile.global
 # don't include subdirectory-path-dependent -I and -L switches
 STD_CPPFLAGS := $(filter-out -I$(top_srcdir)/src/include -I$(top_builddir)/src/include,$(CPPFLAGS))
 STD_LDFLAGS := $(filter-out -L$(top_builddir)/src/common -L$(top_builddir)/src/port,$(LDFLAGS))
-override CPPFLAGS += -DVAL_CONFIGURE="\"$(configure_args)\""
 override CPPFLAGS += -DVAL_CC="\"$(CC)\""
 override CPPFLAGS += -DVAL_CPPFLAGS="\"$(STD_CPPFLAGS)\""
 override CPPFLAGS += -DVAL_CFLAGS="\"$(CFLAGS)\""
diff --git a/src/common/config_info.c b/src/common/config_info.c
index dd34fbfc00..902f8226a4 100644
--- a/src/common/config_info.c
+++ b/src/common/config_info.c
@@ -124,11 +124,7 @@ get_configdata(const char *my_exec_path, size_t *configdata_len)
 	i++;
 
 	configdata[i].name = pstrdup("CONFIGURE");
-#ifdef VAL_CONFIGURE
-	configdata[i].setting = pstrdup(VAL_CONFIGURE);
-#else
-	configdata[i].setting = pstrdup(_("not recorded"));
-#endif
+	configdata[i].setting = pstrdup(CONFIGURE_ARGS);
 	i++;
 
 	configdata[i].name = pstrdup("CC");
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index c208dcdfc7..c8384c6c04 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -42,6 +42,9 @@
    Changing BLCKSZ requires an initdb. */
 #undef BLCKSZ
 
+/* Arguments passed to configure */
+#undef CONFIGURE_ARGS
+
 /* Define to the default TCP port number on which the server listens and to
    which clients will try to connect. This can be overridden at run-time, but
    it's convenient if your clients have the right default compiled in.
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 5f72530c72..e9efc97e14 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -247,7 +247,7 @@ sub GenerateFiles
 			print $o "#define DEF_PGPORT $port\n";
 			print $o "#define DEF_PGPORT_STR \"$port\"\n";
 		}
-		print $o "#define VAL_CONFIGURE \""
+		print $o "#define CONFIGURE_ARGS \""
 		  . $self->GetFakeConfigure() . "\"\n";
 		print $o "#endif /* IGNORE_CONFIGURED_SETTINGS */\n";
 		close($o);
-- 
2.24.0

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#1)
Re: Simplify passing of configure arguments to pg_config

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

Currently, configure puts the configure args into the makefiles and
then have the makefiles pass them to the build of pg_config. That looks
like an unnecessary redirection, and indeed that method was
put in place when pg_config was a shell script. We can simplify that
by having configure put the value into pg_config.h directly. This
also makes the standard build system match how the MSVC build system
already does it.

I dunno, is this really an improvement? It makes the handling of
VAL_CONFIGURE different from every other one of the values passed
into pg_config, and I don't see any countervailing addition of
some other regularity. I'm also a bit suspicious of the ad-hoc
escaping step ...

regards, tom lane

#3Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Tom Lane (#2)
Re: Simplify passing of configure arguments to pg_config

On 2019-12-03 06:03, Tom Lane wrote:

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

Currently, configure puts the configure args into the makefiles and
then have the makefiles pass them to the build of pg_config. That looks
like an unnecessary redirection, and indeed that method was
put in place when pg_config was a shell script. We can simplify that
by having configure put the value into pg_config.h directly. This
also makes the standard build system match how the MSVC build system
already does it.

I dunno, is this really an improvement? It makes the handling of
VAL_CONFIGURE different from every other one of the values passed
into pg_config, and I don't see any countervailing addition of
some other regularity.

The other values come from the makefiles, so we have to do it that way.
The configure args come from configure, so why make them go through the
makefile? (PG_VERSION also comes in that way. ;-) )

There is also the weird difference with how the MSVC build system
handles it. It appends VAL_CONFIGURE to pg_config.h instead of passing
it on the command line.

I'm also a bit suspicious of the ad-hoc escaping step ...

Hmm, the current way doesn't handle embedded quotes at all, so perhaps
this wouldn't be necessary. But it would add some robustness.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#4Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Peter Eisentraut (#3)
1 attachment(s)
Re: Simplify passing of configure arguments to pg_config

On 2019-12-04 11:30, Peter Eisentraut wrote:

On 2019-12-03 06:03, Tom Lane wrote:

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

Currently, configure puts the configure args into the makefiles and
then have the makefiles pass them to the build of pg_config. That looks
like an unnecessary redirection, and indeed that method was
put in place when pg_config was a shell script. We can simplify that
by having configure put the value into pg_config.h directly. This
also makes the standard build system match how the MSVC build system
already does it.

I dunno, is this really an improvement? It makes the handling of
VAL_CONFIGURE different from every other one of the values passed
into pg_config, and I don't see any countervailing addition of
some other regularity.

The other values come from the makefiles, so we have to do it that way.
The configure args come from configure, so why make them go through the
makefile? (PG_VERSION also comes in that way. ;-) )

There is also the weird difference with how the MSVC build system
handles it. It appends VAL_CONFIGURE to pg_config.h instead of passing
it on the command line.

Here is an updated version of the patch after the removal of
pg_config.h.win32. It's easier to see now how this helps unify the
handling of this between the two build systems.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

v2-0001-Simplify-passing-of-configure-arguments-to-pg_con.patchtext/plain; charset=UTF-8; name=v2-0001-Simplify-passing-of-configure-arguments-to-pg_con.patch; x-mac-creator=0; x-mac-type=0Download
From 459c1ec0708348ea1db8d23d789fa8e391904867 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Sun, 22 Dec 2019 14:50:47 +0100
Subject: [PATCH v2] Simplify passing of configure arguments to pg_config

The previous system had configure put the value into the makefiles and
then have the makefiles pass them to the build of pg_config.  That was
put in place when pg_config was a shell script.  We can simplify that
by having configure put the value into pg_config.h directly.  This
also makes the standard build system match how the MSVC build system
already does it.
---
 configure                  | 6 ++++--
 configure.in               | 2 +-
 src/Makefile.global.in     | 3 ---
 src/common/Makefile        | 1 -
 src/common/config_info.c   | 6 +-----
 src/include/pg_config.h.in | 3 +++
 src/tools/msvc/Solution.pm | 7 +------
 7 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/configure b/configure
index 9de50377ff..ef0e9ac6ca 100755
--- a/configure
+++ b/configure
@@ -776,7 +776,6 @@ build_vendor
 build_cpu
 build
 PG_MAJORVERSION
-configure_args
 target_alias
 host_alias
 build_alias
@@ -2797,7 +2796,10 @@ ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.
 
 
 
-configure_args=$ac_configure_args
+
+cat >>confdefs.h <<_ACEOF
+#define CONFIGURE_ARGS "$ac_configure_args"
+_ACEOF
 
 
 PG_MAJORVERSION=`expr "$PACKAGE_VERSION" : '\([0-9][0-9]*\)'`
diff --git a/configure.in b/configure.in
index 9c5e5e7f8c..c5323ff9b4 100644
--- a/configure.in
+++ b/configure.in
@@ -27,7 +27,7 @@ AC_COPYRIGHT([Copyright (c) 1996-2019, PostgreSQL Global Development Group])
 AC_CONFIG_SRCDIR([src/backend/access/common/heaptuple.c])
 AC_CONFIG_AUX_DIR(config)
 AC_PREFIX_DEFAULT(/usr/local/pgsql)
-AC_SUBST(configure_args, [$ac_configure_args])
+AC_DEFINE_UNQUOTED(CONFIGURE_ARGS, ["$ac_configure_args"], [Saved arguments from configure])
 
 [PG_MAJORVERSION=`expr "$PACKAGE_VERSION" : '\([0-9][0-9]*\)'`]
 AC_SUBST(PG_MAJORVERSION)
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 05b66380e0..95f5a104e5 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -74,9 +74,6 @@ endif # not PGXS
 
 vpathsearch = `for f in $(addsuffix /$(1),$(subst :, ,. $(VPATH))); do test -r $$f && echo $$f && break; done`
 
-# Saved arguments from configure
-configure_args = @configure_args@
-
 
 ##########################################################################
 #
diff --git a/src/common/Makefile b/src/common/Makefile
index ffb0f6edff..fd43558830 100644
--- a/src/common/Makefile
+++ b/src/common/Makefile
@@ -31,7 +31,6 @@ include $(top_builddir)/src/Makefile.global
 # don't include subdirectory-path-dependent -I and -L switches
 STD_CPPFLAGS := $(filter-out -I$(top_srcdir)/src/include -I$(top_builddir)/src/include,$(CPPFLAGS))
 STD_LDFLAGS := $(filter-out -L$(top_builddir)/src/common -L$(top_builddir)/src/port,$(LDFLAGS))
-override CPPFLAGS += -DVAL_CONFIGURE="\"$(configure_args)\""
 override CPPFLAGS += -DVAL_CC="\"$(CC)\""
 override CPPFLAGS += -DVAL_CPPFLAGS="\"$(STD_CPPFLAGS)\""
 override CPPFLAGS += -DVAL_CFLAGS="\"$(CFLAGS)\""
diff --git a/src/common/config_info.c b/src/common/config_info.c
index dd34fbfc00..902f8226a4 100644
--- a/src/common/config_info.c
+++ b/src/common/config_info.c
@@ -124,11 +124,7 @@ get_configdata(const char *my_exec_path, size_t *configdata_len)
 	i++;
 
 	configdata[i].name = pstrdup("CONFIGURE");
-#ifdef VAL_CONFIGURE
-	configdata[i].setting = pstrdup(VAL_CONFIGURE);
-#else
-	configdata[i].setting = pstrdup(_("not recorded"));
-#endif
+	configdata[i].setting = pstrdup(CONFIGURE_ARGS);
 	i++;
 
 	configdata[i].name = pstrdup("CC");
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 050c48b108..97d98751ef 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -42,6 +42,9 @@
    Changing BLCKSZ requires an initdb. */
 #undef BLCKSZ
 
+/* Saved arguments from configure */
+#undef CONFIGURE_ARGS
+
 /* Define to the default TCP port number on which the server listens and to
    which clients will try to connect. This can be overridden at run-time, but
    it's convenient if your clients have the right default compiled in.
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 909bded592..4c7fc7bc30 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -195,6 +195,7 @@ sub GenerateFiles
 		ALIGNOF_SHORT              => 2,
 		AC_APPLE_UNIVERSAL_BUILD   => undef,
 		BLCKSZ                     => 1024 * $self->{options}->{blocksize},
+		CONFIGURE_ARGS             => '"' . $self->GetFakeConfigure() . '"',
 		DEF_PGPORT                 => $port,
 		DEF_PGPORT_STR             => qq{"$port"},
 		ENABLE_GSS                 => $self->{options}->{gss} ? 1 : undef,
@@ -533,12 +534,6 @@ sub GenerateFiles
 	$self->GenerateConfigHeader('src/include/pg_config_ext.h', \%define, 0);
 	$self->GenerateConfigHeader('src/interfaces/ecpg/include/ecpg_config.h', \%define, 0);
 
-	open(my $f, '>>', 'src/include/pg_config.h')
-	  || confess "Could not write to src/include/pg_config.h\n";
-	print $f "\n";
-	print $f "#define VAL_CONFIGURE \"" . $self->GetFakeConfigure() . "\"\n";
-	close($f);
-
 	$self->GenerateDefFile(
 		"src/interfaces/libpq/libpqdll.def",
 		"src/interfaces/libpq/exports.txt",
-- 
2.24.1

#5Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Peter Eisentraut (#4)
Re: Simplify passing of configure arguments to pg_config

On 2019-12-22 14:56, Peter Eisentraut wrote:

There is also the weird difference with how the MSVC build system
handles it. It appends VAL_CONFIGURE to pg_config.h instead of passing
it on the command line.

Here is an updated version of the patch after the removal of
pg_config.h.win32. It's easier to see now how this helps unify the
handling of this between the two build systems.

committed

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services