ytakagi / rpms / libselinux

Forked from rpms/libselinux 4 years ago
Clone

Blame SOURCES/0006-libselinux-Use-Python-distutils-to-install-SELinux-p.patch

b2442d
From 67d490a38a319126f371eaf66a5fc922d7005b1f Mon Sep 17 00:00:00 2001
b2442d
From: Petr Lautrbach <plautrba@redhat.com>
b2442d
Date: Thu, 16 May 2019 15:01:59 +0200
b2442d
Subject: [PATCH 6/6] libselinux: Use Python distutils to install SELinux
b2442d
 python bindings
b2442d
b2442d
SWIG-4.0 changed its behavior so that it uses: from . import _selinux  which
b2442d
looks for _selinux module in the same directory as where __init__.py is -
b2442d
$(PYLIBDIR)/site-packages/selinux. But _selinux module is installed into
b2442d
$(PYLIBDIR)/site-packages/ since a9604c30a5e2f ("libselinux: Change the location
b2442d
of _selinux.so").
b2442d
b2442d
In order to prevent such breakage in future use Python's distutils instead of
b2442d
building and installing python bindings manually in Makefile.
b2442d
b2442d
Fixes:
b2442d
>>> import selinux
b2442d
Traceback (most recent call last):
b2442d
  File "<stdin>", line 1, in <module>
b2442d
  File "/usr/lib64/python3.7/site-packages/selinux/__init__.py", line 13, in <module>
b2442d
    from . import _selinux
b2442d
ImportError: cannot import name '_selinux' from 'selinux' (/usr/lib64/python3.7/site-packages/selinux/__init__.py)
b2442d
>>>
b2442d
b2442d
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
b2442d
---
b2442d
 libselinux/src/.gitignore |  2 +-
b2442d
 libselinux/src/Makefile   | 37 ++++++++-----------------------------
b2442d
 libselinux/src/setup.py   | 24 ++++++++++++++++++++++++
b2442d
 3 files changed, 33 insertions(+), 30 deletions(-)
b2442d
 create mode 100644 libselinux/src/setup.py
b2442d
b2442d
diff --git a/libselinux/src/.gitignore b/libselinux/src/.gitignore
b2442d
index 4dcc3b3b..428afe5a 100644
b2442d
--- a/libselinux/src/.gitignore
b2442d
+++ b/libselinux/src/.gitignore
b2442d
@@ -1,4 +1,4 @@
b2442d
 selinux.py
b2442d
-selinuxswig_wrap.c
b2442d
+selinuxswig_python_wrap.c
b2442d
 selinuxswig_python_exception.i
b2442d
 selinuxswig_ruby_wrap.c
b2442d
diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
b2442d
index e9ed0383..826c830c 100644
b2442d
--- a/libselinux/src/Makefile
b2442d
+++ b/libselinux/src/Makefile
b2442d
@@ -36,7 +36,7 @@ TARGET=libselinux.so
b2442d
 LIBPC=libselinux.pc
b2442d
 SWIGIF= selinuxswig_python.i selinuxswig_python_exception.i
b2442d
 SWIGRUBYIF= selinuxswig_ruby.i
b2442d
-SWIGCOUT= selinuxswig_wrap.c
b2442d
+SWIGCOUT= selinuxswig_python_wrap.c
b2442d
 SWIGPYOUT= selinux.py
b2442d
 SWIGRUBYCOUT= selinuxswig_ruby_wrap.c
b2442d
 SWIGLOBJ:= $(patsubst %.c,$(PYPREFIX)%.lo,$(SWIGCOUT))
b2442d
@@ -55,7 +55,7 @@ ifeq ($(LIBSEPOLA),)
b2442d
         LDLIBS_LIBSEPOLA := -l:libsepol.a
b2442d
 endif
b2442d
 
b2442d
-GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) selinuxswig_python_exception.i
b2442d
+GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) $(SWIGCOUT) selinuxswig_python_exception.i
b2442d
 SRCS= $(filter-out $(GENERATED) audit2why.c, $(sort $(wildcard *.c)))
b2442d
 
b2442d
 MAX_STACK_SIZE=32768
b2442d
@@ -125,25 +125,18 @@ DISABLE_FLAGS+= -DNO_ANDROID_BACKEND
b2442d
 SRCS:= $(filter-out label_backends_android.c, $(SRCS))
b2442d
 endif
b2442d
 
b2442d
-SWIG = swig -Wall -python -o $(SWIGCOUT) -outdir ./ $(DISABLE_FLAGS)
b2442d
-
b2442d
 SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./ $(DISABLE_FLAGS)
b2442d
 
b2442d
 all: $(LIBA) $(LIBSO) $(LIBPC)
b2442d
 
b2442d
-pywrap: all $(SWIGFILES) $(AUDIT2WHYSO)
b2442d
+pywrap: all selinuxswig_python_exception.i
b2442d
+	CFLAGS="$(SWIG_CFLAGS)" $(PYTHON) setup.py build_ext -I $(DESTDIR)$(INCLUDEDIR) -L $(DESTDIR)$(LIBDIR)
b2442d
 
b2442d
 rubywrap: all $(SWIGRUBYSO)
b2442d
 
b2442d
-$(SWIGLOBJ): $(SWIGCOUT)
b2442d
-	$(CC) $(CFLAGS) $(SWIG_CFLAGS) $(PYINC) -fPIC -DSHARED -c -o $@ $<
b2442d
-
b2442d
 $(SWIGRUBYLOBJ): $(SWIGRUBYCOUT)
b2442d
 	$(CC) $(CFLAGS) $(SWIG_CFLAGS) $(RUBYINC) -fPIC -DSHARED -c -o $@ $<
b2442d
 
b2442d
-$(SWIGSO): $(SWIGLOBJ)
b2442d
-	$(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $< -lselinux $(PYLIBS)
b2442d
-
b2442d
 $(SWIGRUBYSO): $(SWIGRUBYLOBJ)
b2442d
 	$(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $^ -lselinux $(RUBYLIBS)
b2442d
 
b2442d
@@ -161,29 +154,15 @@ $(LIBPC): $(LIBPC).in ../VERSION
b2442d
 selinuxswig_python_exception.i: ../include/selinux/selinux.h
b2442d
 	bash -e exception.sh > $@ || (rm -f $@ ; false)
b2442d
 
b2442d
-$(AUDIT2WHYLOBJ): audit2why.c
b2442d
-	$(CC) $(filter-out -Werror, $(CFLAGS)) $(PYINC) -fPIC -DSHARED -c -o $@ $<
b2442d
-
b2442d
-$(AUDIT2WHYSO): $(AUDIT2WHYLOBJ) $(LIBSEPOLA)
b2442d
-	$(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $^ -lselinux $(LDLIBS_LIBSEPOLA) $(PYLIBS) -Wl,-soname,audit2why.so,--version-script=audit2why.map,-z,defs
b2442d
-
b2442d
 %.o:  %.c policy.h
b2442d
 	$(CC) $(CFLAGS) $(TLSFLAGS) -c -o $@ $<
b2442d
 
b2442d
 %.lo:  %.c policy.h
b2442d
 	$(CC) $(CFLAGS) -fPIC -DSHARED -c -o $@ $<
b2442d
 
b2442d
-$(SWIGCOUT): $(SWIGIF)
b2442d
-	$(SWIG) $<
b2442d
-
b2442d
-$(SWIGPYOUT): $(SWIGCOUT)
b2442d
-
b2442d
 $(SWIGRUBYCOUT): $(SWIGRUBYIF)
b2442d
 	$(SWIGRUBY) $<
b2442d
 
b2442d
-swigify: $(SWIGIF)
b2442d
-	$(SWIG) $<
b2442d
-
b2442d
 install: all 
b2442d
 	test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
b2442d
 	install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
b2442d
@@ -194,10 +173,8 @@ install: all
b2442d
 	ln -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
b2442d
 
b2442d
 install-pywrap: pywrap
b2442d
-	test -d $(DESTDIR)$(PYTHONLIBDIR)/selinux || install -m 755 -d $(DESTDIR)$(PYTHONLIBDIR)/selinux
b2442d
-	install -m 755 $(SWIGSO) $(DESTDIR)$(PYTHONLIBDIR)/_selinux$(PYCEXT)
b2442d
-	install -m 755 $(AUDIT2WHYSO) $(DESTDIR)$(PYTHONLIBDIR)/selinux/audit2why$(PYCEXT)
b2442d
-	install -m 644 $(SWIGPYOUT) $(DESTDIR)$(PYTHONLIBDIR)/selinux/__init__.py
b2442d
+	$(PYTHON) setup.py install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR)`
b2442d
+	install -m 644 selinux.py $(DESTDIR)$(PYTHONLIBDIR)/selinux/__init__.py
b2442d
 
b2442d
 install-rubywrap: rubywrap
b2442d
 	test -d $(DESTDIR)$(RUBYINSTALL) || install -m 755 -d $(DESTDIR)$(RUBYINSTALL) 
b2442d
@@ -208,6 +185,8 @@ relabel:
b2442d
 
b2442d
 clean-pywrap:
b2442d
 	-rm -f $(SWIGLOBJ) $(SWIGSO) $(AUDIT2WHYLOBJ) $(AUDIT2WHYSO)
b2442d
+	$(PYTHON) setup.py clean
b2442d
+	-rm -rf build *~ \#* *pyc .#*
b2442d
 
b2442d
 clean-rubywrap:
b2442d
 	-rm -f $(SWIGRUBYLOBJ) $(SWIGRUBYSO)
b2442d
diff --git a/libselinux/src/setup.py b/libselinux/src/setup.py
b2442d
new file mode 100644
b2442d
index 00000000..b12e7869
b2442d
--- /dev/null
b2442d
+++ b/libselinux/src/setup.py
b2442d
@@ -0,0 +1,24 @@
b2442d
+#!/usr/bin/python3
b2442d
+
b2442d
+from distutils.core import Extension, setup
b2442d
+
b2442d
+setup(
b2442d
+    name="selinux",
b2442d
+    version="2.9",
b2442d
+    description="SELinux python 3 bindings",
b2442d
+    author="SELinux Project",
b2442d
+    author_email="selinux@vger.kernel.org",
b2442d
+    ext_modules=[
b2442d
+        Extension('selinux._selinux',
b2442d
+                  sources=['selinuxswig_python.i'],
b2442d
+                  include_dirs=['../include'],
b2442d
+                  library_dirs=['.'],
b2442d
+                  libraries=['selinux']),
b2442d
+        Extension('selinux.audit2why',
b2442d
+                  sources=['audit2why.c'],
b2442d
+                  include_dirs=['../include'],
b2442d
+                  library_dirs=['.'],
b2442d
+                  libraries=['selinux'],
b2442d
+                  extra_link_args=['-l:libsepol.a'])
b2442d
+    ],
b2442d
+)
b2442d
-- 
b2442d
2.22.0
b2442d