archlinux-s390x/patches/pkgbuild/git.sh
Mathieu Benoit d5b8158e55 [ADD] stage 2: the rebuild loop, and git to feed it
The loop applies each hook on the HOST -- /build is the same directory from
both sides, so makepkg in the chroot reads the patched PKGBUILD and nothing is
duplicated inside. It drops --nocheck: stage 1 skipped the test suites because
they ran against the host's libraries, and here they test what was built.
Each rebuilt package is installed into the chroot before the next one, with
the host's pacman and --root, because the chroot's own pacman will not start
until stage 2 has rebuilt it.

Two hooks must NOT run there, and both for the same satisfying reason: the
condition they work around does not exist in the chroot. libgcrypt.sh points
at a host prefix holding our libgpg-error, which the chroot has installed
properly. git.sh drops ZLIB_NG=1 because Ubuntu ships no zlib-ng headers,
while our own zlib-ng package ships them.

git is here because STAGE 2 needs it, not the repository: 51 of the 159
PKGBUILDs take their sources from git+https, and makepkg validates that clone
even under --noextract. Nothing depends on git. Its three -- perl-error,
perl-mailtools with perl-timedate, zlib-ng -- were read from the depends array
rather than from my own tool, which had reported `zsh` as a dependency of git.
It is not; the tool's regex was catching a neighbouring array.

--- FR ---

La boucle applique chaque crochet sur l'HÔTE — /build est le même répertoire
des deux côtés, donc makepkg dans le chroot lit le PKGBUILD corrigé et rien
n'est dupliqué dedans. Elle abandonne --nocheck : l'étage 1 sautait les suites
de tests parce qu'elles s'exécutaient contre les bibliothèques de l'hôte ; ici
elles éprouvent ce qui a été bâti. Chaque paquet reconstruit est installé dans
le chroot avant le suivant, avec le pacman de l'hôte et --root, celui du
chroot ne démarrant pas avant que l'étage 2 ne l'ait reconstruit.

Deux crochets ne doivent PAS y tourner, et pour la même raison satisfaisante :
la condition qu'ils contournent n'existe pas dans le chroot. libgcrypt.sh
pointe sur un préfixe hôte contenant notre libgpg-error, que le chroot a
installé correctement. git.sh retire ZLIB_NG=1 parce qu'Ubuntu ne livre pas
les en-têtes zlib-ng, alors que notre propre paquet zlib-ng les livre.

git est là parce que l'ÉTAGE 2 en a besoin, pas le dépôt : 51 des 159
PKGBUILD prennent leurs sources en git+https, et makepkg valide ce clone même
sous --noextract. Rien ne dépend de git. Ses trois dépendances — perl-error,
perl-mailtools avec perl-timedate, zlib-ng — ont été lues dans le tableau
depends plutôt que dans mon propre outil, qui annonçait `zsh` comme dépendance
de git. Elle ne l'est pas : la regex de l'outil attrapait un tableau voisin.

Assisted-by: Claude Opus 5
2026-08-19 08:56:41 -04:00

47 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# git: ZLIB_NG=1, and Ubuntu ships no zlib-ng headers.
#
# compat/zlib-compat.h:5:11: fatal error: zlib-ng.h: No such file or directory
#
# Arch's git links zlib-ng rather than zlib. There is no zlib-ng development
# package on Ubuntu at all -- libz-ng-dev, zlib-ng-dev and libzlib-ng-dev all
# have no candidate -- so the header cannot be had from the host.
#
# THIS HOOK IS STAGE-1 ONLY, and that is the interesting part. Our own zlib-ng
# package DOES ship usr/include/zlib-ng.h, so inside the stage-2 chroot the
# header is present and ZLIB_NG=1 is correct. The hook exists purely because
# stage 1 builds against the host. It is listed in build-stage2.sh's
# STAGE2_SKIP_HOOKS beside libgcrypt.sh, for the same reason: the condition it
# works around does not exist there.
#
# The declaration goes with the flag. git declares zlib-ng in depends, and a
# git built against plain zlib does not use it -- the seventh instance in this
# port of a package asking for something it never linked. `zlib` replaces it,
# which is what the binary will actually need.
#
# WITH_RUST=1 is left alone. rustc and cargo happen to be on this host, so it
# builds -- but the chroot has neither, so stage 2 will stop here and the
# choice will have to be made then: build Rust, or drop the flag. Recorded now
# rather than discovered twice.
set -euo pipefail
python3 - <<'PY'
import io
s = io.open("PKGBUILD", encoding="utf-8").read()
old = " ZLIB_NG=1\n"
assert s.count(old) == 1, "git: expected exactly one ZLIB_NG=1"
s = s.replace(old, "", 1)
old = "'grep' 'shadow' 'zlib-ng')"
assert s.count(old) == 1, "git: depends tail not in the expected form"
s = s.replace(old, "'grep' 'shadow' 'zlib')", 1)
io.open("PKGBUILD", "w", encoding="utf-8").write(s)
PY
grep -q 'ZLIB_NG' PKGBUILD && {
echo "git: ZLIB_NG survived" >&2; exit 1; }
grep -q "'zlib-ng'" PKGBUILD && {
echo "git: zlib-ng still declared" >&2; exit 1; }
grep -qF "'grep' 'shadow' 'zlib')" PKGBUILD || {
echo "git: zlib not substituted in depends" >&2; exit 1; }
echo "git: plain zlib (no zlib-ng headers on the host); STAGE-1 ONLY"