From patchwork Fri May 1 09:29:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Iooss X-Patchwork-Id: 11522351 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E829D913 for ; Fri, 1 May 2020 09:29:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D96D22076D for ; Fri, 1 May 2020 09:29:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728352AbgEAJ3l (ORCPT ); Fri, 1 May 2020 05:29:41 -0400 Received: from mx1.polytechnique.org ([129.104.30.34]:48019 "EHLO mx1.polytechnique.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728236AbgEAJ3l (ORCPT ); Fri, 1 May 2020 05:29:41 -0400 Received: from localhost.localdomain (85-168-38-217.rev.numericable.fr [85.168.38.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTPSA id A46DA5649DF for ; Fri, 1 May 2020 11:29:38 +0200 (CEST) From: Nicolas Iooss To: selinux@vger.kernel.org Subject: [PATCH 1/2] scripts/env_use_destdir: fix Fedora support Date: Fri, 1 May 2020 11:29:28 +0200 Message-Id: <20200501092929.1162708-1-nicolas.iooss@m4x.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-AV-Checked: ClamAV using ClamSMTP at svoboda.polytechnique.org (Fri May 1 11:29:38 2020 +0200 (CEST)) X-Spam-Flag: No, tests=bogofilter, spamicity=0.000000, queueID=DB86D5649E2 X-Org-Mail: nicolas.iooss.2010@polytechnique.org Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org libselinux and libsemanage use: PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; print(get_python_lib(plat_specific=1, prefix='$(PREFIX)'))") while python/semanage and python/sepolgen/src/sepolgen use: PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; print(get_python_lib(prefix='$(PREFIX)'))") This is right: libselinux and libsemanage's Python bindings use native code (thus "plat_specific=1") while the others only install Python files. Nevertheless `scripts/env_use_destdir` only runs the second command when computing `$PYTHONPATH`. When using this script to run `make test` in a minimal Fedora 31 environment, this leads to an error such as: make[2]: Entering directory '/code/python/sepolicy' Traceback (most recent call last): File "test_sepolicy.py", line 117, in import selinux ModuleNotFoundError: No module named 'selinux' Fix this by also adding `get_python_lib(plat_specific=1)` to the computed `$PYTHONPATH`. While at it, preserve `$PYTHONPATH` instead of resetting it. This makes it easier to work with Python virtual environments. Signed-off-by: Nicolas Iooss --- scripts/env_use_destdir | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/env_use_destdir b/scripts/env_use_destdir index 251987c255ce..491da58f9207 100755 --- a/scripts/env_use_destdir +++ b/scripts/env_use_destdir @@ -24,8 +24,14 @@ fi export LD_LIBRARY_PATH="$DESTDIR/usr/lib:$DESTDIR/lib" export PATH="$DESTDIR/usr/sbin:$DESTDIR/usr/bin:$DESTDIR/sbin:$DESTDIR/bin:$PATH" -# shellcheck disable=SC2155 -export PYTHONPATH="$DESTDIR$(${PYTHON:-python3} -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr'))")" +NEW_PYTHONPATH="$DESTDIR$(${PYTHON:-python3} -c "from distutils.sysconfig import *;print(get_python_lib(plat_specific=1, prefix='/usr'))"):$DESTDIR$(${PYTHON:-python3} -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr'))")" +if [ -n "${PYTHONPATH:-}" ] ; then + # Prefix the PYTHONPATH with the new directories + export PYTHONPATH="$NEW_PYTHONPATH:$PYTHONPATH" +else + # Define PYTHONPATH + export PYTHONPATH="$NEW_PYTHONPATH" +fi # shellcheck disable=SC2155 export RUBYLIB="$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorlibdir"]'):$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorarchdir"]')" From patchwork Fri May 1 09:29:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Iooss X-Patchwork-Id: 11522353 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 53C9D15AB for ; Fri, 1 May 2020 09:29:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D19B2173E for ; Fri, 1 May 2020 09:29:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728433AbgEAJ3o (ORCPT ); Fri, 1 May 2020 05:29:44 -0400 Received: from mx1.polytechnique.org ([129.104.30.34]:34561 "EHLO mx1.polytechnique.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728423AbgEAJ3n (ORCPT ); Fri, 1 May 2020 05:29:43 -0400 Received: from localhost.localdomain (85-168-38-217.rev.numericable.fr [85.168.38.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTPSA id 8EB0A5649DF for ; Fri, 1 May 2020 11:29:41 +0200 (CEST) From: Nicolas Iooss To: selinux@vger.kernel.org Subject: [PATCH 2/2] scripts/env_use_destdir: propagate PREFIX, LIBDIR, BINDIR, etc. Date: Fri, 1 May 2020 11:29:29 +0200 Message-Id: <20200501092929.1162708-2-nicolas.iooss@m4x.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200501092929.1162708-1-nicolas.iooss@m4x.org> References: <20200501092929.1162708-1-nicolas.iooss@m4x.org> MIME-Version: 1.0 X-AV-Checked: ClamAV using ClamSMTP at svoboda.polytechnique.org (Fri May 1 11:29:42 2020 +0200 (CEST)) X-Spam-Flag: No, tests=bogofilter, spamicity=0.000000, queueID=F237F5649E2 X-Org-Mail: nicolas.iooss.2010@polytechnique.org Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org On systems using non-default `PREFIX`, `LIBDIR`, `SHLIBDIR`, `BINDIR` or `SBINDIR`, running `DESTDIR=/path/to/destdir ./scripts/env_use_destdir make test` does not perform the intended behavior, because the testing programs and libraries are installed into locations that are not added to `LD_LIBRARY_PATH` nor `PATH`. More precisely, with `LIBDIR=/usr/lib64 SHLIBDIR=/lib64`, `env_use_destdir` does not work. Fix this by adding the installation directories relative to `DESTDIR` in `LD_LIBRARY_PATH` and `PATH`. Signed-off-by: Nicolas Iooss Acked-by: Petr Lautrbach --- scripts/env_use_destdir | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/env_use_destdir b/scripts/env_use_destdir index 491da58f9207..8274013e9cf0 100755 --- a/scripts/env_use_destdir +++ b/scripts/env_use_destdir @@ -22,7 +22,26 @@ if [ -z "${DESTDIR:-}" ] ; then fi export LD_LIBRARY_PATH="$DESTDIR/usr/lib:$DESTDIR/lib" +if [ -n "${PREFIX:-}" ] ; then + LD_LIBRARY_PATH="$DESTDIR$PREFIX/lib:$LD_LIBRARY_PATH" +fi +if [ -n "${LIBDIR:-}" ] ; then + LD_LIBRARY_PATH="$DESTDIR$LIBDIR:$LD_LIBRARY_PATH" +fi +if [ -n "${SHLIBDIR:-}" ] ; then + LD_LIBRARY_PATH="$DESTDIR$SHLIBDIR:$LD_LIBRARY_PATH" +fi + export PATH="$DESTDIR/usr/sbin:$DESTDIR/usr/bin:$DESTDIR/sbin:$DESTDIR/bin:$PATH" +if [ -n "${PREFIX:-}" ] ; then + PATH="$DESTDIR$PREFIX/sbin:$DESTDIR$PREFIX/bin:$LD_LIBRARY_PATH" +fi +if [ -n "${BINDIR:-}" ] ; then + PATH="$DESTDIR$BINDIR:$PATH" +fi +if [ -n "${SBINDIR:-}" ] ; then + PATH="$DESTDIR$SBINDIR:$PATH" +fi NEW_PYTHONPATH="$DESTDIR$(${PYTHON:-python3} -c "from distutils.sysconfig import *;print(get_python_lib(plat_specific=1, prefix='/usr'))"):$DESTDIR$(${PYTHON:-python3} -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr'))")" if [ -n "${PYTHONPATH:-}" ] ; then