Skip to content

Commit 1fce703

Browse files
committed
libselinux,libsemanage: Replace PYSITEDIR with PYTHONLIBDIR
libselinux and libsemanage Makefiles use site.getsitepackages() in order to get the path to /usr/lib/pythonX.Y/site-packages relevant to the Python interpreter selected with $(PYTHON). This method is incompatible with Python virtual environments, as described in pypa/virtualenv#355 (comment) which has been opened for more than 5 years. On the contrary python/semanage and python/sepolgen Makefiles use distutils.sysconfig.get_python_lib() in order to get the site-packages path into a variable named PYTHONLIBDIR. This way of computing PYTHONLIBDIR is compatible with virtual environments and gives the same result as PYSITEDIR. As PYTHONLIBDIR works in more cases than PYSITEDIR, make libselinux and libsemanage Makefiles use it. Signed-off-by: Nicolas Iooss <[email protected]>
1 parent 21d749b commit 1fce703

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ before_script:
9696
- export PKG_CONFIG_PATH="/opt/python/$($PYTHON -c 'import sys;print("%d.%d.%d" % sys.version_info[:3])')/lib/pkgconfig"
9797
# PyPy does not provide a config file for pkg-config nor a pypy-c.so
9898
- if echo "$PYVER" | grep -q pypy ; then export PYINC=-I$($PYTHON -c 'import sys;print(sys.prefix)')/include PYLIBS= ; fi
99-
# Python virtualenvs do not support "import site; print(site.getsitepackages()[0]"
100-
# cf. https://github.com/pypa/virtualenv/issues/355#issuecomment-10250452
101-
- export PYSITEDIR="/usr/lib/$($PYTHON -c 'import sys;print("python%d.%d" % sys.version_info[:2])')/site-packages"
10299

103100
# Find the Ruby executable with version $RUBYLIBVER
104101
- export RUBY="$(ls -d -1 "$HOME/.rvm/rubies/ruby-$RUBYLIBVER"*/bin/ruby | head -n 1)"
@@ -126,7 +123,7 @@ script:
126123
# Set up environment variables for the tests
127124
- export LD_LIBRARY_PATH="$DESTDIR/usr/lib:$DESTDIR/lib"
128125
- export PATH="$DESTDIR/usr/sbin:$DESTDIR/usr/bin:$DESTDIR/sbin:$DESTDIR/bin:$PATH"
129-
- export PYTHONPATH="$DESTDIR$PYSITEDIR"
126+
- export PYTHONPATH="$DESTDIR$($PYTHON -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr'))")"
130127
- export RUBYLIB="$DESTDIR/$($RUBY -e 'puts RbConfig::CONFIG["vendorlibdir"]'):$DESTDIR/$($RUBY -e 'puts RbConfig::CONFIG["vendorarchdir"]')"
131128

132129
# Show variables (to help debugging issues)

libselinux/src/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ SHLIBDIR ?= /lib
1414
INCLUDEDIR ?= $(PREFIX)/include
1515
PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
1616
PYLIBS ?= $(shell $(PKG_CONFIG) --libs $(PYPREFIX))
17-
PYSITEDIR ?= $(shell $(PYTHON) -c 'import site; print(site.getsitepackages()[0])')
17+
PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; print(get_python_lib(prefix='$(PREFIX)'))")
1818
PYCEXT ?= $(shell $(PYTHON) -c 'import imp;print([s for s,m,t in imp.get_suffixes() if t == imp.C_EXTENSION][0])')
1919
RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + RbConfig::CONFIG["rubyarchhdrdir"] + " -I" + RbConfig::CONFIG["rubyhdrdir"]')
2020
RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " -L" + RbConfig::CONFIG["archlibdir"] + " " + RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
@@ -205,10 +205,10 @@ install: all
205205
ln -sf --relative $(DESTDIR)$(SHLIBDIR)/$(LIBSO) $(DESTDIR)$(LIBDIR)/$(TARGET)
206206

207207
install-pywrap: pywrap
208-
test -d $(DESTDIR)$(PYSITEDIR)/selinux || install -m 755 -d $(DESTDIR)$(PYSITEDIR)/selinux
209-
install -m 755 $(SWIGSO) $(DESTDIR)$(PYSITEDIR)/_selinux$(PYCEXT)
210-
install -m 755 $(AUDIT2WHYSO) $(DESTDIR)$(PYSITEDIR)/selinux/audit2why$(PYCEXT)
211-
install -m 644 $(SWIGPYOUT) $(DESTDIR)$(PYSITEDIR)/selinux/__init__.py
208+
test -d $(DESTDIR)$(PYTHONLIBDIR)/selinux || install -m 755 -d $(DESTDIR)$(PYTHONLIBDIR)/selinux
209+
install -m 755 $(SWIGSO) $(DESTDIR)$(PYTHONLIBDIR)/_selinux$(PYCEXT)
210+
install -m 755 $(AUDIT2WHYSO) $(DESTDIR)$(PYTHONLIBDIR)/selinux/audit2why$(PYCEXT)
211+
install -m 644 $(SWIGPYOUT) $(DESTDIR)$(PYTHONLIBDIR)/selinux/__init__.py
212212

213213
install-rubywrap: rubywrap
214214
test -d $(DESTDIR)$(RUBYINSTALL) || install -m 755 -d $(DESTDIR)$(RUBYINSTALL)

libsemanage/src/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LIBDIR ?= $(PREFIX)/lib
1313
INCLUDEDIR ?= $(PREFIX)/include
1414
PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
1515
PYLIBS ?= $(shell $(PKG_CONFIG) --libs $(PYPREFIX))
16-
PYSITEDIR ?= $(shell $(PYTHON) -c 'import site; print(site.getsitepackages()[0])')
16+
PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; print(get_python_lib(prefix='$(PREFIX)'))")
1717
PYCEXT ?= $(shell $(PYTHON) -c 'import imp;print([s for s,m,t in imp.get_suffixes() if t == imp.C_EXTENSION][0])')
1818
RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + RbConfig::CONFIG["rubyarchhdrdir"] + " -I" + RbConfig::CONFIG["rubyhdrdir"]')
1919
RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " -L" + RbConfig::CONFIG["archlibdir"] + " " + RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
@@ -136,9 +136,9 @@ install: all
136136
cd $(DESTDIR)$(LIBDIR) && ln -sf $(LIBSO) $(TARGET)
137137

138138
install-pywrap: pywrap
139-
test -d $(DESTDIR)$(PYSITEDIR) || install -m 755 -d $(DESTDIR)$(PYSITEDIR)
140-
install -m 755 $(SWIGSO) $(DESTDIR)$(PYSITEDIR)/_semanage$(PYCEXT)
141-
install -m 644 semanage.py $(DESTDIR)$(PYSITEDIR)
139+
test -d $(DESTDIR)$(PYTHONLIBDIR) || install -m 755 -d $(DESTDIR)$(PYTHONLIBDIR)
140+
install -m 755 $(SWIGSO) $(DESTDIR)$(PYTHONLIBDIR)/_semanage$(PYCEXT)
141+
install -m 644 semanage.py $(DESTDIR)$(PYTHONLIBDIR)
142142

143143

144144
install-rubywrap: rubywrap

0 commit comments

Comments
 (0)