commit:     f5295c36e37b492652d896c319905f8b359dcc87
Author:     James Le Cuirot <chewi <AT> gentoo <DOT> org>
AuthorDate: Wed Sep 13 19:42:17 2023 +0000
Commit:     James Le Cuirot <chewi <AT> gentoo <DOT> org>
CommitDate: Wed Sep 13 19:43:02 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f5295c36

dev-lang/python: Don't lose *FLAGS when cross-compiling

We have to rename the *FLAGS variables before building, but we build twice when
cross-compiling, so the values get lost the second time around. Work around this
by moving the CBUILD Python build into a separate shell function. This makes the
ebuild tidier anyway.

Signed-off-by: James Le Cuirot <chewi <AT> gentoo.org>

 dev-lang/python/python-3.10.13.ebuild          | 125 ++++++++++++------------
 dev-lang/python/python-3.11.5.ebuild           | 127 +++++++++++++------------
 dev-lang/python/python-3.12.0_rc2_p1-r1.ebuild | 126 ++++++++++++------------
 3 files changed, 194 insertions(+), 184 deletions(-)

diff --git a/dev-lang/python/python-3.10.13.ebuild 
b/dev-lang/python/python-3.10.13.ebuild
index 67085bcef06b..7c9b6e88f370 100644
--- a/dev-lang/python/python-3.10.13.ebuild
+++ b/dev-lang/python/python-3.10.13.ebuild
@@ -132,6 +132,69 @@ src_prepare() {
        eautoreconf
 }
 
+build_cbuild_python() {
+       # Hack to workaround get_libdir not being able to handle CBUILD, bug 
#794181
+       local cbuild_libdir=$(unset PKG_CONFIG_PATH ; $(tc-getBUILD_PKG_CONFIG) 
--keep-system-libs --libs-only-L libffi)
+
+       # pass system CFLAGS & LDFLAGS as _NODIST, otherwise they'll get
+       # propagated to sysconfig for built extensions
+       #
+       # -fno-lto to avoid bug #700012 (not like it matters for mini-CBUILD 
Python anyway)
+       local -x CFLAGS_NODIST="${BUILD_CFLAGS} -fno-lto"
+       local -x LDFLAGS_NODIST=${BUILD_LDFLAGS}
+       local -x CFLAGS= LDFLAGS=
+       local -x BUILD_CFLAGS="${CFLAGS_NODIST}"
+       local -x BUILD_LDFLAGS=${LDFLAGS_NODIST}
+
+       # We need to build our own Python on CBUILD first, and feed it in.
+       # bug #847910 and bug #864911.
+       local myeconfargs_cbuild=(
+               "${myeconfargs[@]}"
+
+               --prefix="${BROOT}"/usr
+               --libdir="${cbuild_libdir:2}"
+
+               # Avoid needing to load the right libpython.so.
+               --disable-shared
+
+               # As minimal as possible for the mini CBUILD Python
+               # we build just for cross.
+               --without-lto
+               --disable-optimizations
+       )
+
+       mkdir "${WORKDIR}"/${P}-${CBUILD} || die
+       pushd "${WORKDIR}"/${P}-${CBUILD} &> /dev/null || die
+       # We disable _ctypes and _crypt for CBUILD because Python's setup.py 
can't handle locating
+       # libdir correctly for cross.
+       PYTHON_DISABLE_MODULES+=" _ctypes _crypt" \
+               ECONF_SOURCE="${S}" econf_build "${myeconfargs_cbuild[@]}"
+
+       # Avoid as many dependencies as possible for the cross build.
+       cat >> Makefile <<-EOF || die
+               MODULE_NIS=disabled
+               MODULE__DBM=disabled
+               MODULE__GDBM=disabled
+               MODULE__DBM=disabled
+               MODULE__SQLITE3=disabled
+               MODULE__HASHLIB=disabled
+               MODULE__SSL=disabled
+               MODULE__CURSES=disabled
+               MODULE__CURSES_PANEL=disabled
+               MODULE_READLINE=disabled
+               MODULE__TKINTER=disabled
+               MODULE_PYEXPAT=disabled
+               MODULE_ZLIB=disabled
+       EOF
+
+       # Unfortunately, we do have to build this immediately, and
+       # not in src_compile, because CHOST configure for Python
+       # will check the existence of the Python it was pointed to
+       # immediately.
+       PYTHON_DISABLE_MODULES+=" _ctypes _crypt" emake
+       popd &> /dev/null || die
+}
+
 src_configure() {
        # disable automagic bluetooth headers detection
        if ! use bluetooth; then
@@ -243,70 +306,10 @@ src_configure() {
        local -x OPT=
 
        if tc-is-cross-compiler ; then
-               # Hack to workaround get_libdir not being able to handle 
CBUILD, bug #794181
-               local cbuild_libdir=$(unset PKG_CONFIG_PATH ; 
$(tc-getBUILD_PKG_CONFIG) --keep-system-libs --libs-only-L libffi)
-
-               # pass system CFLAGS & LDFLAGS as _NODIST, otherwise they'll get
-               # propagated to sysconfig for built extensions
-               #
-               # -fno-lto to avoid bug #700012 (not like it matters for 
mini-CBUILD Python anyway)
-               local -x CFLAGS_NODIST="${BUILD_CFLAGS} -fno-lto"
-               local -x LDFLAGS_NODIST=${BUILD_LDFLAGS}
-               local -x CFLAGS= LDFLAGS=
-               local -x BUILD_CFLAGS="${CFLAGS_NODIST}"
-               local -x BUILD_LDFLAGS=${LDFLAGS_NODIST}
-
-               # We need to build our own Python on CBUILD first, and feed it 
in.
-               # bug #847910 and bug #864911.
-               local myeconfargs_cbuild=(
-                       "${myeconfargs[@]}"
-
-                       --prefix="${BROOT}"/usr
-                       --libdir="${cbuild_libdir:2}"
-
-                       # Avoid needing to load the right libpython.so.
-                       --disable-shared
-
-                       # As minimal as possible for the mini CBUILD Python
-                       # we build just for cross.
-                       --without-lto
-                       --disable-optimizations
-               )
-
+               build_cbuild_python
                # Point the imminent CHOST build to the Python we just
                # built for CBUILD.
                export PATH="${WORKDIR}/${P}-${CBUILD}:${PATH}"
-
-               mkdir "${WORKDIR}"/${P}-${CBUILD} || die
-               pushd "${WORKDIR}"/${P}-${CBUILD} &> /dev/null || die
-               # We disable _ctypes and _crypt for CBUILD because Python's 
setup.py can't handle locating
-               # libdir correctly for cross.
-               PYTHON_DISABLE_MODULES="${PYTHON_DISABLE_MODULES} _ctypes 
_crypt" \
-                       ECONF_SOURCE="${S}" econf_build 
"${myeconfargs_cbuild[@]}"
-
-               # Avoid as many dependencies as possible for the cross build.
-               cat >> Makefile <<-EOF || die
-                       MODULE_NIS=disabled
-                       MODULE__DBM=disabled
-                       MODULE__GDBM=disabled
-                       MODULE__DBM=disabled
-                       MODULE__SQLITE3=disabled
-                       MODULE__HASHLIB=disabled
-                       MODULE__SSL=disabled
-                       MODULE__CURSES=disabled
-                       MODULE__CURSES_PANEL=disabled
-                       MODULE_READLINE=disabled
-                       MODULE__TKINTER=disabled
-                       MODULE_PYEXPAT=disabled
-                       MODULE_ZLIB=disabled
-               EOF
-
-               # Unfortunately, we do have to build this immediately, and
-               # not in src_compile, because CHOST configure for Python
-               # will check the existence of the Python it was pointed to
-               # immediately.
-               PYTHON_DISABLE_MODULES="${PYTHON_DISABLE_MODULES} _ctypes 
_crypt" emake
-               popd &> /dev/null || die
        fi
 
        # pass system CFLAGS & LDFLAGS as _NODIST, otherwise they'll get

diff --git a/dev-lang/python/python-3.11.5.ebuild 
b/dev-lang/python/python-3.11.5.ebuild
index df3980352b02..1740b9d96079 100644
--- a/dev-lang/python/python-3.11.5.ebuild
+++ b/dev-lang/python/python-3.11.5.ebuild
@@ -137,6 +137,70 @@ src_prepare() {
        eautoreconf
 }
 
+build_cbuild_python() {
+       # Hack to workaround get_libdir not being able to handle CBUILD, bug 
#794181
+       local cbuild_libdir=$(unset PKG_CONFIG_PATH ; $(tc-getBUILD_PKG_CONFIG) 
--keep-system-libs --libs-only-L libffi)
+
+       # pass system CFLAGS & LDFLAGS as _NODIST, otherwise they'll get
+       # propagated to sysconfig for built extensions
+       #
+       # -fno-lto to avoid bug #700012 (not like it matters for mini-CBUILD 
Python anyway)
+       local -x CFLAGS_NODIST="${BUILD_CFLAGS} -fno-lto"
+       local -x LDFLAGS_NODIST=${BUILD_LDFLAGS}
+       local -x CFLAGS= LDFLAGS=
+       local -x BUILD_CFLAGS="${CFLAGS_NODIST}"
+       local -x BUILD_LDFLAGS=${LDFLAGS_NODIST}
+
+       # We need to build our own Python on CBUILD first, and feed it in.
+       # bug #847910
+       local myeconfargs_cbuild=(
+               "${myeconfargs[@]}"
+
+               --prefix="${BROOT}"/usr
+               --libdir="${cbuild_libdir:2}"
+
+               # Avoid needing to load the right libpython.so.
+               --disable-shared
+
+               # As minimal as possible for the mini CBUILD Python
+               # we build just for cross to satisfy --with-build-python.
+               --without-lto
+               --without-readline
+               --disable-optimizations
+       )
+
+       mkdir "${WORKDIR}"/${P}-${CBUILD} || die
+       pushd "${WORKDIR}"/${P}-${CBUILD} &> /dev/null || die
+       # We disable _ctypes and _crypt for CBUILD because Python's setup.py 
can't handle locating
+       # libdir correctly for cross.
+       PYTHON_DISABLE_MODULES+=" _ctypes _crypt" \
+               ECONF_SOURCE="${S}" econf_build "${myeconfargs_cbuild[@]}"
+
+       # Avoid as many dependencies as possible for the cross build.
+       cat >> Makefile <<-EOF || die
+               MODULE_NIS_STATE=disabled
+               MODULE__DBM_STATE=disabled
+               MODULE__GDBM_STATE=disabled
+               MODULE__DBM_STATE=disabled
+               MODULE__SQLITE3_STATE=disabled
+               MODULE__HASHLIB_STATE=disabled
+               MODULE__SSL_STATE=disabled
+               MODULE__CURSES_STATE=disabled
+               MODULE__CURSES_PANEL_STATE=disabled
+               MODULE_READLINE_STATE=disabled
+               MODULE__TKINTER_STATE=disabled
+               MODULE_PYEXPAT_STATE=disabled
+               MODULE_ZLIB_STATE=disabled
+       EOF
+
+       # Unfortunately, we do have to build this immediately, and
+       # not in src_compile, because CHOST configure for Python
+       # will check the existence of the --with-build-python value
+       # immediately.
+       PYTHON_DISABLE_MODULES+=" _ctypes _crypt" emake
+       popd &> /dev/null || die
+}
+
 src_configure() {
        local disable
        # disable automagic bluetooth headers detection
@@ -232,73 +296,12 @@ src_configure() {
        local -x OPT=
 
        if tc-is-cross-compiler ; then
-               # Hack to workaround get_libdir not being able to handle 
CBUILD, bug #794181
-               local cbuild_libdir=$(unset PKG_CONFIG_PATH ; 
$(tc-getBUILD_PKG_CONFIG) --keep-system-libs --libs-only-L libffi)
-
-               # pass system CFLAGS & LDFLAGS as _NODIST, otherwise they'll get
-               # propagated to sysconfig for built extensions
-               #
-               # -fno-lto to avoid bug #700012 (not like it matters for 
mini-CBUILD Python anyway)
-               local -x CFLAGS_NODIST="${BUILD_CFLAGS} -fno-lto"
-               local -x LDFLAGS_NODIST=${BUILD_LDFLAGS}
-               local -x CFLAGS= LDFLAGS=
-               local -x BUILD_CFLAGS="${CFLAGS_NODIST}"
-               local -x BUILD_LDFLAGS=${LDFLAGS_NODIST}
-
-               # We need to build our own Python on CBUILD first, and feed it 
in.
-               # bug #847910
-               local myeconfargs_cbuild=(
-                       "${myeconfargs[@]}"
-
-                       --prefix="${BROOT}"/usr
-                       --libdir="${cbuild_libdir:2}"
-
-                       # Avoid needing to load the right libpython.so.
-                       --disable-shared
-
-                       # As minimal as possible for the mini CBUILD Python
-                       # we build just for cross to satisfy 
--with-build-python.
-                       --without-lto
-                       --without-readline
-                       --disable-optimizations
-               )
-
+               build_cbuild_python
                myeconfargs+=(
                        # Point the imminent CHOST build to the Python we just
                        # built for CBUILD.
                        --with-build-python="${WORKDIR}"/${P}-${CBUILD}/python
                )
-
-               mkdir "${WORKDIR}"/${P}-${CBUILD} || die
-               pushd "${WORKDIR}"/${P}-${CBUILD} &> /dev/null || die
-               # We disable _ctypes and _crypt for CBUILD because Python's 
setup.py can't handle locating
-               # libdir correctly for cross.
-               PYTHON_DISABLE_MODULES="${PYTHON_DISABLE_MODULES} _ctypes 
_crypt" \
-                       ECONF_SOURCE="${S}" econf_build 
"${myeconfargs_cbuild[@]}"
-
-               # Avoid as many dependencies as possible for the cross build.
-               cat >> Makefile <<-EOF || die
-                       MODULE_NIS_STATE=disabled
-                       MODULE__DBM_STATE=disabled
-                       MODULE__GDBM_STATE=disabled
-                       MODULE__DBM_STATE=disabled
-                       MODULE__SQLITE3_STATE=disabled
-                       MODULE__HASHLIB_STATE=disabled
-                       MODULE__SSL_STATE=disabled
-                       MODULE__CURSES_STATE=disabled
-                       MODULE__CURSES_PANEL_STATE=disabled
-                       MODULE_READLINE_STATE=disabled
-                       MODULE__TKINTER_STATE=disabled
-                       MODULE_PYEXPAT_STATE=disabled
-                       MODULE_ZLIB_STATE=disabled
-               EOF
-
-               # Unfortunately, we do have to build this immediately, and
-               # not in src_compile, because CHOST configure for Python
-               # will check the existence of the --with-build-python value
-               # immediately.
-               PYTHON_DISABLE_MODULES="${PYTHON_DISABLE_MODULES} _ctypes 
_crypt" emake
-               popd &> /dev/null || die
        fi
 
        # pass system CFLAGS & LDFLAGS as _NODIST, otherwise they'll get

diff --git a/dev-lang/python/python-3.12.0_rc2_p1-r1.ebuild 
b/dev-lang/python/python-3.12.0_rc2_p1-r1.ebuild
index 07d09f165320..1a53a9eb0e9f 100644
--- a/dev-lang/python/python-3.12.0_rc2_p1-r1.ebuild
+++ b/dev-lang/python/python-3.12.0_rc2_p1-r1.ebuild
@@ -137,6 +137,70 @@ src_prepare() {
        eautoreconf
 }
 
+build_cbuild_python() {
+       # Hack to workaround get_libdir not being able to handle CBUILD, bug 
#794181
+       local cbuild_libdir=$(unset PKG_CONFIG_PATH ; $(tc-getBUILD_PKG_CONFIG) 
--keep-system-libs --libs-only-L libffi)
+
+       # pass system CFLAGS & LDFLAGS as _NODIST, otherwise they'll get
+       # propagated to sysconfig for built extensions
+       #
+       # -fno-lto to avoid bug #700012 (not like it matters for mini-CBUILD 
Python anyway)
+       local -x CFLAGS_NODIST="${BUILD_CFLAGS} -fno-lto"
+       local -x LDFLAGS_NODIST=${BUILD_LDFLAGS}
+       local -x CFLAGS= LDFLAGS=
+       local -x BUILD_CFLAGS="${CFLAGS_NODIST}"
+       local -x BUILD_LDFLAGS=${LDFLAGS_NODIST}
+
+       # We need to build our own Python on CBUILD first, and feed it in.
+       # bug #847910
+       local myeconfargs_cbuild=(
+               "${myeconfargs[@]}"
+
+               --prefix="${BROOT}"/usr
+               --libdir="${cbuild_libdir:2}"
+
+               # Avoid needing to load the right libpython.so.
+               --disable-shared
+
+               # As minimal as possible for the mini CBUILD Python
+               # we build just for cross to satisfy --with-build-python.
+               --without-lto
+               --without-readline
+               --disable-optimizations
+       )
+
+       mkdir "${WORKDIR}"/${P}-${CBUILD} || die
+       pushd "${WORKDIR}"/${P}-${CBUILD} &> /dev/null || die
+
+       # Avoid as many dependencies as possible for the cross build.
+       mkdir Modules || die
+       cat > Modules/Setup.local <<-EOF || die
+               *disabled*
+               nis
+               _dbm _gdbm
+               _sqlite3
+               _hashlib _ssl
+               _curses _curses_panel
+               readline
+               _tkinter
+               pyexpat
+               zlib
+               # We disabled these for CBUILD because Python's setup.py can't 
handle locating
+               # libdir correctly for cross. This should be rechecked for the 
pure Makefile approach,
+               # and uncommented if needed.
+               #_ctypes _crypt
+       EOF
+
+       ECONF_SOURCE="${S}" econf_build "${myeconfargs_cbuild[@]}"
+
+       # Unfortunately, we do have to build this immediately, and
+       # not in src_compile, because CHOST configure for Python
+       # will check the existence of the --with-build-python value
+       # immediately.
+       emake
+       popd &> /dev/null || die
+}
+
 src_configure() {
        local disable
        # disable automagic bluetooth headers detection
@@ -243,72 +307,12 @@ src_configure() {
        local -x OPT=
 
        if tc-is-cross-compiler ; then
-               # Hack to workaround get_libdir not being able to handle 
CBUILD, bug #794181
-               local cbuild_libdir=$(unset PKG_CONFIG_PATH ; 
$(tc-getBUILD_PKG_CONFIG) --keep-system-libs --libs-only-L libffi)
-
-               # pass system CFLAGS & LDFLAGS as _NODIST, otherwise they'll get
-               # propagated to sysconfig for built extensions
-               #
-               # -fno-lto to avoid bug #700012 (not like it matters for 
mini-CBUILD Python anyway)
-               local -x CFLAGS_NODIST="${BUILD_CFLAGS} -fno-lto"
-               local -x LDFLAGS_NODIST=${BUILD_LDFLAGS}
-               local -x CFLAGS= LDFLAGS=
-               local -x BUILD_CFLAGS="${CFLAGS_NODIST}"
-               local -x BUILD_LDFLAGS=${LDFLAGS_NODIST}
-
-               # We need to build our own Python on CBUILD first, and feed it 
in.
-               # bug #847910
-               local myeconfargs_cbuild=(
-                       "${myeconfargs[@]}"
-
-                       --libdir="${cbuild_libdir:2}"
-
-                       # Avoid needing to load the right libpython.so.
-                       --disable-shared
-
-                       # As minimal as possible for the mini CBUILD Python
-                       # we build just for cross to satisfy 
--with-build-python.
-                       --without-lto
-                       --without-readline
-                       --disable-optimizations
-               )
-
+               build_cbuild_python
                myeconfargs+=(
                        # Point the imminent CHOST build to the Python we just
                        # built for CBUILD.
                        --with-build-python="${WORKDIR}"/${P}-${CBUILD}/python
                )
-
-               mkdir "${WORKDIR}"/${P}-${CBUILD} || die
-               pushd "${WORKDIR}"/${P}-${CBUILD} &> /dev/null || die
-
-               # Avoid as many dependencies as possible for the cross build.
-               mkdir Modules || die
-               cat > Modules/Setup.local <<-EOF || die
-                       *disabled*
-                       nis
-                       _dbm _gdbm
-                       _sqlite3
-                       _hashlib _ssl
-                       _curses _curses_panel
-                       readline
-                       _tkinter
-                       pyexpat
-                       zlib
-                       # We disabled these for CBUILD because Python's 
setup.py can't handle locating
-                       # libdir correctly for cross. This should be rechecked 
for the pure Makefile approach,
-                       # and uncommented if needed.
-                       #_ctypes _crypt
-               EOF
-
-               ECONF_SOURCE="${S}" econf_build "${myeconfargs_cbuild[@]}"
-
-               # Unfortunately, we do have to build this immediately, and
-               # not in src_compile, because CHOST configure for Python
-               # will check the existence of the --with-build-python value
-               # immediately.
-               emake
-               popd &> /dev/null || die
        fi
 
        # pass system CFLAGS & LDFLAGS as _NODIST, otherwise they'll get

Reply via email to