From 9140de74cf3f156c7aa4e7e65882288bf3e388df Mon Sep 17 00:00:00 2001 From: Nicolas Iooss Date: Thu, 17 Nov 2016 22:50:18 +0100 Subject: [PATCH] libselinux, libsemanage: use Python-specific .so extension The Makefiles currently install the Python wrapper libraries using .so suffix (_selinux.so, audit2why.so and _semanage.so). Even though this works well with CPython 2 and 3, PyPy fails to find these files because it is looking for files with a specific version token in the suffix (eg. _selinux.pypy-41.so). This suffix is advertised by the imp module. Here is the result of 'import imp;print([s for s, m, t in imp.get_suffixes() if t == imp.C_EXTENSION])' for several Python versions: Python 2.7.12: ['.so', 'module.so'] Python 3.5.2: ['.cpython-35m-x86_64-linux-gnu.so', '.abi3.so', '.so'] PyPy 5.4.1 (Python 2.7.10): ['.pypy-41.so'] PyPy3 5.5.0-alpha0 (Python 3.3.5): ['.pypy3-55.so', '.pypy3-55.so'] Define the name of the installed Python-C extension using the first extension of these lists, in order to make the Python extensions compatible with pypy. When building the Python wrappers for PyPy and PyPy3 on Linux, the following environment variables need to be set (PyPy does not provide a pkg-config file nor a platform-agnostic way to build the string "-lpypy-c"): PYTHON=pypy (or PYTHON=pypy3) PYINC=-I$($PYTHON -c 'import sys;print(sys.prefix)')/include PYLIBS=-lpypy-c (or PYLIBS= if LDFLAGS does not have -Wl,-no-undefined) Signed-off-by: Nicolas Iooss --- libselinux/src/Makefile | 5 +++-- libsemanage/src/Makefile | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile index 928cc049..d17792c1 100644 --- a/libselinux/src/Makefile +++ b/libselinux/src/Makefile @@ -15,6 +15,7 @@ INCLUDEDIR ?= $(PREFIX)/include PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX)) PYLIBS ?= $(shell $(PKG_CONFIG) --libs $(PYPREFIX)) PYSITEDIR ?= $(DESTDIR)$(shell $(PYTHON) -c 'import site; print(site.getsitepackages()[0])') +PYCEXT ?= $(shell $(PYTHON) -c 'import imp;print([s for s,m,t in imp.get_suffixes() if t == imp.C_EXTENSION][0])') RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + RbConfig::CONFIG["rubyarchhdrdir"] + " -I" + RbConfig::CONFIG["rubyhdrdir"]') RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " -lruby"') RUBYINSTALL ?= $(DESTDIR)$(shell $(RUBY) -e 'puts RbConfig::CONFIG["vendorarchdir"]') @@ -185,8 +186,8 @@ install: all install-pywrap: pywrap test -d $(PYSITEDIR)/selinux || install -m 755 -d $(PYSITEDIR)/selinux - install -m 755 $(SWIGSO) $(PYSITEDIR)/_selinux.so - install -m 755 $(AUDIT2WHYSO) $(PYSITEDIR)/selinux/audit2why.so + install -m 755 $(SWIGSO) $(PYSITEDIR)/_selinux$(PYCEXT) + install -m 755 $(AUDIT2WHYSO) $(PYSITEDIR)/selinux/audit2why$(PYCEXT) install -m 644 $(SWIGPYOUT) $(PYSITEDIR)/selinux/__init__.py install-rubywrap: rubywrap diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile index 5176582f..ef25902b 100644 --- a/libsemanage/src/Makefile +++ b/libsemanage/src/Makefile @@ -15,6 +15,7 @@ INCLUDEDIR ?= $(PREFIX)/include PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX)) PYLIBS ?= $(shell $(PKG_CONFIG) --libs $(PYPREFIX)) PYSITEDIR ?= $(DESTDIR)$(shell $(PYTHON) -c 'import site; print(site.getsitepackages()[0])') +PYCEXT ?= $(shell $(PYTHON) -c 'import imp;print([s for s,m,t in imp.get_suffixes() if t == imp.C_EXTENSION][0])') RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + RbConfig::CONFIG["rubyarchhdrdir"] + " -I" + RbConfig::CONFIG["rubyhdrdir"]') RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " -lruby"') RUBYINSTALL ?= $(DESTDIR)$(shell $(RUBY) -e 'puts RbConfig::CONFIG["vendorarchdir"]') @@ -145,7 +146,7 @@ install: all install-pywrap: pywrap test -d $(PYSITEDIR) || install -m 755 -d $(PYSITEDIR) - install -m 755 $(SWIGSO) $(PYSITEDIR)/_semanage.so + install -m 755 $(SWIGSO) $(PYSITEDIR)/_semanage$(PYCEXT) install -m 644 semanage.py $(PYSITEDIR)