dev-lang/python-oem: Apply Flatcar modifications

I changed the way we modify the ebuild by keeping the modifications as
minimal as possible, leaving disabling whatever that can be disabled
to the USE flags.
This commit is contained in:
Krzesimir Nowak 2023-02-02 17:01:38 +01:00
parent 981ed883d8
commit f0833eeb45
2 changed files with 111 additions and 93 deletions

View File

@ -0,0 +1,45 @@
Modifications made:
- Keep using internal expat and libffi, thus dropping dev-libs/libffi
and dev-libs/expat from the dependencies.
- Drop dev-python/gentoo-common dependency, it provides the
EXTERNALLY-MANAGED file, but we will provide our own.
- Since this package is installed only for OEM partition as a binary
package, and the installation there happens after the packages
database is removed, we unset the RDEPEND variable. The RDEPEND
variable needs to be empty as it's also used during the binary
package installation. The contents of RDEPEND are already inside the
DEPEND variable, so we are safe.
- We modify the configure flags:
- Add `--prefix=/usr/share/oem/python` as `/usr/share/oem` is where
the OEM partition is mounted.
- Add `--with-platlibdir="$(get_libdir)"`, this is to make sure that
consistent library directory gets picked. In our case for both
amd64 and arm64, it's lib64.
- Change `--enable-shared` to `--disable-shared`. This will skip
building dynamic libraries, as we don't need them.
- Add `--includedir=/discard/include` and change `--mandir` and
`--infodir` to also use `/discard` to install files there. Makes
it easy to remove the unnecessary files.
- We disable loadable sqlite extensions.
- As we want to use the internal versions of expat and libffi, we
change `--with-system-{expat,ffi}` to
`--without-system-{expat,ffi}`.
- Comment out the `--with-wheel-pkg-dir` as it's some ensurepip
stuff we are disabling anyway.
- Essentially drop `src_install` and write our own variant, where we
run `make altinstall`, remove unnecessary files (the original
`src_install` could be read to find out which files to remove),
creates a versionless python symlink, adds an EXTERNALLY-MANAGED
file, and removes the `/discard` directory.

View File

@ -40,11 +40,13 @@ RESTRICT="!test? ( test )"
# run the bootstrap code on your dev box and include the results in the
# patchset. See bug 447752.
# Flatcar: Drop a dependency on dev-libs/expat, we will use the internal one.
# Flatcar: Drop a dependency on dev-libs/libffi, we will use the internal one.
# Flatcar: Drop a dependency on dev-python/gentoo-common, we will install our own EXTERNALLY-MANAGED file
RDEPEND="
app-arch/bzip2:=
app-arch/xz-utils:=
dev-lang/python-exec[python_targets_python3_10(-)]
dev-libs/libffi:=
dev-python/gentoo-common
sys-apps/util-linux:=
>=sys-libs/zlib-1.1.3:=
@ -65,7 +67,6 @@ RDEPEND="
dev-tcltk/blt:=
dev-tcltk/tix
)
xml? ( >=dev-libs/expat-2.1:= )
!!<sys-apps/sandbox-2.21
"
# bluetooth requires headers from bluez
@ -86,6 +87,11 @@ RDEPEND+="
!build? ( app-misc/mime-types )
"
# Flatcar: Unset RDEPEND, DEPEND already contains it. OEM packages are
# installed after production images are pruned of the previously
# installed package database.
unset RDEPEND
VERIFY_SIG_OPENPGP_KEY_PATH=${BROOT}/usr/share/openpgp-keys/python.org.asc
# large file tests involve a 2.5G file being copied (duplicated)
@ -111,9 +117,11 @@ src_unpack() {
}
src_prepare() {
# Ensure that internal copies of expat and libffi are not used.
rm -r Modules/expat || die
rm -r Modules/_ctypes/libffi* || die
# Flatcar: We keep the internal expat copy.
# Flatcar: We keep the internal libffi copy.
# # Ensure that internal copies of expat and libffi are not used.
# rm -r Modules/expat || die
# rm -r Modules/_ctypes/libffi* || die
local PATCHES=(
"${WORKDIR}/${PATCHSET}"
@ -209,19 +217,37 @@ src_configure() {
# a chance for users rebuilding python before glibc
ac_cv_header_stropts_h=no
--enable-shared
# Flatcar: Use oem-specific prefix.
--prefix=/usr/share/oem/python
# Flatcar: Make sure we put libs into a correct subdirectory.
--with-platlibdir="$(get_libdir)"
# Flatcar: No need for shared libs.
# --enable-shared
--disable-shared
--without-static-libpython
--enable-ipv6
--infodir='${prefix}/share/info'
--mandir='${prefix}/share/man'
# Flatcar: Set includedir to discardable directory
--includedir='/discard/include'
# Flatcar: Set infodir and mandir to discardable directory
# --infodir='/${prefix}/share/info'
# --mandir='/${prefix}/share/man'
--infodir='/discard/info'
--mandir='/discard/man'
--with-computed-gotos
--with-dbmliborder="${dbmliborder}"
--with-libc=
--enable-loadable-sqlite-extensions
# Flatcar: No need for loadable extensions.
# --enable-loadable-sqlite-extensions
--disable-loadable-sqlite-extensions
--without-ensurepip
--with-system-expat
--with-system-ffi
--with-wheel-pkg-dir="${EPREFIX}"/usr/lib/python/ensurepip
# Flatcar: We use internal expat
# --with-system-expat
--without-system-expat
# Flatcar: We use internal ffi
# --with-system-ffi
--without-system-ffi
# Flatcar: It's for ensurepip, which we disable
# --with-wheel-pkg-dir="${EPREFIX}"/usr/lib/python/ensurepip
$(use_with lto)
$(use_enable pgo optimizations)
@ -397,92 +423,39 @@ src_test() {
[[ ${ret} -eq 0 ]] || die "emake test failed"
}
# Flatcar: Rewrite src_install to just run make altinstall, remove
# some installed files (refer to the original src_install to see which
# files to drop), adding symlinks and the EXTERNALLY-MANAGED file, and
# removing the /discard directory.
src_install() {
local libdir=${ED}/usr/lib/python${PYVER}
local prefix=/usr/share/oem/python
local eprefix="${ED}${prefix}"
local libdir="${prefix}/$(get_libdir)"
local elibdir="${eprefix}/$(get_libdir)"
local pythonplatlibdir="${libdir}/python${PYVER}"
local epythonplatlibdir="${elibdir}/python${PYVER}"
local bindir="${prefix}/bin"
local ebindir="${eprefix}/bin"
emake DESTDIR="${D}" altinstall
# Fix collisions between different slots of Python.
rm "${ED}/usr/$(get_libdir)/libpython3.so" || die
rm -r "${epythonplatlibdir}"/ensurepip || die
rm -r "${epythonplatlibdir}/"{sqlite3,test/test_sqlite*} || die
rm -r "${ebindir}/idle${PYVER}" || die
rm -r "${epythonplatlibdir}/"{idlelib,tkinter,test/test_tk*} || die
# Cheap hack to get version with ABIFLAGS
local abiver=$(cd "${ED}/usr/include"; echo python*)
if [[ ${abiver} != python${PYVER} ]]; then
# Replace python3.X with a symlink to python3.Xm
rm "${ED}/usr/bin/python${PYVER}" || die
dosym "${abiver}" "/usr/bin/python${PYVER}"
# Create python3.X-config symlink
dosym "${abiver}-config" "/usr/bin/python${PYVER}-config"
# Create python-3.5m.pc symlink
dosym "python-${PYVER}.pc" "/usr/$(get_libdir)/pkgconfig/${abiver/${PYVER}/-${PYVER}}.pc"
fi
# create a simple versionless 'python' symlink
dosym "python${PYVER}" "${bindir}/python"
dosym "python${PYVER}" "${bindir}/python3"
# python seems to get rebuilt in src_install (bug 569908)
# Work around it for now.
if has_version dev-libs/libffi[pax-kernel]; then
pax-mark E "${ED}/usr/bin/${abiver}"
else
pax-mark m "${ED}/usr/bin/${abiver}"
fi
rm -r "${libdir}"/ensurepip/_bundled || die
if ! use ensurepip; then
rm -r "${libdir}"/ensurepip || die
fi
if ! use sqlite; then
rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die
fi
if ! use tk; then
rm -r "${ED}/usr/bin/idle${PYVER}" || die
rm -r "${libdir}/"{idlelib,tkinter,test/test_tk*} || die
fi
ln -s ../python/EXTERNALLY-MANAGED "${libdir}/EXTERNALLY-MANAGED" || die
dodoc Misc/{ACKS,HISTORY,NEWS}
if use examples; then
docinto examples
find Tools -name __pycache__ -exec rm -fr {} + || die
dodoc -r Tools
fi
insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
local libname=$(
printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' |
emake --no-print-directory -s -f - 2>/dev/null
)
newins Tools/gdb/libpython.py "${libname}"-gdb.py
newconfd "${FILESDIR}/pydoc.conf" pydoc-${PYVER}
newinitd "${FILESDIR}/pydoc.init" pydoc-${PYVER}
sed \
-e "s:@PYDOC_PORT_VARIABLE@:PYDOC${PYVER/./_}_PORT:" \
-e "s:@PYDOC@:pydoc${PYVER}:" \
-i "${ED}/etc/conf.d/pydoc-${PYVER}" \
"${ED}/etc/init.d/pydoc-${PYVER}" || die "sed failed"
# python-exec wrapping support
local pymajor=${PYVER%.*}
local EPYTHON=python${PYVER}
local scriptdir=${D}$(python_get_scriptdir)
mkdir -p "${scriptdir}" || die
# python and pythonX
ln -s "../../../bin/${abiver}" "${scriptdir}/python${pymajor}" || die
ln -s "python${pymajor}" "${scriptdir}/python" || die
# python-config and pythonX-config
# note: we need to create a wrapper rather than symlinking it due
# to some random dirname(argv[0]) magic performed by python-config
cat > "${scriptdir}/python${pymajor}-config" <<-EOF || die
#!/bin/sh
exec "${abiver}-config" "\${@}"
insinto "${pythonplatlibdir}"
# https://peps.python.org/pep-0668/
newins - EXTERNALLY-MANAGED <<-EOF
[externally-managed]
Error=
Please contact Flatcar maintainers if some python package
is necessary for this OEM image.
EOF
chmod +x "${scriptdir}/python${pymajor}-config" || die
ln -s "python${pymajor}-config" "${scriptdir}/python-config" || die
# 2to3, pydoc
ln -s "../../../bin/2to3-${PYVER}" "${scriptdir}/2to3" || die
ln -s "../../../bin/pydoc${PYVER}" "${scriptdir}/pydoc" || die
# idle
if use tk; then
ln -s "../../../bin/idle${PYVER}" "${scriptdir}/idle" || die
fi
rm -r "${ED}/discard" || die
}