aboutsummaryrefslogtreecommitdiff
path: root/bin/check_links
blob: a07997672078badeeb48e66373a3b188751e2e28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
#
# Check rustdoc HTML links and anchors
# bin/build_html must have been run first.
#
# Adapted from
#    https://gitlab.torproject.org/Diziet/rust-derive-adhoc/-/blob/main/maint/check-doc-links?ref_type=heads

set -e
set -o pipefail

# nailing-cargo --no-nail --- bin/build_html
# nailing-cargo --preclean=no --- bin/check_links

chk_dir=html.link-check

rm -rf html.link-check
cp -al html $chk_dir

# Fix up https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=425632

# shellcheck disable=SC2016
find $chk_dir -name \*.html -print0 |
xargs -0r -- perl -i~ -pe '
	s{\bid=("[^"]+")[^<>]*\>}{$&<a name=$1>}g;
'

linklint -xref -out linklint.errors -error -root $chk_dir /@

cat linklint.errors

set +e
grep ERROR linklint.errors
rc=$?
set -e

case $rc in
0) echo >&2 '** found linkcheck errors **'; exit 1;;
1) ;;
*) echo >&2 "linkcheck failed $rc"; exit 1;;
esac