Tuesday, September 24, 2019

Adding binary renaming facility to python.port.mk

Index: python.port.mk
===================================================================
RCS file: /cvs/ports/lang/python/python.port.mk,v
retrieving revision 1.114
diff -u -p -r1.114 python.port.mk
--- python.port.mk 24 Jun 2019 14:25:54 -0000 1.114
+++ python.port.mk 24 Sep 2019 19:44:49 -0000
@@ -246,3 +246,21 @@ ERRORS += "***\n*** WARNING: running upd
.endif

.endif
+
+# Facility to de-conflict binaries for python ports with both flavors
+
+MODPY_SUFFIX_RENAME ?= No
+
+MODPY_SUFFIX_CMD ?= for i in ${PREFIX}/bin/*; do \
+ mv $${i} $${i}${MODPY_BIN_SUFFIX} ;\
+ done
+
+.if defined(FLAVORS) && ${FLAVORS:Mpython3} && \
+ ${MODPY_SUFFIX_RENAME:L} == "yes"
+. if !target(post-install)
+post-install:
+ ${MODPY_SUFFIX_CMD}
+. elif make(fake)
+ERRORS += "***\n*** WARNING: MODPY_SUFFIX_RENAME=Yes but post-install target exists\n***\n"
+. endif
+.endif
Index: port-modules.5
===================================================================
RCS file: /cvs/src/share/man/man5/port-modules.5,v
retrieving revision 1.241
diff -u -p -r1.241 port-modules.5
--- port-modules.5 27 Aug 2019 14:33:24 -0000 1.241
+++ port-modules.5 24 Sep 2019 19:45:18 -0000
@@ -1426,12 +1426,17 @@ then edit it to prefix any lines creatin
.Ev MODPY_PYCACHE
directories with
.Ev MODPY_COMMENT .
-As python2 and python3 packages should permit being installed together,
-it may be necessary to suffix names of common binaries or directories,
-or split common files into a subpackage.
If updating the PLIST without using the python3 flavor,
take care not to remove ${MODPY_PYCACHE}, ${MODPY_PYC_MAGIC_TAG}, or
${MODPY_ABI_TAG} variables from the PLIST.
+.Pp
+As python2 and python3 packages should permit being installed together,
+it may be necessary to suffix names of common binaries or directories,
+or split common files into a subpackage. A port can set
+.Ev MODPY_SUFFIX_RENAME
+to Yes to have any files in ${PREFIX}/bin renamed with
+.Ev MODPY_BIN_SUFFIX
+on the end.
.It lang/ruby
See
.Xr ruby-module 5 .
While telling someone how to deal with collisions of binaries for python
ports, it occurred to me that the renaming is something that could be
factored out into python.port.mk.

So I did that.

The diff introduces MODPY_SUFFIX_RENAME. It defaults to No. If set to Yes,
it will use a for loop the rename everything in ${PREFIX}/bin with
MODPY_BIN_SUFFIX. For python2 that is currently a no-op, but I don't
bypass the rename in case that changes in future (there have been
rumblings about defaulting to python3). If a do-install target is
already defined a warning will be thrown.

If one desires to use this but *have* defined a do-install target,
one can just include a line with MODPY_SUFFIX_CMD like this:

do-install:
${MODPY_SUFFIX_CMD}
/usr/bin/other things

I've attached a diff to implement this and another to update port-modules(5)

I tested this with www/py-gunicorn, textproc/py-unideocde, and
textproc/py-vobject. Those three do a rename in post-install. I changed
them to eliminate the do-install target and added MODPY_SUFFIX_RENAME=Yes.
I regenerated the PLIST to make sure it didn't change. There were no
changes.

I also tested py-dateutil which doesn't use it as a check that it doesn't
change the PLIST. It didn't.

Comments? OK?

--Kurt

No comments:

Post a Comment