377. The image gates
This page explains the last checks the tree must pass before it becomes an image, and what to do when one of them stops the build. Read it when the image phase fails in 087_gates.sh.
Every package passed the package lint when it was built. Some faults are visible only in the finished tree, where every package sits beside every other:
- a library a program loads from a package it never declared;
- a script whose interpreter is not installed;
- a desktop entry whose program is missing;
- a link into a package that was swept;
- a QML module the base left out.
script/phases/70_image/087_gates.sh runs four checks over the tree that is about to become the image, and stops the phase on their findings, before the initramfs and the ISO are written. The first check stops the phase only for what it finds under the four directories that hold manuals, documentation and translations. A build with KDOS_MAKE_BINHOST=1 adds a fifth check, over the binhost 010_binhost.sh wrote. A last report, which never stops the phase, lists the packages that install no licence text.
The step
# only this phase to re-run once the recipe or ports/base is fixed.
#
# RUNS AFTER the sweep and every index (the manual index, the font cache), so
# what it reads is what the image carries, and before 090_initramfs.sh and
# 110_iso.sh. What the later steps write into the tree (the initramfs and its
# module list, the source offer) is generated, and unowned.py subtracts it,
# as it does KDOS's licence text, which 10_bootstrap's 000_file_system.sh
# installs.
# The scripts read the repository's phase lists and recipes, so the working
# directory is /kdos.
set -e
source script/phases/70_image/phase.env
cd /kdos
rc=0
# Ports whose sources hold no licence text: public-domain and CC0 code and
# data, and data published under terms no file of the source carries.
LICENCE_TEXTLESS="sqlite snooze iana-etc debian-dep11 fwupd-snapshot"
echo "[gates] unowned files"
python3 testing/unowned.py --root / --fs /kdos/fs \
--fail-under usr/share/locale --fail-under usr/share/man \
--fail-under usr/share/doc --fail-under usr/share/info || rc=1
echo "[gates] run-time references"
python3 testing/linkcheck.py --root / || rc=1
echo "[gates] links, launchers and rules"
python3 testing/entrycheck.py --root / || rc=1
if [ "${KDOS_IMAGE:-base}" = full ]; then
echo "[gates] the base's run-time needs: KDOS_IMAGE=full drops nothing"
else
echo "[gates] the base's run-time needs"
python3 script/lib/imageset.py --tree /kdos --root / --verify \
--full /kdos/build/fs || rc=1
fi
if [ "${KDOS_MAKE_BINHOST:-0}" = 1 ] && [ -f /kdos/build/binhost/PACKAGES ]; then
echo "[gates] the binhost's measured run-time needs"
unmeasured=$(awk -v RS= -F'\n' '{
p = ""; e = ""; o = 0; n = 0
for (i = 1; i <= NF; i++) {
if ($i ~ /^P:/) p = substr($i, 3)
else if ($i ~ /^E:/) e = substr($i, 3)
else if ($i ~ /^O:/) o = 1
else if ($i ~ /^N:/) n = 1
}
if (p != "" && e != "" && !o && !n) print p
}' /kdos/build/binhost/PACKAGES)
if [ -n "$unmeasured" ]; then
echo "FAIL $(wc -w <<<"$unmeasured") binhost package(s) carry no N: line (no run-time needs record): $(head -c 600 <<<"${unmeasured//$'\n'/ }")"
rc=1
fi
fi
echo "[gates] licence texts"
nolicence=
expected=
for p in /var/lib/kpkg/db/*; do
[ -f "$p" ] || continue
n=${p##*/}
[ -d "/usr/share/licenses/$n" ] && continue
awk 'NR > 1 && /[^\/]$/ { found = 1; exit } END { exit !found }' "$p" || continue
case " $LICENCE_TEXTLESS " in
*" $n "*) expected="$expected $n" ;;
*) nolicence="$nolicence $n" ;;
esac
done
[ -z "$expected" ] || echo " no text in the source, as expected:$expected"
if [ -n "$nolicence" ]; then
echo " $(wc -w <<<"$nolicence") package(s) install no /usr/share/licenses/<name>:$nolicence"
else
echo " every other package installs /usr/share/licenses/<name>"
fi
if [ "$rc" != 0 ]; then
echo "FATAL: the tree fails unowned, linkcheck, entrycheck, the base's run-time needs or the binhost's N: lines; see the FAIL and finding lines above." >&2
exit 1
script/phases/70_image/087_gates.sh, lines 56–136
The first three checks are Python programs in testing/, which script/chroot/exec.sh binds read-only at /kdos/testing in the chroot; the fourth is script/lib/imageset.py, the script that chose the base. They read the phase lists and recipes of the repository, so the step changes into /kdos first. Each is given --root /, the root being built.
Every check runs before the step decides. A finding in the first does not hide the others, so one failed build prints every problem the tree has, not just the first.
The four checks
testing/unowned.py-
Lists every file and symlink that no package’s manifest and no path of
fs/provides. Such a file is removed by no package removal and replaced by no update: it was written outside a package’s staging tree, by a tool run against the live root, or lost from a manifest. Mount points, scratch, homes, kpkg’s state, kpkg and kinstall themselves, and what is generated over every package (the shared indexes, the launcher table, the source offer, KDOS’s licence text, the initramfs and its module list) are subtracted; aLICENSElink to that text belongs to the package kpkg built it into, and one no package owns is reported. The report covers the whole tree, and a finding stops the phase only underusr/share/locale,usr/share/man,usr/share/docorusr/share/info, the four--fail-underdirectories, where it prints aFAIL unownedline for each path. 020_cleanup.sh has already removed every unowned file there that kpkg’s size and language policy prunes from a package, so what is left is a manual or catalogue that would ship and that no removal or update would ever touch. Any other unowned file is reported and passes. testing/linkcheck.py-
Reads every file the package manifests name, and fails on three kinds of finding. An ELF file’s
DT_NEEDED, resolved the way musl’s loader resolves it, lands in a package outside the consumer’s transitivedepends: a dependency only the build order supplied, which a removal, a parallel build or an update can take away. A script’s#!interpreter, or an ELF file’s interpreter, does not resolve in the root. Or one process would map bothlibcrypto.so.3andlibcrypto.so.4, whose symbols musl would bind to whichever was loaded first. It also prints warnings that do not fail. testing/entrycheck.py-
Fails on a symlink that resolves to nothing; a desktop entry’s or D-Bus service’s
Exec=whose program is not in the root; a visible desktop entry whoseIcon=no icon theme provides; and a udev rule’sRUN,PROGRAMorIMPORT{program}whose program does not exist. Each of these does nothing at run time without saying why: the menu shows a launcher that starts nothing, the bus activates nothing, the menu draws a blank, and udev logs the failure at debug level. script/lib/imageset.py --verify-
Runs under
KDOS_IMAGE=baseonly. Reads the run-time needs each kept package’s install recorded in/var/lib/kpkg/db/.needs/<name>(its sonames,#!interpreters, QML and Python imports and its recipe’sruntime =words; see Run-time needs) and resolves each in the stage. An edge nothing in the stage provides is looked up in--full /kdos/build/fs, the tree the stage was trimmed from, and one a package there provides printsFAIL <package>: <edge>: only <provider> provides it, and the image drops it. A package with no record (installed before records were kept) is counted as unmeasured, and an edge nothing in either tree provides is counted; neither fails. UnderKDOS_IMAGE=fullnothing is dropped and the step says so. - The binhost’s
N:lines -
Runs under
KDOS_MAKE_BINHOST=1only, when/kdos/build/binhost/PACKAGESexists. A current package stanza, one with anE:and noO:, must carry anN:line, the build-only ports the package needs at run time (see 010_binhost.sh). One without it has no run-time needs record in the build tree, sokdos update installwould keep every build-only dependency of it; the check printsFAIL <n> binhost package(s) carry no N: line (no run-time needs record): <names>, and rebuilding each named port records its needs. - The licence texts
-
A report, never a failure. Every installed package that owns a file and has no
/usr/share/licenses/<name>is listed. A package of our own whose licence namesMITcarries a link to KDOS’s text from kpkg, so it is listed only when it is of another licence alone and itsbuild.shinstalls no text. The ports inLICENCE_TEXTLESS(sqlite,snooze,iana-etc,debian-dep11andfwupd-snapshot, whose sources hold no text: public-domain and CC0 code and data, and data published under terms no file carries) are printed apart, on a lineno text in the source, as expected:. Any other name, on the line<n> package(s) install no /usr/share/licenses/<name>:, is a port whose source keeps its text where kpkg does not look, and itsbuild.shshould install it (see What kpkg does around build.sh).
Under KDOS_IMAGE=base the tree is the image stage, trimmed to the base, so linkcheck.py, entrycheck.py and imageset.py --verify are also the proof that the base’s closure is whole. A library, an interpreter, a program, a QML module or a Python package that a base package needs, and that went with the packages 017_stage.sh removed, is a finding. The fix is a depends = or runtime = the recipe lacks, or a name to add to ports/base. Only imageset.py --verify sees a QML or a Python import, and only for a package installed since its needs were recorded.
The exact rules of each, their exemptions and how to run them by hand are in Files nothing owns, Run-time references and Links, launchers and rules.
When it stops the phase
Each check marks what stopped the phase:
| Check | What it prints |
|---|---|
unowned.py |
A FAIL unowned line for each path it stops on |
linkcheck.py |
A FAIL line for each finding |
entrycheck.py |
A line naming the kind of each finding (link, exec, icon or udev), and a count of each at the end |
imageset.py --verify |
A FAIL line for each edge met only outside the base, and an imageset: verify: count line |
| The binhost check | One FAIL line naming its packages |
All of them are in the step’s log, build/logs/70_image/<NNNN>_gates.sh.log (see Step logs).
The fix is usually in a recipe: a missing depends, a package that installs a link to a file it does not ship, a desktop entry naming the wrong program, or a build that installs a manual outside its package. Rebuild the port, then run the image phase again; nothing earlier needs to run:
make build BUILD_ARGS="--phases <phase>,70_image --rebuild <port>"
You can run the checks on your machine over build/fs without a build:
| Check | Command |
|---|---|
| Files nothing owns | make unowned |
| Run-time references | make linkcheck |
| Links, launchers and rules | make entrycheck |
| The base’s run-time needs | python3 script/lib/imageset.py --root build/fs --verify |
The last fails a kept package whose edge only a dropped package of build/fs provides. For packages with no record, measure them first with kpkg needs --scan and pass the directory with --needs (Run-time needs).
build/fs holds every package, so under KDOS_IMAGE=base these commands check the whole tree and not the base; only this step checks the stage, which exists only while a step runs. build/fs belongs to root, so run them from a container or as root; see The other harnesses.
Why it runs here
After the trim, the orphan sweep and every index, so it checks exactly what the image carries, and before 090_initramfs.sh and 110_iso.sh, so a tree that fails is never written into an image. The files those later steps write into the root, the initramfs and its module list, and the source offer from 105_ports.sh, are generated, and unowned.py subtracts them, as it does KDOS’s licence text from 000_file_system.sh.
What it leaves
Nothing. The step only reads the tree.
See also
- The other harnesses: every tree check and what it proves
- The package lint: the checks made on each package as it is built
- A build that failed: reading a failed step