Act on the adversarial review: six assertions that could not go red
An adversarial reviewer with a named hunt list asked, of every gate in the change, what edit to the PRODUCT would turn it red. Six could not be made to fail:
pkg-config --variable=pkgdatadirexits 0 and prints an empty line for an UNDEFINED variable, so deleting thepkgdatadir=line it was written to protect left it green -- while foot's get_variable() fails three packages later. Now captures the value, requires it non-empty, and requires the staged directory to exist.pkg-config --modversion fcftprints a version and never compares one, while the comment claimed foot's >=3.3.1 <4.0.0 pin was asserted. Now --atleast-version and --max-version, which do compare.- gperf and samurai asserted nothing at all. gperf is the sharp one: this module argues at length that an ABSENT gperf makes fontconfig conclude FC_GPERF_SIZE_T from a substitution that tested nothing, with configure still exiting 0 -- and then did not check the tool was present. Now
test -xplus actually running it. - Three more were subsumed by the command immediately above them.
The meson launcher -- the most fragile artifact here, on the critical path of five packages -- was never executed by the package that writes it, and structurally could not be: meson declared no build-inputs, so no python3 was on PATH during its own build. It now declares python and ends by running the launcher, checking the version, and asserting zero pycache directories, which turns the -B finding from a comment into a standing check.
The date-macro gate could not distinguish its own stated mechanism. It compiled with a bare $CC -- no response file, therefore no -O2, which is the stated trigger -- and the builder sets SOURCE_DATE_EPOCH=0, which renders as exactly the literal it compares against. So its green was equally consistent with "the toolchain pins these unconditionally" and "clang honoured the builder's epoch". Now compiles with $CC $CFLAGS and recompiles under SOURCE_DATE_EPOCH=1000000000 requiring the output to be unchanged. Both arms pass, so the claim is now warranted rather than merely true.
Also: wayland links an executable and lacked -Dprefer_static, working only because expat.pc happens to have no Requires.private; three cp calls became install -m because busybox cp masks mode by the ambient umask and this builder treats mode as identity-relevant; a comment had a paragraph pasted into the middle of a sentence; trailing whitespace.
And one explanation is withdrawn. The samurai comment claimed the realloc(NULL, 0) behaviour was "a property of the zig-bundled libc rather than of musl generally" -- but zig bundles musl SOURCE and compiles it, so there is no separate implementation for the property to belong to. The measurement stands; the mechanism is now marked open instead of dressed as a finding.
src/core/packages/build-tools.sgl | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
src/core/packages/datastructures.sgl | 7 +++++--
src/core/packages/fonts.sgl | 10 +++++++++-
src/core/packages/python.sgl | 36 ++++++++++++++++++++++++++++++++++--
src/core/packages/wayland.sgl | 47 +++++++++++++++++++++++++++++++++++++++++++++--
5 files changed, 206 insertions(+), 34 deletions(-)src/core/packages/build-tools.sglmodified
(define-library (core packages build-tools) (import (sigil core) (core build-environments) (core packages python) (sigil env package) (sigil build external)) (export byacc file gperf meson samurai) "set -eu\n" "d=\"$(dirname \"$PWD\")/install-root\"\n" "test -x \"$d${out}/bin/yacc\"\n" "cp \"$d${out}/bin/yacc\" \"$d${out}/bin/byacc\"\n" ;; `install -m` rather than `cp`: busybox `cp` masks the ;; source mode by the ambient UMASK, which would ;; make the installed permissions a function of the ;; environment rather than of the derivation. "install -m 755 \"$d${out}/bin/yacc\" \"$d${out}/bin/byacc\"\n" "test -x \"$d${out}/bin/byacc\"\n" "echo BYACC-DUAL-NAME-INSTALLED\n")))))) ;; reads like a missing file. ;; ;; THIS TOOLCHAIN'S LIBC RETURNS NULL FROM realloc(NULL, 0) WHILE RETURNING ;; NON-NULL FROM malloc(0). Upstream musl's realloc begins ;; `if (!p) return malloc(n);` and would return non-null, so this is a ;; property of the zig-bundled libc rather than of musl generally, and ;; anything in this channel calling `realloc(p, 0)` inherits it. Measured ;; through a volatile function pointer, because the optimizer rewrites a ;; visible `realloc(NULL, n)` into `malloc(n)` and hides the real answer. ;; NON-NULL FROM malloc(0). Measured through a volatile function pointer, ;; at -O0 and -O2, with `realloc(NULL, 32)` as a passing positive control -- ;; the indirection is necessary because the optimizer rewrites a VISIBLE ;; `realloc(NULL, n)` into `malloc(n)` and hides the real answer. ;; ;; THE MEASUREMENT IS WHAT THIS PACKAGE RELIES ON; THE EXPLANATION IS NOT ;; SETTLED, and an earlier version of this comment overstated it. It said ;; the behaviour was "a property of the zig-bundled libc rather than of musl ;; generally", on the grounds that upstream musl's realloc opens ;; `if (!p) return malloc(n);`. That reasoning does not hold up: zig ;; bundles musl SOURCE and compiles it, so there is no separate ;; implementation for the property to belong to. Either the musl version ;; here differs from the one that reasoning describes, or the reasoning is ;; simply wrong. Nothing in this channel depends on which -- the patch is ;; defensive and correct under either -- so it is left as an open question ;; rather than dressed up as a finding. ;; ;; What IS established and does matter: anything in this channel calling ;; `realloc(p, 0)` and treating NULL as failure will break the same way. ;; ;; REVISIT ON EVERY VERSION BUMP. Upstream master still has the same line, ;; so the patch is expected to keep applying -- but if it stops, the right path: "patches/samurai-realloc-zero-length.patch" sha256: "f160b3d9265a68b88cbcc5e7b04ec5e65f1ef89289dac14919e3702c80e025b3"))) (external-phase kind: 'make) (external-phase kind: 'install args: (list "PREFIX=${out}"))))) (external-phase kind: 'install args: (list "PREFIX=${out}")) ;; ASSERT THE BINARY. Every other package in this change ;; checks what its consumers will look for; samurai and gperf ;; were the two that did not, and gperf is the sharp one -- ;; see the note there. (external-phase kind: 'run args: (list "sh" "-c" (string-append "set -eu\n" "d=\"$(dirname \"$PWD\")/install-root\"\n" "test -x \"$d${out}/bin/samu\"\n" "echo SAMURAI-INSTALLED\n")))))) ;; gperf, a perfect-hash generator. Nothing in this channel wants one; it ;; is here because fontconfig's configure RUNS it, at configure time: phases: (list (external-phase kind: 'configure args: (list "--prefix=${out}")) (external-phase kind: 'make) (external-phase kind: 'install)))) (external-phase kind: 'install) ;; ASSERT THE BINARY, AND THIS ONE IS LOAD-BEARING RATHER ;; THAN TIDY. The entire argument for packaging gperf is ;; that an ABSENT gperf makes fontconfig's configure.ac:216 ;; probe conclude `FC_GPERF_SIZE_T=size_t` from a command ;; substitution that tested nothing -- with configure still ;; exiting 0. Packaging gperf closes that only if ;; `bin/gperf` actually exists. Without this line, a gperf ;; whose `make install` put the binary somewhere else would ;; ship green and hand fontconfig straight back into the ;; silent-wrong-answer state this package was written to ;; prevent, with every gate downstream still passing. (external-phase kind: 'run args: (list "sh" "-c" (string-append "set -eu\n" "d=\"$(dirname \"$PWD\")/install-root\"\n" "test -x \"$d${out}/bin/gperf\"\n" ;; And prove it RUNS, because the thing ;; fontconfig does is run it. "\"$d${out}/bin/gperf\" --version | head -1\n" "echo GPERF-INSTALLED\n")))))) ;; meson. Pure Python, so there is nothing to compile and the whole ;; package is one `run` phase that copies a tree and writes a launcher. ;; package is one `run` phase that copies a tree, writes a launcher, and ;; then RUNS that launcher. ;; ;; WHY THE LAUNCHER EXECS `python3` FROM PATH RATHER THAN AN ABSOLUTE PATH. ;; The honest way to write this would be `${python}/bin/python3`, but location: "https://github.com/mesonbuild/meson/releases/download/1.8.2/meson-1.8.2.tar.gz" sha256: "c105816d8158c76b72adcb9ff60297719096da7d07f6b1f000fd8c013cd387af") buildenv: core-buildenv ;; PYTHON IS A BUILD INPUT SO THAT THIS PACKAGE CAN RUN ITS OWN ;; LAUNCHER. meson compiles nothing, so strictly it needs no inputs at ;; all -- and that was the earlier definition. The cost was that the ;; single most fragile artifact here, a hand-written shell wrapper on ;; the critical path of five packages, was never executed by the ;; package that produces it: the first thing to run it was the next ;; package's `meson setup`, one build later. Declaring python buys the ;; `--version` call at the end of the phase, which is a real gate. build-inputs: (list python) phases: (list (external-phase kind: 'run "d=\"$(dirname \"$PWD\")/install-root\"\n" "mkdir -p \"$d${out}/lib/meson\" \"$d${out}/bin\"\n" "cp -a mesonbuild \"$d${out}/lib/meson/\"\n" "cp meson.py \"$d${out}/lib/meson/\"\n" ;; THE LAUNCHER LOCATES ITSELF rather than ;; baking `${out}`. `${out}` expands to the ;; SANDBOX view -- /sigil/store/<item> -- which ;; exists inside any build that binds meson and ;; nowhere else. A launcher carrying that path ;; works where meson is actually used and dies ;; under `sigil env shell`, which is a real ;; failure mode this package hit on its first ;; build and which the same shape gives ncurses' ;; `install -m` rather than `cp`: busybox `cp` ;; creates the destination with the source's mode ;; masked by the ambient UMASK, so the installed ;; permissions would be a function of the ;; environment rather than of the derivation. ;; Every autotools `make install` in this channel ;; uses `install -m` for exactly that reason. "install -m 644 meson.py \"$d${out}/lib/meson/meson.py\"\n" ;; THE LAUNCHER LOCATES ITSELF rather than baking ;; `${out}`. `${out}` expands to the SANDBOX ;; view -- /sigil/store/<item> -- which exists ;; inside any build that binds meson and nowhere ;; else. A launcher carrying that path works ;; where meson is actually used and dies under ;; `sigil env shell`, which is a real failure ;; mode this package hit on its first build, and ;; which the same shape gives ncurses' ;; compiled-in terminfo root. Deriving the ;; prefix from `$0` costs one line, works in both ;; places, and leaves no absolute path in the ;; artifact at all. ;; ;; A quoted heredoc delimiter keeps the shell out ;; of `$0` and `$@`; neither uses braces, so ;; sigil's own `${...}` interpolation does not see ;; them either. ;; ;; `-B` IS LOAD-BEARING AND THIS PACKAGE PROVED ;; IT THE EXPENSIVE WAY. Without it, the FIRST ;; `-B` IS LOAD-BEARING AND THIS PACKAGE PROVED IT ;; THE EXPENSIVE WAY. Without it, the FIRST ;; `meson --version` wrote 99 `.pyc` files into ;; `__pycache__` directories INSIDE meson's own ;; store item. The item then failed content ;; stopped from writing beside its own sources at ;; run time. Python is merely the first one here. ;; The failure is also delayed by one invocation, ;; so it does not look like a packaging bug -- ;; the run that breaks the item succeeds. ;; of `$0` and `$@`; neither uses braces, so ;; sigil's own `${...}` interpolation does not ;; see them either. ;; so it does not look like a packaging bug -- the ;; run that breaks the item succeeds. "cat > \"$d${out}/bin/meson\" <<'WRAP'\n" "#!/bin/sh\n" "here=$(CDPATH= cd -- \"$(dirname -- \"$0\")\" && pwd)\n" "WRAP\n" "chmod 755 \"$d${out}/bin/meson\"\n" "test -d \"$d${out}/lib/meson/mesonbuild\"\n" ;; RUN THE LAUNCHER. This is the gate the earlier ;; definition lacked: it exercises the shebang, ;; the `$0`-relative prefix derivation, the `-B` ;; flag, python3 resolving from PATH, and ;; mesonbuild importing -- none of which the ;; preceding `test -d` touches, because that is ;; subsumed by the `cp -a` above it. "v=\"$(\"$d${out}/bin/meson\" --version)\"\n" "echo \"MESON-LAUNCHER-VERSION=[$v]\"\n" "test \"$v\" = \"1.8.2\"\n" ;; And prove `-B` did its job: running the ;; launcher must NOT have written bytecode beside ;; the sources, or the store item corrupts itself ;; on first use. "n=$(find \"$d${out}/lib/meson\" -name '__pycache__' -type d | wc -l)\n" "echo \"MESON-PYCACHE-DIRS=$n\"\n" "test \"$n\" -eq 0\n" "echo MESON-INSTALLED\n"))))))))src/core/packages/datastructures.sglmodified
"set -eu\n" "d=\"$(dirname \"$PWD\")/install-root\"\n" "mkdir -p \"$d${out}/include\" \"$d${out}/lib/pkgconfig\"\n" "cp tllist.h \"$d${out}/include/\"\n" ;; `install -m` rather than `cp`, so the installed mode is a ;; function of the derivation and not of the ;; ambient umask. "install -m 644 tllist.h \"$d${out}/include/tllist.h\"\n" "cat > \"$d${out}/lib/pkgconfig/tllist.pc\" <<'PC'\n" "Name: tllist\n" "Description: A C header file only implementation of a typed linked list\n" "test -f \"$d${out}/include/tllist.h\"\n" "PKG_CONFIG_PATH=\"$d${out}/lib/pkgconfig\" pkg-config --exists tllist\n" "PKG_CONFIG_PATH=\"$d${out}/lib/pkgconfig\" pkg-config --modversion tllist\n" "echo TLLIST-INSTALLED\n")))))))) "echo TLLIST-INSTALLED\n"))))))))src/core/packages/fonts.sglmodified
;; foot pins fcft to >=3.3.1 <4.0.0, so the ;; version pkg-config reports is load-bearing and ;; is asserted rather than assumed. "PKG_CONFIG_PATH=\"$d${out}/lib/pkgconfig\" pkg-config --modversion fcft\n" ;; `--modversion` PRINTS a version; it does not ;; CHECK one, and it exits 0 for any value. foot ;; pins fcft to `>=3.3.1 <4.0.0`, so assert that ;; range with the options that actually compare. ;; Printing it as well keeps the value in the log. "v=$(PKG_CONFIG_PATH=\"$d${out}/lib/pkgconfig\" pkg-config --modversion fcft)\n" "echo \"FCFT-VERSION=[$v]\"\n" "PKG_CONFIG_PATH=\"$d${out}/lib/pkgconfig\" pkg-config --atleast-version=3.3.1 fcft\n" "PKG_CONFIG_PATH=\"$d${out}/lib/pkgconfig\" pkg-config --max-version=3.99.99 fcft\n" "echo FCFT-INSTALLED\n"))))))))src/core/packages/python.sglmodified
"set -eu\n" "echo '#include <stdio.h>' > dtcheck.c\n" "echo 'int main(void){ printf(\"%s|%s\", __DATE__, __TIME__); return 0; }' >> dtcheck.c\n" "$CC -Wno-error=date-time dtcheck.c -o dtcheck\n" ;; ARM 1 -- COMPILED WITH $CFLAGS, which is the ;; whole point. An earlier version of this gate ;; ran a bare `$CC`, so it carried no ;; `@compiler.flags` response file and therefore ;; no `-O2` -- it vouched for a configuration ;; CPython is not built in, while the comment ;; above names `-O2` as the trigger. A gate that ;; compiles under different flags than the code it ;; certifies is asserting its author's ;; expectations rather than the product. "$CC $CFLAGS -Wno-error=date-time dtcheck.c -o dtcheck\n" "v=$(./dtcheck)\n" "echo \"TOOLCHAIN-DATE-MACROS=[$v]\"\n" "test \"$v\" = \"Jan 1 1970|00:00:00\"\n" "rm -f dtcheck dtcheck.c\n" ;; ARM 2 -- THE ARM THAT SEPARATES THE TWO ;; EXPLANATIONS. The builder sets ;; SOURCE_DATE_EPOCH=0, and epoch 0 renders as ;; exactly "Jan 1 1970" / "00:00:00" -- the ;; literal arm 1 compares against. So arm 1 alone ;; is green under BOTH hypotheses: "the toolchain ;; pins these macros unconditionally" (which is ;; what licenses the -Wno-error above) and "clang ;; is honouring the builder's epoch" (which would ;; not license it, because the guarantee would ;; then belong to a variable a future builder ;; could stop setting). ;; ;; Overriding the epoch to a DIFFERENT instant ;; discriminates: if the output moves, the macros ;; track SOURCE_DATE_EPOCH and this package's ;; justification is wrong. "w=$(SOURCE_DATE_EPOCH=1000000000 ./dtcheck)\n" "printf 'DATE-MACROS-UNDER-EPOCH-1000000000=[%s]\\n' \"$w\"\n" "e=$(SOURCE_DATE_EPOCH=1000000000 $CC $CFLAGS -Wno-error=date-time dtcheck.c -o dtcheck2 && ./dtcheck2)\n" "echo \"DATE-MACROS-RECOMPILED-UNDER-EPOCH=[$e]\"\n" "test \"$e\" = \"Jan 1 1970|00:00:00\"\n" "rm -f dtcheck dtcheck2 dtcheck.c\n" "echo DATE-MACRO-PINNING-CONFIRMED\n"))) (external-phase kind: 'configuresrc/core/packages/wayland.sglmodified
" --prefix=${out}" " --buildtype=plain" " --default-library=static" ;; `-Dprefer_static=true` HERE TOO, although ;; nothing needs it TODAY. wayland builds ;; `wayland-scanner`, an executable that links ;; expat, and it links only because `expat.pc` ;; happens to carry no `Requires.private:` -- so ;; the default, non-static pkg-config query is ;; sufficient by coincidence rather than by ;; construction. The moment expat grows one, or ;; the scanner gains a dependency that has one, ;; this package reproduces the `undefined symbol` ;; link failure that fontconfig's ;; `Requires.private: expat` produced in foot. " -Dprefer_static=true" ;; documentation wants doxygen, xmlto and ;; xsltproc; dtd_validation wants libxml2. Both ;; are probes on what happens to be visible, and ;; And prove the variable foot reads back is ;; actually readable, by the tool that will read ;; it. "PKG_CONFIG_PATH=\"$d${out}/lib/pkgconfig\" pkg-config --variable=pkgdatadir wayland-protocols\n" "echo WAYLAND-PROTOCOLS-INSTALLED\n")))))))) ;; A BARE `pkg-config --variable=` CALL IS NOT A ;; GATE. pkg-config exits 0 and prints an empty ;; line when the requested variable is UNDEFINED, ;; so deleting the `pkgdatadir=` line from the ;; heredoc above would leave this green -- and ;; foot's `get_variable('pkgdatadir')` would then ;; fail three packages later, inside ;; wayland-scanner, which is exactly the distance ;; these assertions exist to close. Require the ;; value to be non-empty AND to name a real ;; directory. "v=$(PKG_CONFIG_PATH=\"$d${out}/lib/pkgconfig\" pkg-config --variable=pkgdatadir wayland-protocols)\n" "echo \"WAYLAND-PROTOCOLS-PKGDATADIR=[$v]\"\n" "test -n \"$v\"\n" ;; AND THE VALUE MUST NAME A REAL DIRECTORY -- ;; but the STAGED one. `$v` is an absolute ;; `/sigil/store/<item>/...` path, which is where ;; the directory will live once this output is in ;; the store and bound into a consumer's sandbox. ;; It does not exist yet DURING this build; the ;; files are under `$d` until the realizer moves ;; them. So the staged equivalent is `$d$v`. ;; ;; The first version of this check tested `$v` ;; directly and failed the build immediately -- ;; which is the right direction for a new gate to ;; be wrong in, and worth leaving a note about: ;; a path emitted by pkg-config is a CONSUMER-time ;; path, and a build-time assertion about it has ;; to add the staging offset. "test -d \"$d$v\"\n" "echo WAYLAND-PROTOCOLS-INSTALLED\n"))))))))