Supporting plpython 2+3 builds better

Started by Tom Laneover 13 years ago6 messages
#1Tom Lane
tgl@sss.pgh.pa.us

I wrote:

After reading the recent thread about python 2 vs python 3 support,
I thought I'd amuse myself by trying to get plpython3 supported in
the Fedora packages. That turned out to be unreasonably painful
(which is something we oughta fix eventually), but it worked,

To give you an idea of what "unreasonably painful" means, attached is
the specfile diff needed to make this happen. I will not comment on
the fragility of this beyond observing that the "touch -r" commands
are *necessary*, else you get incorrect results.

I think we really need to do something to make this type of build less
painful, because as far as I can see most distros are going to be
wanting to support both python 2 and 3 for awhile to come.

A sketch of a solution might go like this:

* Extend configure to have two switches, say "--with-python" and
"--with-python3", which you can select either or both of. If you
want to pick executables that are not named "python" and "python3",
perhaps write it like "--with-python3=/usr/bin/python3.2mu". (I'd
be inclined to remove the dependency on a PYTHON envvar altogether.)

* Make configure output two independent sets of variables into
Makefile.global, viz

python2_includespec = ...
python2_libdir = ...
python2_libspec = ...
python2_additional_libs = ...
python2_configdir = ...
python2_majorversion = ...
python2_version = ...

python3_includespec = ...
python3_libdir = ...
python3_libspec = ...
python3_additional_libs = ...
python3_configdir = ...
python3_majorversion = ...
python3_version = ...

* Make plpython's Makefile build, test, install plpython2 and/or
plpython3 depending on what's set in Makefile.global.

I'm not sure yet whether it's possible to do this without duplicating a
lot of logic in config/python.m4 and plpython's Makefile.

Another problem is that Makefile.shlib isn't designed to build more than
one shared library per directory, which means that we might end up
having to copy all the source files into a new plpython3 subdirectory
anyway. We're already doing some of that with the regression test
files, though.

Thoughts?

regards, tom lane

#2Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#1)
Re: Supporting plpython 2+3 builds better

On Sat, 2012-09-08 at 19:18 -0400, Tom Lane wrote:

To give you an idea of what "unreasonably painful" means, attached is
the specfile diff needed to make this happen. I will not comment on
the fragility of this beyond observing that the "touch -r" commands
are *necessary*, else you get incorrect results.

I think an easier way is to configure two vpath builds and install the
pieces you want from each one. yo

Another problem is that Makefile.shlib isn't designed to build more
than one shared library per directory,

That's the main problem, but fixing it would be very useful in other
places as well. I had it on my radar to do something about that.

which means that we might end up having to copy all the source files
into a new plpython3 subdirectory anyway. We're already doing some of
that with the regression test files, though.

Doing it with the test files is already annoying enough. For instance,
we don't have a static list of all the files we need to copy (because of
expected file variants that are not tracked in the makefiles), so we
need to copy the files again on each run. If you extend this to all
source files, things would get totally bizarre.

A less invasive method might be to set up a second directory
pl/plpython3 which vpath-builds from pl/plpython.

But frankly, I'd like to work on the multiple-shlibs-in-one-directory
issue, because all of the above issues and more are projected in their
own strange ways on something like the transforms feature. For example,
how would you organize the source code for an extension module that
provides a new data type and adapters for plpython{2,3}u and plperl{,u},
with tests and all that?

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#2)
Re: Supporting plpython 2+3 builds better

Peter Eisentraut <peter_e@gmx.net> writes:

On Sat, 2012-09-08 at 19:18 -0400, Tom Lane wrote:

To give you an idea of what "unreasonably painful" means, attached is
the specfile diff needed to make this happen. I will not comment on
the fragility of this beyond observing that the "touch -r" commands
are *necessary*, else you get incorrect results.

I think an easier way is to configure two vpath builds and install the
pieces you want from each one.

I thought about that, and didn't like it, because then you have no proof
that the plpython3 you built in the one tree will actually play with the
core code you built in the other tree. Messy as my solution is, the
regression test step does actually test the intended live combination of
executables.

Another problem is that Makefile.shlib isn't designed to build more
than one shared library per directory,

That's the main problem, but fixing it would be very useful in other
places as well. I had it on my radar to do something about that.

This would be a good thing. Got any ideas how to do it?

regards, tom lane

#4Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#3)
1 attachment(s)
Re: Supporting plpython 2+3 builds better

On Sun, 2012-09-09 at 03:35 -0400, Tom Lane wrote:

Another problem is that Makefile.shlib isn't designed to build more
than one shared library per directory,

That's the main problem, but fixing it would be very useful in other
places as well. I had it on my radar to do something about that.

This would be a good thing. Got any ideas how to do it?

Here is a very rough patch. It obviously will need a lot of
fine-tuning, but it's the idea.

Attachments:

pg-multiple-shlibs-wip.patchtext/x-patch; charset=UTF-8; name=pg-multiple-shlibs-wip.patchDownload
diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index 4da2f10..790fbf4 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -77,6 +77,11 @@
 COMPILER = $(CC) $(CFLAGS)
 LINK.static = $(AR) $(AROPT)
 
+# "legacy" interface
+ifeq ($(words $(NAMES)),1)
+NAMES = $(NAME)
+$(NAME)_OBJS = $(OBJS)
+endif
 
 
 ifdef SO_MAJOR_VERSION
@@ -89,10 +94,20 @@ shlib_bare	= lib$(NAME)$(DLSUFFIX)
 soname		= $(shlib_major)
 else
 # Naming convention for dynamically loadable modules
-shlib		= $(NAME)$(DLSUFFIX)
+shlib_pattern = %$(DLSUFFIX)
 endif
 stlib		= lib$(NAME).a
 
+define shlib_template
+_fullname = $$(patsubst %,$$(shlib_pattern),$(1))
+shlibs := $(shlibs) $$(_fullname)
+$$(_fullname)_OBJS = $$($(1)_OBJS)
+ALL_OBJS += $$($(1)_OBJS)
+endef
+
+$(foreach name,$(NAMES),$(eval $(call shlib_template,$(name))))
+
+
 ifndef soname
 # additional flags for backend modules
 SHLIB_LINK += $(BE_DLLLIBS)
@@ -309,7 +324,7 @@ endif
 
 all-static-lib: $(stlib)
 
-all-shared-lib: $(shlib)
+all-shared-lib: $(shlibs)
 
 ifndef haslibarule
 $(stlib): $(OBJS) | $(SHLIB_PREREQS)
@@ -321,9 +336,10 @@ endif #haslibarule
 ifeq (,$(filter cygwin win32,$(PORTNAME)))
 ifneq ($(PORTNAME), aix)
 
+.SECONDEXPANSION:
 # Normal case
-$(shlib): $(OBJS) | $(SHLIB_PREREQS)
-	$(LINK.shared) -o $@ $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK)
+$(shlibs): %: $$(%_OBJS) | $(SHLIB_PREREQS)
+	$(LINK.shared) -o $@ $^ $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK)
 ifdef shlib_major
 # If we're using major and minor versions, then make a symlink to major-version-only.
 ifneq ($(shlib), $(shlib_major))
@@ -495,7 +511,7 @@ endif # no soname
 
 .PHONY: clean-lib
 clean-lib:
-	rm -f $(shlib) $(shlib_bare) $(shlib_major) $(stlib) $(exports_file)
+	rm -f $(shlibs) $(shlib_bare) $(shlib_major) $(stlib) $(exports_file)
 
 ifneq (,$(SHLIB_EXPORTS))
 maintainer-clean-lib:
diff --git a/src/pl/plpgsql/src/Makefile b/src/pl/plpgsql/src/Makefile
index e3fef84..182cd8e 100644
--- a/src/pl/plpgsql/src/Makefile
+++ b/src/pl/plpgsql/src/Makefile
@@ -11,13 +11,14 @@ top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
 # Shared library parameters
-NAME= plpgsql
+NAMES= plpgsql foobar
 
 override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
 SHLIB_LINK = $(filter -lintl, $(LIBS))
 rpath =
 
-OBJS = pl_gram.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o pl_scanner.o
+plpgsql_OBJS = pl_gram.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o pl_scanner.o
+foobar_OBJS = foo.o bar.o
 
 DATA = plpgsql.control plpgsql--1.0.sql plpgsql--unpackaged--1.0.sql
 
@@ -74,7 +75,7 @@ distprep: pl_gram.h pl_gram.c plerrcodes.h
 # pl_gram.c, pl_gram.h and plerrcodes.h are in the distribution tarball,
 # so they are not cleaned here.
 clean distclean: clean-lib
-	rm -f $(OBJS)
+	rm -f $(ALL_OBJS)
 
 maintainer-clean: clean
 	rm -f pl_gram.c pl_gram.h plerrcodes.h
#5Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Peter Eisentraut (#4)
Re: Supporting plpython 2+3 builds better

Excerpts from Peter Eisentraut's message of lun sep 10 09:50:42 -0300 2012:

On Sun, 2012-09-09 at 03:35 -0400, Tom Lane wrote:

Another problem is that Makefile.shlib isn't designed to build more
than one shared library per directory,

That's the main problem, but fixing it would be very useful in other
places as well. I had it on my radar to do something about that.

This would be a good thing. Got any ideas how to do it?

Here is a very rough patch. It obviously will need a lot of
fine-tuning, but it's the idea.

I remember trying to do this for the mb/conversion_procs subdir years
ago, to make them build in parallel to save some time. It didn't go
anywhere but the basic idea seems similar in spirit. Maybe we can use
this there too to make it fast.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

#6Peter Eisentraut
peter_e@gmx.net
In reply to: Alvaro Herrera (#5)
Re: Supporting plpython 2+3 builds better

On 9/10/12 9:26 AM, Alvaro Herrera wrote:

I remember trying to do this for the mb/conversion_procs subdir years
ago, to make them build in parallel to save some time. It didn't go
anywhere but the basic idea seems similar in spirit. Maybe we can use
this there too to make it fast.

Parallel builds across subdirectories should work now, so that shouldn't
be necessary anymore. Although removing some directory depth might be
nice, but there is a general hesitation about renaming files.