Skip to content

Commit 9f39295

Browse files
authored
Rollup merge of rust-lang#110565 - weihanglo:linkchecker, r=ehuss
linkchecker: running from a directory separate from the book Since rust-lang/cargo#11851, Cargo became a Cargo workspace of itself. However, since `src/tools/linkchecker` cannot run inside a workspace, Cargo needs a workaround that excludes `src/doc` from workspace member probing. To remove this hack, this PR adds a new optional argument `--path` for `linkchecker.sh`. With this new argument, `linkchecker.sh` can be run from a directory separate from the book. This also benefits other projects using linkchecker, as they can run it under target directory or any other directory, reducing leftover.
2 parents 4624616 + 60f1790 commit 9f39295

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/tools/linkchecker/linkcheck.sh

+18-8
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@
1616
#
1717
# --all Check all books. This can help make sure you don't break links
1818
# from other books into your book.
19+
#
20+
# --path <book-path>
21+
# Path to the root directory for the book. Default to the current
22+
# working directory if omitted.
1923

2024
set -e
2125

22-
if [ ! -f book.toml ] && [ ! -f src/SUMMARY.md ]
23-
then
24-
echo "Run command in root directory of the book."
25-
exit 1
26-
fi
27-
2826
html_dir="$(rustc +nightly --print sysroot)/share/doc/rust/html"
2927

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

4038
book_name=""
39+
# Default to the current directory
40+
book_path="."
4141
# Iterative will avoid cleaning up, so you can quickly run it repeatedly.
4242
iterative=0
4343
# If "1", test all books, else only this book.
@@ -52,6 +52,10 @@ do
5252
--all)
5353
all_books=1
5454
;;
55+
--path)
56+
book_path="${2:-.}"
57+
shift
58+
;;
5559
*)
5660
if [ -n "$book_name" ]
5761
then
@@ -70,6 +74,12 @@ then
7074
exit 1
7175
fi
7276

77+
if [ ! -f "$book_path/book.toml" ] && [ ! -f "$book_path/src/SUMMARY.md" ]
78+
then
79+
echo "Run command in root directory of the book or provide a path to the book"
80+
exit 1
81+
fi
82+
7383
if [ ! -d "$html_dir/$book_name" ]
7484
then
7585
echo "book name \"$book_name\" not found in sysroot \"$html_dir\""
@@ -93,11 +103,11 @@ then
93103
fi
94104

95105
echo "Building book \"$book_name\"..."
96-
mdbook build
106+
mdbook build "$book_path"
97107

98108
cp -R "$html_dir" linkcheck
99109
rm -rf "linkcheck/$book_name"
100-
cp -R book "linkcheck/$book_name"
110+
cp -R "$book_path/book" "linkcheck/$book_name"
101111

102112
if [ "$all_books" = "1" ]
103113
then

0 commit comments

Comments
 (0)