All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] libselinux, libsemanage: use Python-specific .so extension
@ 2016-11-17 21:50 Nicolas Iooss
  2016-11-18 13:56 ` Stephen Smalley
  0 siblings, 1 reply; 2+ messages in thread
From: Nicolas Iooss @ 2016-11-17 21:50 UTC (permalink / raw)
  To: selinux

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 <nicolas.iooss@m4x.org>
---
 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 928cc049cedb..d17792c13350 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 5176582f654d..ef25902bb019 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)
 
 
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] libselinux, libsemanage: use Python-specific .so extension
  2016-11-17 21:50 [PATCH 1/1] libselinux, libsemanage: use Python-specific .so extension Nicolas Iooss
@ 2016-11-18 13:56 ` Stephen Smalley
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Smalley @ 2016-11-18 13:56 UTC (permalink / raw)
  To: Nicolas Iooss, selinux

On 11/17/2016 04:50 PM, Nicolas Iooss wrote:
> 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 <nicolas.iooss@m4x.org>

Thanks, applied

> ---
>  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 928cc049cedb..d17792c13350 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 5176582f654d..ef25902bb019 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)
>  
>  
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-18 13:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-17 21:50 [PATCH 1/1] libselinux, libsemanage: use Python-specific .so extension Nicolas Iooss
2016-11-18 13:56 ` Stephen Smalley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.