selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] scripts/env_use_destdir: fix Fedora support
@ 2020-05-01  9:29 Nicolas Iooss
  2020-05-01  9:29 ` [PATCH 2/2] scripts/env_use_destdir: propagate PREFIX, LIBDIR, BINDIR, etc Nicolas Iooss
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Iooss @ 2020-05-01  9:29 UTC (permalink / raw)
  To: selinux

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 <module>
        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 <nicolas.iooss@m4x.org>
---
 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"]')"
-- 
2.26.2


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

* [PATCH 2/2] scripts/env_use_destdir: propagate PREFIX, LIBDIR, BINDIR, etc.
  2020-05-01  9:29 [PATCH 1/2] scripts/env_use_destdir: fix Fedora support Nicolas Iooss
@ 2020-05-01  9:29 ` Nicolas Iooss
  2020-05-04 12:31   ` Petr Lautrbach
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Iooss @ 2020-05-01  9:29 UTC (permalink / raw)
  To: selinux

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 <nicolas.iooss@m4x.org>
---
 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
-- 
2.26.2


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

* Re: [PATCH 2/2] scripts/env_use_destdir: propagate PREFIX, LIBDIR, BINDIR, etc.
  2020-05-01  9:29 ` [PATCH 2/2] scripts/env_use_destdir: propagate PREFIX, LIBDIR, BINDIR, etc Nicolas Iooss
@ 2020-05-04 12:31   ` Petr Lautrbach
  2020-05-05 13:19     ` Petr Lautrbach
  0 siblings, 1 reply; 4+ messages in thread
From: Petr Lautrbach @ 2020-05-04 12:31 UTC (permalink / raw)
  To: selinux; +Cc: Nicolas Iooss

[-- Attachment #1: Type: text/plain, Size: 2252 bytes --]

On Fri, May 01, 2020 at 11:29:29AM +0200, Nicolas Iooss wrote:
> 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 <nicolas.iooss@m4x.org>

For both patches:

Acked-by: Petr Lautrbach <plautrba@redhat.com>

> ---
>  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
> -- 
> 2.26.2
> 

-- 
()  ascii ribbon campaign - against html e-mail 
/\  www.asciiribbon.org   - against proprietary attachments

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH 2/2] scripts/env_use_destdir: propagate PREFIX, LIBDIR, BINDIR, etc.
  2020-05-04 12:31   ` Petr Lautrbach
@ 2020-05-05 13:19     ` Petr Lautrbach
  0 siblings, 0 replies; 4+ messages in thread
From: Petr Lautrbach @ 2020-05-05 13:19 UTC (permalink / raw)
  To: selinux; +Cc: Nicolas Iooss

[-- Attachment #1: Type: text/plain, Size: 2574 bytes --]

On Mon, May 04, 2020 at 02:31:52PM +0200, Petr Lautrbach wrote:
> On Fri, May 01, 2020 at 11:29:29AM +0200, Nicolas Iooss wrote:
> > 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 <nicolas.iooss@m4x.org>
> 
> For both patches:
> 
> Acked-by: Petr Lautrbach <plautrba@redhat.com>

Both applied.

> > ---
> >  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
> > -- 
> > 2.26.2
> > 
> 
> -- 
> ()  ascii ribbon campaign - against html e-mail 
> /\  www.asciiribbon.org   - against proprietary attachments



-- 
()  ascii ribbon campaign - against html e-mail 
/\  www.asciiribbon.org   - against proprietary attachments

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2020-05-05 13:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-01  9:29 [PATCH 1/2] scripts/env_use_destdir: fix Fedora support Nicolas Iooss
2020-05-01  9:29 ` [PATCH 2/2] scripts/env_use_destdir: propagate PREFIX, LIBDIR, BINDIR, etc Nicolas Iooss
2020-05-04 12:31   ` Petr Lautrbach
2020-05-05 13:19     ` Petr Lautrbach

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).