mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-02-02 23:38:41 +08:00
Make fixes recommended by shellcheck
This commit is contained in:
parent
6c310b9ca8
commit
9dd1b807c4
9
tools/convert-quotes.sh
Normal file → Executable file
9
tools/convert-quotes.sh
Normal file → Executable file
@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
dir=$1
|
mkdir -p tmp/src
|
||||||
|
rm -rf tmp/*.md
|
||||||
|
|
||||||
mkdir -p "tmp/$dir"
|
for f in src/"${1:-\"\"}"*.md
|
||||||
|
|
||||||
for f in $dir/*.md
|
|
||||||
do
|
do
|
||||||
cat "$f" | cargo run --bin convert_quotes > "tmp/$f"
|
cargo run --bin convert_quotes < "$f" > "tmp/$f"
|
||||||
mv "tmp/$f" "$f"
|
mv "tmp/$f" "$f"
|
||||||
done
|
done
|
||||||
|
2
tools/doc-to-md.sh
Normal file → Executable file
2
tools/doc-to-md.sh
Normal file → Executable file
@ -3,7 +3,7 @@
|
|||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
# Get all the docx files in the tmp dir.
|
# Get all the docx files in the tmp dir.
|
||||||
ls tmp/*.docx | \
|
find tmp -name '*.docx' -print0 | \
|
||||||
# Extract just the filename so we can reuse it easily.
|
# Extract just the filename so we can reuse it easily.
|
||||||
xargs -n 1 basename -s .docx | \
|
xargs -n 1 basename -s .docx | \
|
||||||
while IFS= read -r filename; do
|
while IFS= read -r filename; do
|
||||||
|
2
tools/megadiff.sh
Normal file → Executable file
2
tools/megadiff.sh
Normal file → Executable file
@ -12,7 +12,7 @@ rm -rf tmp/book-after/css/ tmp/book-after/theme/ tmp/book-after/img/ tmp/book-af
|
|||||||
tmp/book-after/*.json tmp/book-after/print.html
|
tmp/book-after/*.json tmp/book-after/print.html
|
||||||
|
|
||||||
# Get all the html files before
|
# Get all the html files before
|
||||||
ls tmp/book-before/*.html | \
|
find tmp/book-before -name '*.html' -print0 | \
|
||||||
# Extract just the filename so we can reuse it easily.
|
# Extract just the filename so we can reuse it easily.
|
||||||
xargs -n 1 basename | \
|
xargs -n 1 basename | \
|
||||||
while IFS= read -r filename; do
|
while IFS= read -r filename; do
|
||||||
|
2
tools/nostarch.sh
Normal file → Executable file
2
tools/nostarch.sh
Normal file → Executable file
@ -12,7 +12,7 @@ rm -rf tmp/markdown
|
|||||||
MDBOOK_OUTPUT__MARKDOWN=1 mdbook build -d tmp
|
MDBOOK_OUTPUT__MARKDOWN=1 mdbook build -d tmp
|
||||||
|
|
||||||
# Get all the Markdown files
|
# Get all the Markdown files
|
||||||
ls tmp/markdown/${1:-""}*.md | \
|
find tmp/markdown -name "${1:-\"\"}*.md" -print0 | \
|
||||||
# Extract just the filename so we can reuse it easily.
|
# Extract just the filename so we can reuse it easily.
|
||||||
xargs -n 1 basename | \
|
xargs -n 1 basename | \
|
||||||
# Remove all links followed by `<!-- ignore -->``, then
|
# Remove all links followed by `<!-- ignore -->``, then
|
||||||
|
31
tools/update-rustc.sh
Normal file → Executable file
31
tools/update-rustc.sh
Normal file → Executable file
@ -3,18 +3,18 @@
|
|||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
# Build the book before making any changes for comparison of the output.
|
# Build the book before making any changes for comparison of the output.
|
||||||
echo 'Building book into `tmp/book-before` before updating...'
|
echo 'Building book into tmp/book-before before updating...'
|
||||||
mdbook build -d tmp/book-before
|
mdbook build -d tmp/book-before
|
||||||
|
|
||||||
# Rustfmt all listings
|
# Rustfmt all listings
|
||||||
echo 'Formatting all listings...'
|
echo 'Formatting all listings...'
|
||||||
find -s listings -name Cargo.toml -print0 | while IFS= read -r -d '' f; do
|
find -s listings -name Cargo.toml -print0 | while IFS= read -r -d '' f; do
|
||||||
dir_to_fmt=$(dirname $f)
|
dir_to_fmt=$(dirname "$f")
|
||||||
|
|
||||||
# There are a handful of listings we don't want to rustfmt and skipping
|
# There are a handful of listings we don't want to rustfmt and skipping
|
||||||
# doesn't work; those will have a file in their directory that explains why.
|
# doesn't work; those will have a file in their directory that explains why.
|
||||||
if [ ! -f "${dir_to_fmt}/rustfmt-ignore" ]; then
|
if [ ! -f "${dir_to_fmt}/rustfmt-ignore" ]; then
|
||||||
cd $dir_to_fmt
|
cd "$dir_to_fmt"
|
||||||
cargo fmt --all && true
|
cargo fmt --all && true
|
||||||
cd - > /dev/null
|
cd - > /dev/null
|
||||||
fi
|
fi
|
||||||
@ -30,42 +30,42 @@ root_dir=$(pwd)
|
|||||||
echo 'Regenerating output...'
|
echo 'Regenerating output...'
|
||||||
# For any listings where we show the output,
|
# For any listings where we show the output,
|
||||||
find -s listings -name output.txt -print0 | while IFS= read -r -d '' f; do
|
find -s listings -name output.txt -print0 | while IFS= read -r -d '' f; do
|
||||||
build_directory=$(dirname $f)
|
build_directory=$(dirname "$f")
|
||||||
full_build_directory="${root_dir}/${build_directory}"
|
full_build_directory="${root_dir}/${build_directory}"
|
||||||
full_output_path="${full_build_directory}/output.txt"
|
full_output_path="${full_build_directory}/output.txt"
|
||||||
tmp_build_directory="tmp/${build_directory}"
|
tmp_build_directory="tmp/${build_directory}"
|
||||||
|
|
||||||
cd $tmp_build_directory
|
cd "$tmp_build_directory"
|
||||||
|
|
||||||
# Save the previous compile time; we're going to keep it to minimize diff
|
# Save the previous compile time; we're going to keep it to minimize diff
|
||||||
# churn
|
# churn
|
||||||
compile_time=$(sed -E -ne 's/.*Finished (dev|test) \[unoptimized \+ debuginfo] target\(s\) in ([0-9.]*).*/\2/p' ${full_output_path})
|
compile_time=$(sed -E -ne 's/.*Finished (dev|test) \[unoptimized \+ debuginfo] target\(s\) in ([0-9.]*).*/\2/p' "${full_output_path}")
|
||||||
|
|
||||||
# Save the hash from the first test binary; we're going to keep it to
|
# Save the hash from the first test binary; we're going to keep it to
|
||||||
# minimize diff churn
|
# minimize diff churn
|
||||||
test_binary_hash=$(sed -E -ne 's@.*Running [^[:space:]]+ \(target/debug/deps/[^-]*-([^\s]*)\)@\1@p' ${full_output_path} | head -n 1)
|
test_binary_hash=$(sed -E -ne 's@.*Running [^[:space:]]+ \(target/debug/deps/[^-]*-([^\s]*)\)@\1@p' "${full_output_path}" | head -n 1)
|
||||||
|
|
||||||
# Act like this is the first time this listing has been built
|
# Act like this is the first time this listing has been built
|
||||||
cargo clean
|
cargo clean
|
||||||
|
|
||||||
# Run the command in the existing output file
|
# Run the command in the existing output file
|
||||||
cargo_command=$(sed -ne 's/$ \(.*\)/\1/p' ${full_output_path})
|
cargo_command=$(sed -ne 's/$ \(.*\)/\1/p' "${full_output_path}")
|
||||||
|
|
||||||
# Clear the output file of everything except the command
|
# Clear the output file of everything except the command
|
||||||
echo "$ ${cargo_command}" > ${full_output_path}
|
echo "$ ${cargo_command}" > "${full_output_path}"
|
||||||
|
|
||||||
# Regenerate the output and append to the output file. Turn some warnings
|
# Regenerate the output and append to the output file. Turn some warnings
|
||||||
# off to reduce output noise, and use one test thread to get consistent
|
# off to reduce output noise, and use one test thread to get consistent
|
||||||
# ordering of tests in the output when the command is `cargo test`.
|
# ordering of tests in the output when the command is `cargo test`.
|
||||||
RUSTFLAGS="-A unused_variables -A dead_code" RUST_TEST_THREADS=1 $cargo_command >> ${full_output_path} 2>&1 || true
|
RUSTFLAGS="-A unused_variables -A dead_code" RUST_TEST_THREADS=1 $cargo_command >> "${full_output_path}" 2>&1 || true
|
||||||
|
|
||||||
# Set the project file path to the projects directory plus the crate name
|
# Set the project file path to the projects directory plus the crate name
|
||||||
# instead of a path to the computer of whoever is running this
|
# instead of a path to the computer of whoever is running this
|
||||||
sed -i '' -E -e 's@(Compiling|Checking) ([^\)]*) v0.1.0 (.*)@\1 \2 v0.1.0 (file:///projects/\2)@' ${full_output_path}
|
sed -i '' -E -e 's@(Compiling|Checking) ([^\)]*) v0.1.0 (.*)@\1 \2 v0.1.0 (file:///projects/\2)@' "${full_output_path}"
|
||||||
|
|
||||||
# Restore the previous compile time, if there is one
|
# Restore the previous compile time, if there is one
|
||||||
if [ -n "${compile_time}" ]; then
|
if [ -n "${compile_time}" ]; then
|
||||||
sed -i '' -E -e "s/Finished (dev|test) \[unoptimized \+ debuginfo] target\(s\) in [0-9.]*/Finished \1 [unoptimized + debuginfo] target(s) in ${compile_time}/" ${full_output_path}
|
sed -i '' -E -e "s/Finished (dev|test) \[unoptimized \+ debuginfo] target\(s\) in [0-9.]*/Finished \1 [unoptimized + debuginfo] target(s) in ${compile_time}/" "${full_output_path}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Restore the previous test binary hash, if there is one
|
# Restore the previous test binary hash, if there is one
|
||||||
@ -73,14 +73,17 @@ find -s listings -name output.txt -print0 | while IFS= read -r -d '' f; do
|
|||||||
replacement='s@Running ([^[:space:]]+) \(target/debug/deps/([^-]*)-([^\s]*)\)@Running \1 (target/debug/deps/\2-'
|
replacement='s@Running ([^[:space:]]+) \(target/debug/deps/([^-]*)-([^\s]*)\)@Running \1 (target/debug/deps/\2-'
|
||||||
replacement+="${test_binary_hash}"
|
replacement+="${test_binary_hash}"
|
||||||
replacement+=')@g'
|
replacement+=')@g'
|
||||||
sed -i '' -E -e "${replacement}" ${full_output_path}
|
sed -i '' -E -e "${replacement}" "${full_output_path}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Clean again
|
||||||
|
cargo clean
|
||||||
|
|
||||||
cd - > /dev/null
|
cd - > /dev/null
|
||||||
done
|
done
|
||||||
|
|
||||||
# Build the book after making all the changes
|
# Build the book after making all the changes
|
||||||
echo 'Building book into `tmp/book-after` after updating...'
|
echo 'Building book into tmp/book-after after updating...'
|
||||||
mdbook build -d tmp/book-after
|
mdbook build -d tmp/book-after
|
||||||
|
|
||||||
# Run the megadiff script that removes all files that are the same, leaving only files to audit
|
# Run the megadiff script that removes all files that are the same, leaving only files to audit
|
||||||
|
Loading…
Reference in New Issue
Block a user