archlinux-s390x/patches/pkgbuild/brotli.sh
Mathieu Benoit dcaa55b19a [ADD] host deps: the tools six packages needed and nobody declared
--nodeps means every makedepend must be named here by hand. Seven builds
stopped on one, each naming a different tool: itstool, convert, fig2dev,
asciidoctor, libnsl, python -m build, libbpf, history.

The list was also a lie by omission. libreadline-dev, libncurses-dev,
zlib1g-dev, python3-dev, doxygen, xsltproc, docbook-xsl, elinks and
libcap2-bin were on this VM by hand and never declared. They made the
builds pass here and would fail on a fresh Ubuntu, for reasons that have
nothing to do with s390x.

history.pc is generated rather than copied: our own readline package
ships a correct one, but its libdir names /usr/lib, which on a multiarch
host holds no libhistory. The .pc has to describe THIS host.

Three hooks for what apt cannot buy. systemd asks for an EFI arch s390x
does not have -- and says "python3 is missing modules: elftools", which
sends you to apt for four lines before admitting the real reason.

--- FR ---

--nodeps veut dire que chaque makedepend doit être nommé ici à la main.
Sept compilations se sont arrêtées sur l'une d'elles, chacune désignant
un outil différent : itstool, convert, fig2dev, asciidoctor, libnsl,
python -m build, libbpf, history.

La liste mentait aussi par omission. libreadline-dev, libncurses-dev,
zlib1g-dev, python3-dev, doxygen, xsltproc, docbook-xsl, elinks et
libcap2-bin étaient posés à la main sur cette VM, jamais déclarés. Ils
faisaient passer les compilations ici et auraient échoué sur un Ubuntu
neuf, pour des raisons étrangères à s390x.

history.pc est généré et non copié : notre propre paquet readline en
livre un correct, mais son libdir nomme /usr/lib, qui sur un hôte
multiarch ne contient aucun libhistory. Le .pc doit décrire CET hôte-ci.

Trois crochets pour ce qu'apt n'achète pas. systemd réclame une
architecture EFI que s390x n'a pas — et annonce « python3 is missing
modules: elftools », ce qui envoie chez apt pour quatre lignes avant
d'avouer la vraie raison.

Assisted-by: Claude Opus 5
2026-08-17 01:33:41 -04:00

85 lines
4.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# brotli: two Debian defaults, and both of them ship silently.
#
# Neither produces an error. makepkg exits 0 both times and the repository
# gains a package whose files are in places nothing on the target will look.
# This is the case "an exit code proves nothing, only the artefact proves"
# was written for -- the symptom arrives months later, far from the cause.
set -euo pipefail
# 1. The C library, and the one that actually matters.
#
# brotli's PKGBUILD calls plain `cmake`, not the arch-cmake stand-in, so it
# never sees the -DCMAKE_INSTALL_LIBDIR=lib that stand-in passes. CMake's
# GNUInstallDirs then picks its branch by sniffing the host: no
# /etc/arch-release, /etc/debian_version present, so
#
# CMAKE_INSTALL_LIBDIR = lib/s390x-linux-gnu
#
# Measured on a DESTDIR install of a real build: libbrotlicommon.so.1,
# libbrotlidec.so.1, libbrotlienc.so.1 and their .pc files all under
# /usr/lib/s390x-linux-gnu. brotli is in stage 1 only because the chroot said
# openssl and curl need libbrotli*.so -- and the filesystem package's
# /etc/ld.so.conf reads only ld.so.conf.d, so the target would never find
# them. A no-op in stage 2, where CMake takes the /etc/arch-release branch.
python3 - <<'PY'
import io
s = io.open("PKGBUILD", encoding="utf-8").read()
old = ' -DCMAKE_INSTALL_PREFIX=/usr \\\n'
assert s.count(old) == 1, "expected exactly one cmake configure, found %d" % s.count(old)
s = s.replace(old, old + ' -DCMAKE_INSTALL_LIBDIR=lib \\\n', 1)
io.open("PKGBUILD", "w", encoding="utf-8").write(s)
PY
grep -q 'DCMAKE_INSTALL_LIBDIR=lib' PKGBUILD || {
echo "brotli: libdir not pinned" >&2; exit 1; }
echo "brotli: cmake libdir pinned to lib (host GNUInstallDirs says multiarch)"
# 2. The python wheel, and an honest account of what this buys.
#
# package_python-brotli() runs
#
# python -m installer --destdir="$pkgdir" dist/*.whl
#
# and `installer` asks sysconfig where a wheel belongs. Debian and Ubuntu
# patch sysconfig to prefer the "posix_local" scheme, so the answer here is
# /usr/local/lib/python3.13/dist-packages. Verified by running the real wheel
# through the real installer into a scratch pkgdir.
#
# BE CLEAR ABOUT WHAT THIS FIXES. It does NOT make the module importable on
# Arch. Arch ships python 3.14 and this wheel is cp313 with an ABI-tagged
# _brotli.cpython-313-*.so, so no destination makes a stage-1 wheel work on
# the target; stage 2 is what produces a usable one. What the move buys is
# that an Arch package must not ship files under /usr/local, which Arch
# reserves for the administrator. That is the whole justification, and
# writing a bigger one here would mislead the next reader.
#
# `installer --prefix=/usr` does NOT help: posix_local is literally
# "{base}/local/lib/pythonX.Y/dist-packages", so overriding base with /usr
# still lands in /usr/local. The SCHEME would have to change, and the only
# supported way to change it is to be a different interpreter.
#
# Guarded on the directory, not the host name: under an Arch python the
# directory is absent and the block does nothing. Only purelib moves -- the
# wheel declares py_modules=["brotli"] plus the extension, no scripts and no
# data files, so nothing else of it ever leaves /usr/local.
python3 - <<'PY'
import io
s = io.open("PKGBUILD", encoding="utf-8").read()
old = ' python -m installer --destdir="$pkgdir" dist/*.whl\n'
assert old in s, "installer invocation not found"
new = old + """ # Ubuntu's python installs to /usr/local/lib/pythonX.Y/dist-packages
# (sysconfig's posix_local scheme). An Arch package may not ship /usr/local.
local _pyver=$(python -c 'import sys; print("%d.%d" % sys.version_info[:2])')
if [ -d "$pkgdir/usr/local/lib/python$_pyver/dist-packages" ]; then
install -dm 755 "$pkgdir/usr/lib/python$_pyver"
mv "$pkgdir/usr/local/lib/python$_pyver/dist-packages" \\
"$pkgdir/usr/lib/python$_pyver/site-packages"
rm -rf "$pkgdir/usr/local"
fi
"""
s = s.replace(old, new, 1)
io.open("PKGBUILD", "w", encoding="utf-8").write(s)
PY
grep -q "posix_local scheme" PKGBUILD || {
echo "brotli: wheel relocation not inserted" >&2; exit 1; }
echo "brotli: python wheel moved out of /usr/local"