[PATCHES] Generate shorter name for extra python files

Lukas Slebodnik lslebodn at redhat.com
Tue Apr 17 07:42:07 UTC 2018


On (23/09/17 10:15), Andrew Bartlett via samba-technical wrote:
>On Fri, 2017-09-22 at 22:49 +0200, Lukas Slebodnik wrote:
>> 
>> But as i showed you in previous example it is not a problem that
>> symbol is in version script because it is not part of util library
>> for python3. Version script is used as a whitelist to allow symbols from
>> objects *.o appear in library. But if symbol is missing in object files
>> it will not be part of library even though it is in version script.
>>
>> 
>> https://www.akkadia.org/drepper/dsohowto.pdf
>> Section 2.2 says:
>>   The concept of export maps is to tell the linker explicitly
>>   which symbols to export from the generated object.
>> 
>> And it is much simpler to use version script(export maps)
>> then __attribute__ ((visibility ("hidden")))
>> 
>> 
>> But if you prefer to have separate version script(ABI/*) for python2
>> and python3 I do not have a problem with that. I can just see a small
>> benefit in de-duplication.
>
>The ABI files are not just for the version scripts.  They are also used
>to determine if a symbol is removed or the signature changed, and
>triggers logic to reject such a build.
>
>If there is just one ABI file for both, then if python2 requires a
>different ABI to python3, then either on the other will fail a build. 
>
>However, we don't want ABI files for each possible python3 version (35m
>etc), just for python3 overall, hence the .py3 thing.
>
>I hope this helps clarify things.
>

I would like to apologize that it took ages to send updated version of
patches. Hopefully, it would work for everyone.

Adding Timur to CC for checking it for FreeBSD

And now with patch. :-) I had a suspicion that sending patches after midnight
is not the best idea.

LS
-------------- next part --------------
From fb77992dc65bc1573445f43157b7bc357662ca99 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Mon, 3 Jul 2017 20:38:53 +0200
Subject: [PATCH 1/4] WAF: Generate shorter name for extra python

Generating different name with different architecture and with the same
version of python is not ideal. pkgconfig files should be architecture
independent and libraries for different architectures are stored in
different directories
 e.g. (/usr/lib64, /usr/lib, /usr/lib/x86_64-linux-gnu/ ...)

Additional suffix for extra python consist of string "cp" + LDVERSION
for python if available or fallback to VERSION.

"cp" is short version of "CPython" to match [PEP 425]
https://www.python.org/dev/peps/pep-0425/#abi-tag

Therefore it will be simpler to remove architecture from names
/usr/lib64/pkgconfig/pytalloc-util.cpython-36m-x86_64-linux-gnu.pc
vs.
/usr/lib64/pkgconfig/pytalloc-util-cp36m.pc

Signed-off-by: Lukas Slebodnik <lslebodn at redhat.com>
Signed-off-by: Petr Viktorin <pviktori at redhat.com>
---
 buildtools/wafsamba/samba_python.py      | 11 ++++++-----
 buildtools/wafsamba/wafsamba.py          |  9 +++++----
 third_party/waf/wafadmin/Tools/python.py |  1 +
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/buildtools/wafsamba/samba_python.py b/buildtools/wafsamba/samba_python.py
index cb99fe9f4cc6abe8bc7a5ad208aa346b2717d208..3570096b7decee4860205d425e6e86420f81a613 100644
--- a/buildtools/wafsamba/samba_python.py
+++ b/buildtools/wafsamba/samba_python.py
@@ -85,10 +85,11 @@ def _check_python_headers(conf, mandatory):
     if conf.env['PYTHON_VERSION'] > '3':
         abi_pattern = os.path.splitext(conf.env['pyext_PATTERN'])[0]
         conf.env['PYTHON_SO_ABI_FLAG'] = abi_pattern % ''
+        python_abi_version = conf.env['PYTHON_LDVERSION'].replace('.', '')
+        conf.env['PYTHON_LIBNAME_SO_ABI_FLAG'] = '-cp' + python_abi_version
     else:
         conf.env['PYTHON_SO_ABI_FLAG'] = ''
-    conf.env['PYTHON_LIBNAME_SO_ABI_FLAG'] = (
-        conf.env['PYTHON_SO_ABI_FLAG'].replace('_', '-'))
+        conf.env['PYTHON_LIBNAME_SO_ABI_FLAG'] = ''
 
     for lib in conf.env['LINKFLAGS_PYEMBED']:
         if lib.startswith('-L'):
@@ -170,9 +171,9 @@ def SAMBA_PYTHON(bld, name,
 Build.BuildContext.SAMBA_PYTHON = SAMBA_PYTHON
 
 
-def pyembed_libname(bld, name, extrapython=False):
-    if bld.env['PYTHON_SO_ABI_FLAG']:
-        return name + bld.env['PYTHON_SO_ABI_FLAG']
+def pyembed_libname(bld, name):
+    if bld.env['PYTHON_LIBNAME_SO_ABI_FLAG']:
+        return name + bld.env['PYTHON_LIBNAME_SO_ABI_FLAG']
     else:
         return name
 
diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py
index 12d5421c4a63c06c6feaa5fb04410a2030f0ef4d..d63474fd20a76e93de6eb8d45e7fd35e8e846064 100644
--- a/buildtools/wafsamba/wafsamba.py
+++ b/buildtools/wafsamba/wafsamba.py
@@ -261,10 +261,10 @@ def SAMBA_LIBRARY(bld, libname, source,
     if abi_directory:
         features += ' abi_check'
 
-    if pyembed and bld.env['PYTHON_SO_ABI_FLAG']:
+    if pyembed and bld.env['PYTHON_LIBNAME_SO_ABI_FLAG']:
         # For ABI checking, we don't care about the exact Python version.
-        # Replace the Python ABI tag (e.g. ".cpython-35m") by a generic ".py3"
-        abi_flag = bld.env['PYTHON_SO_ABI_FLAG']
+        # Replace the Python ABI tag (e.g. "-cp35m") by a generic ".py3"
+        abi_flag = bld.env['PYTHON_LIBNAME_SO_ABI_FLAG']
         replacement = '.py%s' % bld.env['PYTHON_VERSION'].split('.')[0]
         version_libname = libname.replace(abi_flag, replacement)
     else:
@@ -331,7 +331,8 @@ def SAMBA_LIBRARY(bld, libname, source,
 
     if pc_files is not None and not private_library:
         if pyembed and bld.env['IS_EXTRA_PYTHON']:
-            bld.PKG_CONFIG_FILES(pc_files, vnum=vnum, extra_name=bld.env['PYTHON_SO_ABI_FLAG'])
+            bld.PKG_CONFIG_FILES(pc_files, vnum=vnum,
+                                 extra_name=bld.env['PYTHON_LIBNAME_SO_ABI_FLAG'])
         else:
             bld.PKG_CONFIG_FILES(pc_files, vnum=vnum)
 
diff --git a/third_party/waf/wafadmin/Tools/python.py b/third_party/waf/wafadmin/Tools/python.py
index cd96b658185273ef211b2feb4f7039896cfc7688..fca1e6e087da0ad29e45deed03c4a5fcb93d292c 100644
--- a/third_party/waf/wafadmin/Tools/python.py
+++ b/third_party/waf/wafadmin/Tools/python.py
@@ -234,6 +234,7 @@ LDVERSION = %r
 	result = False
 	if not python_LDVERSION:
 		python_LDVERSION = env['PYTHON_VERSION']
+	env['PYTHON_LDVERSION'] = python_LDVERSION
 	name = 'python' + python_LDVERSION
 
 	if python_LIBDIR is not None:
-- 
2.17.0


From db7988cd86119d05132da283f1132d8f24bb9818 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Mon, 3 Jul 2017 21:22:10 +0200
Subject: [PATCH 2/4] talloc: Generate shorter name for extra python

Generating different name with different architecture and with the same
version of python is not ideal. pkgconfig files should be architecture
independent and libraries for different architectures are stored in
different directories
 e.g. (/usr/lib64, /usr/lib, /usr/lib/x86_64-linux-gnu/ ...)

Therefore it will be simpler to remove architecture from names
/usr/lib64/pkgconfig/pytalloc-util.cpython-36m-x86_64-linux-gnu.pc
vs.
/usr/lib64/pkgconfig/pytalloc-util-cp36m.pc

Signed-off-by: Lukas Slebodnik <lslebodn at redhat.com>
---
 lib/talloc/pytalloc-util.pc.in | 2 +-
 lib/talloc/wscript             | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/talloc/pytalloc-util.pc.in b/lib/talloc/pytalloc-util.pc.in
index 06f83e26aa43b3eafd0364c1603673742c2de63b..1025ba562fecaec07ce8aa04a2350f638a36be76 100644
--- a/lib/talloc/pytalloc-util.pc.in
+++ b/lib/talloc/pytalloc-util.pc.in
@@ -3,7 +3,7 @@ exec_prefix=@exec_prefix@
 libdir=@libdir@
 includedir=@includedir@
 
-Name: pytalloc-util at PYTHON_SO_ABI_FLAG@
+Name: pytalloc-util at PYTHON_LIBNAME_SO_ABI_FLAG@
 Description: Utility functions for using talloc objects with Python
 Version: @TALLOC_VERSION@
 Libs: @LIB_RPATH@ -L${libdir} -lpytalloc-util at PYTHON_LIBNAME_SO_ABI_FLAG@
diff --git a/lib/talloc/wscript b/lib/talloc/wscript
index 1b3167228fe72f0317f6ea89347e3686d638fe24..b03f5376e2932cd8db4dbd1bc9c76d1c71e81d0c 100644
--- a/lib/talloc/wscript
+++ b/lib/talloc/wscript
@@ -85,7 +85,7 @@ def configure(conf):
             # We need to get a pytalloc-util for all the python versions
             # we are building for
             if conf.env['EXTRA_PYTHON']:
-                name = 'pytalloc-util' + conf.all_envs['extrapython']['PYTHON_SO_ABI_FLAG']
+                name = 'pytalloc-util' + conf.all_envs['extrapython']['PYTHON_LIBNAME_SO_ABI_FLAG']
                 if not conf.CHECK_BUNDLED_SYSTEM_PKG(name, minversion=VERSION,
                                                      implied_deps='talloc replace'):
                     using_system_pytalloc_util = False
-- 
2.17.0


From 098df1cd2dcbb2b11482afacd16831d71471efe3 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Mon, 3 Jul 2017 21:27:34 +0200
Subject: [PATCH 3/4] ldb: Generate shorter name for extra python

Generating different name with different architecture and with the same
version of python is not ideal. pkgconfig files should be architecture
independent and libraries for different architectures are stored in
different directories
 e.g. (/usr/lib64, /usr/lib, /usr/lib/x86_64-linux-gnu/ ...)

Therefore it will be simpler to remove architecture from names
/usr/lib64/pkgconfig/pyldb-util.cpython-36m-x86_64-linux-gnu.pc
vs.
/usr/lib64/pkgconfig/pyldb-util-cp36m.pc

Signed-off-by: Lukas Slebodnik <lslebodn at redhat.com>
---
 lib/ldb/pyldb-util.pc.in | 2 +-
 lib/ldb/wscript          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/ldb/pyldb-util.pc.in b/lib/ldb/pyldb-util.pc.in
index 60ec7029260237d6ddd36ccea90fbb4444eaad7d..99e0378e98a5e51ca30857dd5863a503c6a7e219 100644
--- a/lib/ldb/pyldb-util.pc.in
+++ b/lib/ldb/pyldb-util.pc.in
@@ -4,7 +4,7 @@ libdir=@libdir@
 includedir=@includedir@
 modulesdir=@LDB_MODULESDIR@
 
-Name: pyldb-util at PYTHON_SO_ABI_FLAG@
+Name: pyldb-util at PYTHON_LIBNAME_SO_ABI_FLAG@
 Description: Python bindings for LDB
 Version: @PACKAGE_VERSION@
 Requires: ldb
diff --git a/lib/ldb/wscript b/lib/ldb/wscript
index aab4da132d5c6996a2c9f8c89da055c4f3e04484..d9084878a978176b927f68f7f7fb13160dd92c7d 100644
--- a/lib/ldb/wscript
+++ b/lib/ldb/wscript
@@ -78,7 +78,7 @@ def configure(conf):
             # We need to get a pyldb-util for all the python versions
             # we are building for
             if conf.env['EXTRA_PYTHON']:
-                name = 'pyldb-util' + conf.all_envs['extrapython']['PYTHON_SO_ABI_FLAG']
+                name = 'pyldb-util' + conf.all_envs['extrapython']['PYTHON_LIBNAME_SO_ABI_FLAG']
                 if not conf.CHECK_BUNDLED_SYSTEM_PKG(name, minversion=VERSION,
                                                      onlyif='talloc tdb tevent',
                                                      implied_deps='replace talloc tdb tevent ldb'):
-- 
2.17.0


From 27d5f43f3583bef6ce2fc1814bf876ae6ababba6 Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pviktori at redhat.com>
Date: Tue, 19 Sep 2017 14:03:13 +0200
Subject: [PATCH 4/4] wafsamba: Remove PYTHON_SO_ABI_FLAG

Signed-off-by: Petr Viktorin <pviktori at redhat.com>
---
 buildtools/wafsamba/samba_python.py | 2 --
 1 file changed, 2 deletions(-)

diff --git a/buildtools/wafsamba/samba_python.py b/buildtools/wafsamba/samba_python.py
index 3570096b7decee4860205d425e6e86420f81a613..bd9de68539467612538388aa677d262361ffe162 100644
--- a/buildtools/wafsamba/samba_python.py
+++ b/buildtools/wafsamba/samba_python.py
@@ -84,11 +84,9 @@ def _check_python_headers(conf, mandatory):
 
     if conf.env['PYTHON_VERSION'] > '3':
         abi_pattern = os.path.splitext(conf.env['pyext_PATTERN'])[0]
-        conf.env['PYTHON_SO_ABI_FLAG'] = abi_pattern % ''
         python_abi_version = conf.env['PYTHON_LDVERSION'].replace('.', '')
         conf.env['PYTHON_LIBNAME_SO_ABI_FLAG'] = '-cp' + python_abi_version
     else:
-        conf.env['PYTHON_SO_ABI_FLAG'] = ''
         conf.env['PYTHON_LIBNAME_SO_ABI_FLAG'] = ''
 
     for lib in conf.env['LINKFLAGS_PYEMBED']:
-- 
2.17.0



More information about the samba-technical mailing list