summaryrefslogtreecommitdiffstats
path: root/src/tools/linkchecker
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /src/tools/linkchecker
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/linkchecker')
-rwxr-xr-xsrc/tools/linkchecker/linkcheck.sh26
-rw-r--r--src/tools/linkchecker/main.rs35
2 files changed, 34 insertions, 27 deletions
diff --git a/src/tools/linkchecker/linkcheck.sh b/src/tools/linkchecker/linkcheck.sh
index 9eeebf444..6c1e668a7 100755
--- a/src/tools/linkchecker/linkcheck.sh
+++ b/src/tools/linkchecker/linkcheck.sh
@@ -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" ]
@@ -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.
@@ -52,6 +52,10 @@ do
--all)
all_books=1
;;
+ --path)
+ book_path="${2:-.}"
+ shift
+ ;;
*)
if [ -n "$book_name" ]
then
@@ -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\""
@@ -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
diff --git a/src/tools/linkchecker/main.rs b/src/tools/linkchecker/main.rs
index 4170c32f1..c8a370085 100644
--- a/src/tools/linkchecker/main.rs
+++ b/src/tools/linkchecker/main.rs
@@ -139,18 +139,18 @@ enum FileEntry {
type Cache = HashMap<String, FileEntry>;
fn small_url_encode(s: &str) -> String {
- s.replace("<", "%3C")
- .replace(">", "%3E")
- .replace(" ", "%20")
- .replace("?", "%3F")
- .replace("'", "%27")
- .replace("&", "%26")
- .replace(",", "%2C")
- .replace(":", "%3A")
- .replace(";", "%3B")
- .replace("[", "%5B")
- .replace("]", "%5D")
- .replace("\"", "%22")
+ s.replace('<', "%3C")
+ .replace('>', "%3E")
+ .replace(' ', "%20")
+ .replace('?', "%3F")
+ .replace('\'', "%27")
+ .replace('&', "%26")
+ .replace(',', "%2C")
+ .replace(':', "%3A")
+ .replace(';', "%3B")
+ .replace('[', "%5B")
+ .replace(']', "%5D")
+ .replace('\"', "%22")
}
impl Checker {
@@ -267,7 +267,6 @@ impl Checker {
FileEntry::OtherFile => return,
FileEntry::Redirect { target } => {
let t = target.clone();
- drop(target);
let (target, redir_entry) = self.load_file(&t, report);
match redir_entry {
FileEntry::Missing => {
@@ -391,7 +390,7 @@ impl Checker {
const ERROR_INVALID_NAME: i32 = 123;
let pretty_path =
- file.strip_prefix(&self.root).unwrap_or(&file).to_str().unwrap().to_string();
+ file.strip_prefix(&self.root).unwrap_or(file).to_str().unwrap().to_string();
let entry =
self.cache.entry(pretty_path.clone()).or_insert_with(|| match fs::metadata(file) {
@@ -470,10 +469,8 @@ fn is_exception(file: &Path, link: &str) -> bool {
// NOTE: This cannot be added to `LINKCHECK_EXCEPTIONS` because the resolved path
// calculated in `check` function is outside `build/<triple>/doc` dir.
// So the `strip_prefix` method just returns the old absolute broken path.
- if file.ends_with("std/primitive.slice.html") {
- if link.ends_with("primitive.slice.html") {
- return true;
- }
+ if file.ends_with("std/primitive.slice.html") && link.ends_with("primitive.slice.html") {
+ return true;
}
false
}
@@ -545,7 +542,7 @@ fn with_attrs_in_source<F: FnMut(&str, usize, &str)>(source: &str, attr: &str, m
fn parse_ids(ids: &mut HashSet<String>, file: &str, source: &str, report: &mut Report) {
if ids.is_empty() {
with_attrs_in_source(source, " id", |fragment, i, _| {
- let frag = fragment.trim_start_matches("#").to_owned();
+ let frag = fragment.trim_start_matches('#').to_owned();
let encoded = small_url_encode(&frag);
if !ids.insert(frag) {
report.errors += 1;