3 # This is a script that can be used in each book's CI to validate links using
4 # the same tool as rust-lang/rust.
6 # This requires the rust-docs rustup component to be installed in the nightly
10 # ./linkcheck.sh <name-of-book>
14 # -i "Iterative" mode. The script will not clean up after it is done so
15 # you can inspect the result, and re-run more quickly.
17 # --all Check all books. This can help make sure you don't break links
18 # from other books into your book.
22 if [ ! -f book.toml ] && [ ! -f src/SUMMARY.md ]
24 echo "Run command in root directory of the book."
28 html_dir="$(rustc +nightly --print sysroot)/share/doc/rust/html"
30 if [ ! -d "$html_dir" ]
32 echo "HTML docs are missing from sysroot: $html_dir"
33 echo "Make sure the nightly rust-docs rustup component is installed."
38 # Iterative will avoid cleaning up, so you can quickly run it repeatedly.
40 # If "1", test all books, else only this book.
53 if [ -n "$book_name" ]
55 echo "only one argument allowed"
64 if [ -z "$book_name" ]
66 echo "usage: $0 <name-of-book>"
70 if [ ! -d "$html_dir/$book_name" ]
72 echo "book name \"$book_name\" not found in sysroot \"$html_dir\""
76 if [ "$iterative" = "0" ]
78 echo "Cleaning old directories..."
79 rm -rf linkcheck linkchecker
82 if [ ! -e "linkchecker/main.rs" ] || [ "$iterative" = "0" ]
84 echo "Downloading linkchecker source..."
86 curl -o linkchecker/Cargo.toml \
87 https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/Cargo.toml
88 curl -o linkchecker/main.rs \
89 https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/main.rs
92 echo "Building book \"$book_name\"..."
95 cp -R "$html_dir" linkcheck
96 rm -rf "linkcheck/$book_name"
97 cp -R book "linkcheck/$book_name"
99 if [ "$all_books" = "1" ]
101 check_path="linkcheck"
103 check_path="linkcheck/$book_name"
105 echo "Running linkchecker on \"$check_path\"..."
106 cargo run --manifest-path=linkchecker/Cargo.toml -- "$check_path"
108 if [ "$iterative" = "0" ]
110 rm -rf linkcheck linkchecker
113 echo "Link check completed successfully!"