archlinux-s390x/patches/pkgbuild/git.sh
Mathieu Benoit cb3a32101a [FIX] a hook's scope belongs to its sections, not to its filename
git and meson kept failing in stage 2 on exactly what their own hooks fix, while
the log said

  hook skipped (stage-1 only)

Both were named in STAGE2_SKIP_HOOKS, correctly, when their whole content was a
host workaround: git dropped ZLIB_NG because the host had no zlib-ng headers,
meson moved a wheel out of /usr/local. Then each grew a second section that BOTH
stages need -- git's asciidoc man pages, meson's hotdoc reference manual -- and
the list skips the whole FILE, so the new sections never ran. Two hooks that were
by then two thirds relevant, silently ignored.

A list of filenames cannot say why a hook is listed, and cannot notice when that
reason stops covering the file. The hooks now read EL_STAGE and decide per
section, with the reason written beside each guard; the list is gone. libgcrypt
and libarchive keep a whole-file guard, which now states its reason instead of
being an entry somewhere else.

Verified at both stages: git drops its man pages in each, and keeps ZLIB_NG in
the chroot where zlib-ng exists.

--- FR ---

git et meson échouaient à l'étage 2 sur précisément ce que leurs propres hooks
corrigent, pendant que le journal disait

  hook skipped (stage-1 only)

Tous deux étaient nommés dans STAGE2_SKIP_HOOKS, à juste titre quand tout leur
contenu était un contournement de l'hôte : git abandonnait ZLIB_NG faute
d'en-têtes zlib-ng, meson déplaçait une roue hors de /usr/local. Puis chacun a
gagné une seconde section utile aux DEUX étages — les pages asciidoc de git, le
manuel hotdoc de meson — et la liste saute le FICHIER entier : ces sections n'ont
jamais tourné. Deux hooks devenus pertinents aux deux tiers, ignorés en silence.

Une liste de noms de fichiers ne peut pas dire pourquoi un hook y figure, ni
remarquer que cette raison a cessé de couvrir le fichier. Les hooks lisent
désormais EL_STAGE et tranchent par section, la raison écrite à côté de chaque
garde ; la liste disparaît. libgcrypt et libarchive gardent une garde de fichier
entier, qui énonce sa raison au lieu d'être une entrée ailleurs.

Vérifié aux deux étages : git abandonne ses pages de manuel dans les deux, et
conserve ZLIB_NG dans le chroot, où zlib-ng existe.

Assisted-by: Claude Opus 5
2026-08-23 17:23:30 -04:00

92 lines
4 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
# STAGE 1 ONLY -- this section, not this file.
#
# It used to be expressed by naming this hook in STAGE2_SKIP_HOOKS, which skips
# the whole FILE. Then a section was appended that both stages need, and it
# silently never ran: the package kept failing in stage 2 on the very thing the
# new section fixes, and the log said "hook skipped (stage-1 only)" about a hook
# that was now two thirds relevant.
#
# The scope belongs next to the reason, so each section decides for itself.
if [ "${EL_STAGE:-1}" = 1 ]; then
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"
else
echo "git: zlib-ng available in the chroot; keeping Arch's choice"
fi
# --- no man pages -------------------------------------------------------------
#
# asciidoc: command not found
#
# git's man pages come from asciidoc and xmlto, the Python documentation stack
# this port has declined four times now. FOUR PLACES, which is what makes this
# worth a comment: `man` appears as a make target twice and `install-man` twice,
# once each for git proper and once each for contrib/subtree. Removing the build
# targets and leaving the install targets gives
#
# make: *** No rule to make target 'install-man'
#
# which reads like a broken Makefile.
set -euo pipefail
python3 - <<'ZZPY'
import io, re
lines = io.open("PKGBUILD", encoding="utf-8").read().split("\n")
b = [i for i, l in enumerate(lines) if re.search(r"_make .*\ball man\b", l)]
i2 = [i for i, l in enumerate(lines) if re.search(r"\binstall install-man\b", l)]
assert len(b) == 2, "git: expected two `all man` targets, got %d" % len(b)
assert len(i2) == 2, "git: expected two `install install-man` targets, got %d" % len(i2)
for i in b:
lines[i] = re.sub(r"\ball man\b", "all", lines[i])
for i in i2:
lines[i] = re.sub(r"\binstall install-man\b", "install", lines[i])
io.open("PKGBUILD", "w", encoding="utf-8").write("\n".join(lines))
ZZPY
grep -qE "\ball man\b|\binstall-man\b" PKGBUILD && {
echo "git: a man target survived" >&2; exit 1; }
echo "git: man pages dropped (no asciidoc, four places)"