New issue
Advanced search Search tips

Issue 877680 link

Starred by 1 user

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Chrome
Pri: 3
Type: Bug

Blocking:
issue 876634



Sign in to add a comment

python: improve cross-compiling logic

Project Member Reported by vapier@chromium.org, Aug 24

Issue description

python's cross-compiling logic is a bit flaky atm wrt multilib.
https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/51f0d52dc79d584314c43800e022d0826f1bedfb/dev-lang/python/files/python-2.7.10-cross-distutils.patch

the way it works currently is that it checks to see if the dir exists in the sysroot and if it does, just blindly uses it.  it hardcodes the full list of paths and has a preference of using non "lib" dirs by default.

that means if any package happens to create "lib64" with the right python files, we'll blindly use that even if the target's python is configured to use something else.

this isn't trivial to untangle because `python` is the sdk's executable and has to figure out whether to use the sdk settings or the board's settings.   issue 876634 #c37 has a few more details.
 
Blocking: 876634
Project Member

Comment 2 by bugdroid1@chromium.org, Aug 27

The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/74fb2fe8589b896a32a2a5c60dc9c0604b55827c

commit 74fb2fe8589b896a32a2a5c60dc9c0604b55827c
Author: Mike Frysinger <vapier@chromium.org>
Date: Mon Aug 27 18:08:45 2018

python: make libdir lookup a bit more robust

Currently the distutils libdir lookup just pokes directories on disk
and tries to find the first match.  This works as long as all the ABI
paths are created correctly, but it all falls down if one package uses
the wrong path once (as subsequent builds will keep using that broken
path).

Lets improve this by first adding a lookup of standard Gentoo env vars
$ABI and $LIBDIR_$ABI.  If those two are set, we'll use whatever they
say we should (just like Gentoo does).  If they aren't, we'll fall back
to the existing fragile logic today.

BUG=chromium:877680
TEST=precq passes

Change-Id: Ifdb181c03a21c46e1c88440404d2ba967aec2b54
Reviewed-on: https://chromium-review.googlesource.com/1189003
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Jason Clinton <jclinton@chromium.org>

[modify] https://crrev.com/74fb2fe8589b896a32a2a5c60dc9c0604b55827c/dev-lang/python/files/python-3.4.7-cross-distutils.patch
[rename] https://crrev.com/74fb2fe8589b896a32a2a5c60dc9c0604b55827c/dev-lang/python/python-2.7.10-r4.ebuild
[modify] https://crrev.com/74fb2fe8589b896a32a2a5c60dc9c0604b55827c/dev-lang/python/files/python-2.7.10-cross-distutils.patch
[rename] https://crrev.com/74fb2fe8589b896a32a2a5c60dc9c0604b55827c/dev-lang/python/python-3.4.7-r2.ebuild

Labels: -Pri-2 Pri-3
so current python will respect $ABI and $LIBDIR_$ABI if it's set in the env (which it should for more Gentoo builds).  but it still falls back to the old fragile dir search when those env vars aren't set.

the other part of our patch to distutils.sysconfig works by loading the target's _sysconfigdata.py module and using the variables written to that during build (which is great).  unfortunately, that code is based on the hack to locate the python libdir in the first place.

maybe instead of probing for the /usr/lib/python2.7 dir, we probe for _sysconfigdata.py underneath it, and then we'd load that file and extract the LIBDIR setting from that.  the only downside is that this would break if we had a multilib python install whereby we'd have /usr/lib/python2.7 and /usr/lib64/python2.7 even though we'd only have a single /usr/bin/python.  the use case would be for applications that link against/embed python rather than rely on executing `python`.  for the Gentoo build, i don't think we have a choice other than implementing the same $LIBDIR_$ABI logic.

so to summarize:
- distutils.sysconfig.get_python_lib() continues looking at $LIBDIR_$ABI
  - this should work for multilib Gentoo ebuilds
- for the fallback, we change it to look for _sysconfig.py instead of just a dir
- it then loads _sysconfig.py using imp and reads the LIBDIR setting in that module
  - this should work for code executing `python`

since our frontline is still $LIBDIR_$ABI, going to lower the priority as that's what we have now.  and Gentoo isn't super active afaik when it comes to multilib python packages, and even if it were, CrOS isn't using multilib at all today.

Sign in to add a comment