Skip to content

eBPF-based security platform

docs: check the figures only in a tree that has their script

Daniel Borkmannb724835644de
diff --git a/.github/scripts/check-docs.sh b/.github/scripts/check-docs.sh
index 858b00e2..e2b1716e 100755
--- a/.github/scripts/check-docs.sh
+++ b/.github/scripts/check-docs.sh
@@ -204,8 +204,10 @@ while IFS= read -r page; do
done <"$work/pages"
# Every figure of Documentation/images/ is what its TikZ source makes,
-# which build.py tells from the hash it recorded, without TeX.
-if ! python3 Documentation/figures/build.py --check 2>"$work/figures"; then
+# which build.py tells from the hash it recorded, without TeX. A tree
+# without the script has no figures to check.
+if [ -f Documentation/figures/build.py ] &&
+ ! python3 Documentation/figures/build.py --check 2>"$work/figures"; then
while IFS= read -r line; do
report Documentation/figures "${line#figures: }"
done <"$work/figures"
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index 1469bc0a..996c2984 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -69,7 +69,8 @@ signed config image.
- ``check-docs.sh``: the whole of each field of a threat's fact
box, a hook by its section, each tamper and integrity counter's
entry on its page, the source files a proof reads or the proof
- coverage page lists as read by none, and the tree itself
+ coverage page lists as read by none, a figure against its TikZ
+ source and one without a source, and the tree itself
* - ``t0009-check-unused``
- ``check-unused.sh``: an extern function nothing calls, with its
type on its line or the one above, a header's declaration that is
diff --git a/testing/ci-checks/t0008-check-docs.sh b/testing/ci-checks/t0008-check-docs.sh
index b59140ec..3f3832c8 100755
--- a/testing/ci-checks/t0008-check-docs.sh
+++ b/testing/ci-checks/t0008-check-docs.sh
@@ -4,8 +4,9 @@
#
# t0008 -- .github/scripts/check-docs.sh: the whole of each field of a
# threat's fact box, a hook by its section, the programs and counters no
-# threat names, and the source files a proof reads or the coverage page
-# lists as read by none, on a throwaway repository, and the tree itself.
+# threat names, the source files a proof reads or the coverage page
+# lists as read by none, and a figure against its TikZ source, on a
+# throwaway repository, and the tree itself.
cd "$(dirname "$0")/.."
. ./test-lib.sh
@@ -129,6 +130,38 @@ test_expect_success 'the list names only source files no proof reads' '
grep -qF "no proof reads util/unread.c and no line says why" "$W/err"
'
+# The hash build.py records in the SVG of the figure $1, from the copy of
+# build.py and the style in the throwaway tree.
+figure_stamp() {
+ (cd "$R" && python3 - "$1" <<'EOF'
+import sys
+from pathlib import Path
+sys.path.insert(0, "Documentation/figures")
+import build
+print(build.digest(Path("Documentation/figures") / (sys.argv[1] + ".tex")))
+EOF
+ )
+}
+
+# A tree with one figure, f, whose SVG records the hash of its source.
+with_figure() {
+ good && mkdir -p "$R/Documentation/figures" &&
+ cp "$ROOT/Documentation/figures/build.py" \
+ "$ROOT/Documentation/figures/shirudo-figure.sty" \
+ "$R/Documentation/figures/" &&
+ put Documentation/figures/f.tex "% f" &&
+ put Documentation/images/f.svg \
+ "<svg><!-- Documentation/figures/f.tex, sha256 $(figure_stamp f) --></svg>"
+}
+
+test_expect_success 'a figure is what its TikZ source makes, and has one' '
+ with_figure && check &&
+ put Documentation/figures/f.tex "% f, changed" &&
+ refuses "images/f.svg is not what figures/f.tex makes" &&
+ with_figure && put Documentation/images/g.svg "<svg></svg>" &&
+ refuses "images/g.svg has no source figures/g.tex"
+'
+
test_expect_success 'the tree itself passes' '
(cd "$ROOT" && sh "$S") >"$W/out" 2>"$W/err"
'