Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linkchecker: running from a directory separate from the book #110565

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/tools/linkchecker/linkcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
#
# --all Check all books. This can help make sure you don't break links
# from other books into your book.
#
# --path <book-path>
# Path to the root directory for the book. Default to the current
# working directory if omitted.

set -e

if [ ! -f book.toml ] && [ ! -f src/SUMMARY.md ]
then
echo "Run command in root directory of the book."
exit 1
fi

html_dir="$(rustc +nightly --print sysroot)/share/doc/rust/html"

if [ ! -d "$html_dir" ]
Expand All @@ -38,6 +36,8 @@ fi
export MDBOOK_OUTPUT__HTML__INPUT_404=""

book_name=""
# Default to the current directory
book_path="."
# Iterative will avoid cleaning up, so you can quickly run it repeatedly.
iterative=0
# If "1", test all books, else only this book.
Expand All @@ -52,6 +52,10 @@ do
--all)
all_books=1
;;
--path)
book_path="${2:-.}"
shift
;;
*)
if [ -n "$book_name" ]
then
Expand All @@ -70,6 +74,12 @@ then
exit 1
fi

if [ ! -f "$book_path/book.toml" ] && [ ! -f "$book_path/src/SUMMARY.md" ]
then
echo "Run command in root directory of the book or provide a path to the book"
exit 1
fi

if [ ! -d "$html_dir/$book_name" ]
then
echo "book name \"$book_name\" not found in sysroot \"$html_dir\""
Expand All @@ -93,11 +103,11 @@ then
fi

echo "Building book \"$book_name\"..."
mdbook build
mdbook build "$book_path"

cp -R "$html_dir" linkcheck
rm -rf "linkcheck/$book_name"
cp -R book "linkcheck/$book_name"
cp -R "$book_path/book" "linkcheck/$book_name"

if [ "$all_books" = "1" ]
then
Expand Down