Gentoo Archives: gentoo-commits

From: Jason Zaman <perfinion@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-libs/libselinux/, sys-libs/libselinux/files/
Date: Sun, 01 Sep 2019 10:20:00
Message-Id: 1567330352.079ce1fb1893c226c1cdbbff9e85e0450cae8839.perfinion@gentoo
1 commit: 079ce1fb1893c226c1cdbbff9e85e0450cae8839
2 Author: Jason Zaman <perfinion <AT> gentoo <DOT> org>
3 AuthorDate: Sun Sep 1 09:31:58 2019 +0000
4 Commit: Jason Zaman <perfinion <AT> gentoo <DOT> org>
5 CommitDate: Sun Sep 1 09:32:32 2019 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=079ce1fb
7
8 sys-libs/libselinux: Add compatibility with swig-4
9
10 Swig-4 changed how the native lib is imported, so backport
11 2efa06857575e4118e91ca250b6b92da68b130d5 to fix.
12
13 Closes: https://bugs.gentoo.org/691720
14 Package-Manager: Portage-2.3.69, Repoman-2.3.16
15 Signed-off-by: Jason Zaman <perfinion <AT> gentoo.org>
16
17 ...Use-Python-distutils-to-install-SELinux-p.patch | 205 +++++++++++++++++++++
18 ...selinux-2.9.ebuild => libselinux-2.9-r1.ebuild} | 7 +-
19 sys-libs/libselinux/libselinux-2.9.ebuild | 4 +-
20 3 files changed, 212 insertions(+), 4 deletions(-)
21
22 diff --git a/sys-libs/libselinux/files/0001-libselinux-Use-Python-distutils-to-install-SELinux-p.patch b/sys-libs/libselinux/files/0001-libselinux-Use-Python-distutils-to-install-SELinux-p.patch
23 new file mode 100644
24 index 00000000000..896876a00d6
25 --- /dev/null
26 +++ b/sys-libs/libselinux/files/0001-libselinux-Use-Python-distutils-to-install-SELinux-p.patch
27 @@ -0,0 +1,205 @@
28 +From 2efa06857575e4118e91ca250b6b92da68b130d5 Mon Sep 17 00:00:00 2001
29 +From: Petr Lautrbach <plautrba@××××××.com>
30 +Date: Fri, 7 Jun 2019 17:35:44 +0200
31 +Subject: [PATCH] libselinux: Use Python distutils to install SELinux python
32 + bindings
33 +
34 +Follow officially documented way how to build C extension modules using
35 +distutils - https://docs.python.org/3.8/extending/building.html#building
36 +
37 +Fixes:
38 +
39 +- selinux python module fails to load when it's built using SWIG-4.0:
40 +
41 +>>> import selinux
42 +Traceback (most recent call last):
43 + File "<stdin>", line 1, in <module>
44 + File "/usr/lib64/python3.7/site-packages/selinux/__init__.py", line 13, in <module>
45 + from . import _selinux
46 +ImportError: cannot import name '_selinux' from 'selinux' (/usr/lib64/python3.7/site-packages/selinux/__init__.py)
47 +
48 +SWIG-4.0 changed (again?) its behavior so that it uses: from . import _selinux
49 +which looks for _selinux module in the same directory as where __init__.py is -
50 +$(PYLIBDIR)/site-packages/selinux. But _selinux module is installed into
51 +$(PYLIBDIR)/site-packages/ since a9604c30a5e2f ("libselinux: Change the location
52 +of _selinux.so").
53 +
54 +- audit2why python module fails to build with Python 3.8
55 +
56 +cc -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -DOVERRIDE_GETTID=0 -I../include -D_GNU_SOURCE -DDISABLE_RPM -DNO_ANDROID_BACKEND -DUSE_PCRE2 -DPCRE2_CODE_UNIT_WIDTH=8 -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -L. -shared -o python-3.8audit2why.so python-3.8audit2why.lo -lselinux -l:libsepol.a -Wl,-soname,audit2why.so,--version-script=audit2why.map,-z,defs
57 +/usr/bin/ld: python-3.8audit2why.lo: in function `finish':
58 +/builddir/build/BUILD/libselinux-2.9/src/audit2why.c:166: undefined reference to `PyArg_ParseTuple'
59 +/usr/bin/ld: python-3.8audit2why.lo: in function `_Py_INCREF':
60 +/usr/include/python3.8/object.h:449: undefined reference to `_Py_NoneStruct'
61 +/usr/bin/ld: /usr/include/python3.8/object.h:449: undefined reference to `_Py_NoneStruct'
62 +/usr/bin/ld: python-3.8audit2why.lo: in function `check_booleans':
63 +/builddir/build/BUILD/libselinux-2.9/src/audit2why.c:84: undefined reference to `PyExc_RuntimeError'
64 +...
65 +
66 +It's related to the following Python change
67 +https://docs.python.org/dev/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build
68 +
69 +Python distutils adds correct link options automatically.
70 +
71 +- selinux python module doesn't provide any Python metadata
72 +
73 +When selinux python module was built manually, it didn't provide any metadata.
74 +distutils takes care about that so that selinux Python module is visible for
75 +pip:
76 +
77 +$ pip3 list | grep selinux
78 +selinux 2.9
79 +
80 +Signed-off-by: Petr Lautrbach <plautrba@××××××.com>
81 +---
82 + libselinux/src/.gitignore | 2 +-
83 + libselinux/src/Makefile | 36 ++++++++----------------------------
84 + libselinux/src/setup.py | 24 ++++++++++++++++++++++++
85 + 3 files changed, 33 insertions(+), 29 deletions(-)
86 + create mode 100644 libselinux/src/setup.py
87 +
88 +diff --git libselinux/src/.gitignore libselinux/src/.gitignore
89 +index 4dcc3b3b..428afe5a 100644
90 +--- libselinux/src/.gitignore
91 ++++ libselinux/src/.gitignore
92 +@@ -1,4 +1,4 @@
93 + selinux.py
94 +-selinuxswig_wrap.c
95 ++selinuxswig_python_wrap.c
96 + selinuxswig_python_exception.i
97 + selinuxswig_ruby_wrap.c
98 +diff --git libselinux/src/Makefile libselinux/src/Makefile
99 +index e9ed0383..2b1696a0 100644
100 +--- libselinux/src/Makefile
101 ++++ libselinux/src/Makefile
102 +@@ -36,7 +36,7 @@ TARGET=libselinux.so
103 + LIBPC=libselinux.pc
104 + SWIGIF= selinuxswig_python.i selinuxswig_python_exception.i
105 + SWIGRUBYIF= selinuxswig_ruby.i
106 +-SWIGCOUT= selinuxswig_wrap.c
107 ++SWIGCOUT= selinuxswig_python_wrap.c
108 + SWIGPYOUT= selinux.py
109 + SWIGRUBYCOUT= selinuxswig_ruby_wrap.c
110 + SWIGLOBJ:= $(patsubst %.c,$(PYPREFIX)%.lo,$(SWIGCOUT))
111 +@@ -55,7 +55,7 @@ ifeq ($(LIBSEPOLA),)
112 + LDLIBS_LIBSEPOLA := -l:libsepol.a
113 + endif
114 +
115 +-GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) selinuxswig_python_exception.i
116 ++GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) $(SWIGCOUT) selinuxswig_python_exception.i
117 + SRCS= $(filter-out $(GENERATED) audit2why.c, $(sort $(wildcard *.c)))
118 +
119 + MAX_STACK_SIZE=32768
120 +@@ -125,25 +125,18 @@ DISABLE_FLAGS+= -DNO_ANDROID_BACKEND
121 + SRCS:= $(filter-out label_backends_android.c, $(SRCS))
122 + endif
123 +
124 +-SWIG = swig -Wall -python -o $(SWIGCOUT) -outdir ./ $(DISABLE_FLAGS)
125 +-
126 + SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./ $(DISABLE_FLAGS)
127 +
128 + all: $(LIBA) $(LIBSO) $(LIBPC)
129 +
130 +-pywrap: all $(SWIGFILES) $(AUDIT2WHYSO)
131 ++pywrap: all selinuxswig_python_exception.i
132 ++ CFLAGS="$(CFLAGS) $(SWIG_CFLAGS)" $(PYTHON) setup.py build_ext -I $(DESTDIR)$(INCLUDEDIR) -L $(DESTDIR)$(LIBDIR)
133 +
134 + rubywrap: all $(SWIGRUBYSO)
135 +
136 +-$(SWIGLOBJ): $(SWIGCOUT)
137 +- $(CC) $(CFLAGS) $(SWIG_CFLAGS) $(PYINC) -fPIC -DSHARED -c -o $@ $<
138 +-
139 + $(SWIGRUBYLOBJ): $(SWIGRUBYCOUT)
140 + $(CC) $(CFLAGS) $(SWIG_CFLAGS) $(RUBYINC) -fPIC -DSHARED -c -o $@ $<
141 +
142 +-$(SWIGSO): $(SWIGLOBJ)
143 +- $(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $< -lselinux $(PYLIBS)
144 +-
145 + $(SWIGRUBYSO): $(SWIGRUBYLOBJ)
146 + $(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $^ -lselinux $(RUBYLIBS)
147 +
148 +@@ -161,29 +154,15 @@ $(LIBPC): $(LIBPC).in ../VERSION
149 + selinuxswig_python_exception.i: ../include/selinux/selinux.h
150 + bash -e exception.sh > $@ || (rm -f $@ ; false)
151 +
152 +-$(AUDIT2WHYLOBJ): audit2why.c
153 +- $(CC) $(filter-out -Werror, $(CFLAGS)) $(PYINC) -fPIC -DSHARED -c -o $@ $<
154 +-
155 +-$(AUDIT2WHYSO): $(AUDIT2WHYLOBJ) $(LIBSEPOLA)
156 +- $(CC) $(CFLAGS) $(LDFLAGS) -L. -shared -o $@ $^ -lselinux $(LDLIBS_LIBSEPOLA) $(PYLIBS) -Wl,-soname,audit2why.so,--version-script=audit2why.map,-z,defs
157 +-
158 + %.o: %.c policy.h
159 + $(CC) $(CFLAGS) $(TLSFLAGS) -c -o $@ $<
160 +
161 + %.lo: %.c policy.h
162 + $(CC) $(CFLAGS) -fPIC -DSHARED -c -o $@ $<
163 +
164 +-$(SWIGCOUT): $(SWIGIF)
165 +- $(SWIG) $<
166 +-
167 +-$(SWIGPYOUT): $(SWIGCOUT)
168 +-
169 + $(SWIGRUBYCOUT): $(SWIGRUBYIF)
170 + $(SWIGRUBY) $<
171 +
172 +-swigify: $(SWIGIF)
173 +- $(SWIG) $<
174 +-
175 + install: all
176 + test -d $(DESTDIR)$(LIBDIR) || install -m 755 -d $(DESTDIR)$(LIBDIR)
177 + install -m 644 $(LIBA) $(DESTDIR)$(LIBDIR)
178 +@@ -194,10 +173,9 @@ install: all
179 + ln -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
180 +
181 + install-pywrap: pywrap
182 +- test -d $(DESTDIR)$(PYTHONLIBDIR)/selinux || install -m 755 -d $(DESTDIR)$(PYTHONLIBDIR)/selinux
183 +- install -m 755 $(SWIGSO) $(DESTDIR)$(PYTHONLIBDIR)/_selinux$(PYCEXT)
184 +- install -m 755 $(AUDIT2WHYSO) $(DESTDIR)$(PYTHONLIBDIR)/selinux/audit2why$(PYCEXT)
185 ++ $(PYTHON) setup.py install --prefix=$(PREFIX) `test -n "$(DESTDIR)" && echo --root $(DESTDIR)`
186 + install -m 644 $(SWIGPYOUT) $(DESTDIR)$(PYTHONLIBDIR)/selinux/__init__.py
187 ++ ln -sf --relative $(DESTDIR)$(PYTHONLIBDIR)/selinux/_selinux$(PYCEXT) $(DESTDIR)$(PYTHONLIBDIR)/_selinux$(PYCEXT)
188 +
189 + install-rubywrap: rubywrap
190 + test -d $(DESTDIR)$(RUBYINSTALL) || install -m 755 -d $(DESTDIR)$(RUBYINSTALL)
191 +@@ -208,6 +186,8 @@ relabel:
192 +
193 + clean-pywrap:
194 + -rm -f $(SWIGLOBJ) $(SWIGSO) $(AUDIT2WHYLOBJ) $(AUDIT2WHYSO)
195 ++ $(PYTHON) setup.py clean
196 ++ -rm -rf build *~ \#* *pyc .#*
197 +
198 + clean-rubywrap:
199 + -rm -f $(SWIGRUBYLOBJ) $(SWIGRUBYSO)
200 +diff --git libselinux/src/setup.py libselinux/src/setup.py
201 +new file mode 100644
202 +index 00000000..4dc03f55
203 +--- /dev/null
204 ++++ libselinux/src/setup.py
205 +@@ -0,0 +1,24 @@
206 ++#!/usr/bin/python3
207 ++
208 ++from distutils.core import Extension, setup
209 ++
210 ++setup(
211 ++ name="selinux",
212 ++ version="2.9",
213 ++ description="SELinux python 3 bindings",
214 ++ author="SELinux Project",
215 ++ author_email="selinux@×××××××××××.org",
216 ++ ext_modules=[
217 ++ Extension('selinux._selinux',
218 ++ sources=['selinuxswig_python.i'],
219 ++ include_dirs=['../include'],
220 ++ library_dirs=['.'],
221 ++ libraries=['selinux']),
222 ++ Extension('selinux.audit2why',
223 ++ sources=['audit2why.c'],
224 ++ include_dirs=['../include'],
225 ++ library_dirs=['.'],
226 ++ libraries=['selinux'],
227 ++ extra_link_args=['-l:libsepol.a', '-Wl,--version-script=audit2why.map'])
228 ++ ],
229 ++)
230 +--
231 +2.21.0
232 +
233
234 diff --git a/sys-libs/libselinux/libselinux-2.9.ebuild b/sys-libs/libselinux/libselinux-2.9-r1.ebuild
235 similarity index 96%
236 copy from sys-libs/libselinux/libselinux-2.9.ebuild
237 copy to sys-libs/libselinux/libselinux-2.9-r1.ebuild
238 index 8c1c79a1fae..0a941fc9a82 100644
239 --- a/sys-libs/libselinux/libselinux-2.9.ebuild
240 +++ b/sys-libs/libselinux/libselinux-2.9-r1.ebuild
241 @@ -21,7 +21,7 @@ if [[ ${PV} == 9999 ]] ; then
242 S="${WORKDIR}/${MY_P}/${PN}"
243 else
244 SRC_URI="https://github.com/SELinuxProject/selinux/releases/download/${MY_RELEASEDATE}/${MY_P}.tar.gz"
245 - KEYWORDS="amd64 ~arm ~arm64 ~mips x86"
246 + KEYWORDS="~amd64 ~arm ~arm64 ~mips ~x86"
247 S="${WORKDIR}/${MY_P}"
248 fi
249
250 @@ -43,9 +43,12 @@ DEPEND="${RDEPEND}
251 virtual/pkgconfig
252 python? ( >=dev-lang/swig-2.0.9 )
253 ruby? ( >=dev-lang/swig-2.0.9 )"
254 +PATCHES=(
255 + "${FILESDIR}/0001-libselinux-Use-Python-distutils-to-install-SELinux-p.patch"
256 +)
257
258 src_prepare() {
259 - eapply_user
260 + default
261
262 multilib_copy_sources
263 }
264
265 diff --git a/sys-libs/libselinux/libselinux-2.9.ebuild b/sys-libs/libselinux/libselinux-2.9.ebuild
266 index 8c1c79a1fae..01eb86ea822 100644
267 --- a/sys-libs/libselinux/libselinux-2.9.ebuild
268 +++ b/sys-libs/libselinux/libselinux-2.9.ebuild
269 @@ -41,8 +41,8 @@ RDEPEND=">=sys-libs/libsepol-${SEPOL_VER}:=[${MULTILIB_USEDEP}]
270 elibc_musl? ( sys-libs/fts-standalone )"
271 DEPEND="${RDEPEND}
272 virtual/pkgconfig
273 - python? ( >=dev-lang/swig-2.0.9 )
274 - ruby? ( >=dev-lang/swig-2.0.9 )"
275 + python? ( <dev-lang/swig-4_pre )
276 + ruby? ( <dev-lang/swig-4_pre )"
277
278 src_prepare() {
279 eapply_user