mirror of https://github.com/rust-lang/book
Add rustfmt to the update-rustc script
With a mechanism to ignore particular listings for various reasons
This commit is contained in:
parent
bc8c9f1013
commit
dec27eead0
|
@ -68,6 +68,10 @@ listing beyond the most trivial should be extracted into a file. To do that:
|
|||
of user input or external events like making a web request), keep the output inline but make a
|
||||
comment that contains `manual-regeneration` and instructions for manually updating the inline
|
||||
output.
|
||||
- If you don't want this example to even be attempted to be formatted by `rustfmt` (for example
|
||||
because the example doesn't parse on purpose), add a `rustfmt-ignore` file in the listing's
|
||||
directory and the reason it's not being formatted as the contents of that file (in case it's a
|
||||
rustfmt bug that might get fixed someday).
|
||||
|
||||
## See the effect of some change on the rendered book
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
This listing deliberately doesn't parse so rustfmt fails.
|
|
@ -0,0 +1,3 @@
|
|||
We have some weird comments pointing out borrowing scopes that we don't want to change;
|
||||
unfortunately I haven't found a way to skip them with rustfmt that works so for now we're going to
|
||||
manually skip those listings. See: https://github.com/rust-lang/rustfmt/issues/4028
|
|
@ -0,0 +1,3 @@
|
|||
We have some weird comments pointing out borrowing scopes that we don't want to change;
|
||||
unfortunately I haven't found a way to skip them with rustfmt that works so for now we're going to
|
||||
manually skip those listings. See: https://github.com/rust-lang/rustfmt/issues/4028
|
|
@ -0,0 +1,3 @@
|
|||
We have some weird comments pointing out borrowing scopes that we don't want to change;
|
||||
unfortunately I haven't found a way to skip them with rustfmt that works so for now we're going to
|
||||
manually skip those listings. See: https://github.com/rust-lang/rustfmt/issues/4028
|
|
@ -0,0 +1,3 @@
|
|||
We have some weird comments pointing out borrowing scopes that we don't want to change;
|
||||
unfortunately I haven't found a way to skip them with rustfmt that works so for now we're going to
|
||||
manually skip those listings. See: https://github.com/rust-lang/rustfmt/issues/4028
|
|
@ -0,0 +1,3 @@
|
|||
We have some weird comments pointing out borrowing scopes that we don't want to change;
|
||||
unfortunately I haven't found a way to skip them with rustfmt that works so for now we're going to
|
||||
manually skip those listings. See: https://github.com/rust-lang/rustfmt/issues/4028
|
|
@ -0,0 +1,3 @@
|
|||
We have some weird comments pointing out borrowing scopes that we don't want to change;
|
||||
unfortunately I haven't found a way to skip them with rustfmt that works so for now we're going to
|
||||
manually skip those listings. See: https://github.com/rust-lang/rustfmt/issues/4028
|
|
@ -0,0 +1,3 @@
|
|||
We have some weird comments pointing out borrowing scopes that we don't want to change;
|
||||
unfortunately I haven't found a way to skip them with rustfmt that works so for now we're going to
|
||||
manually skip those listings. See: https://github.com/rust-lang/rustfmt/issues/4028
|
|
@ -0,0 +1,3 @@
|
|||
We have some weird comments pointing out borrowing scopes that we don't want to change;
|
||||
unfortunately I haven't found a way to skip them with rustfmt that works so for now we're going to
|
||||
manually skip those listings. See: https://github.com/rust-lang/rustfmt/issues/4028
|
|
@ -0,0 +1,2 @@
|
|||
This listing is used for demonstrating how to set up a workspace, but the workspace isn't
|
||||
completely set up yet, so rustfmt complains the crate mentioned in Cargo.toml doesn't exist yet.
|
|
@ -0,0 +1 @@
|
|||
This listing deliberately doesn't parse so rustfmt fails.
|
|
@ -0,0 +1 @@
|
|||
max_width = 80
|
|
@ -67,6 +67,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
//
|
||||
// - `target` directories
|
||||
// - `output.txt` files used to display output in the book
|
||||
// - `rustfmt-ignore` files used to signal to update-rustc.sh the listing shouldn't be formatted
|
||||
// - anchor comments or snip comments
|
||||
// - empty `main` functions in `lib.rs` files used to trick rustdoc
|
||||
fn copy_cleaned_listing_files(from: PathBuf, to: PathBuf) -> Result<(), Box<dyn Error>> {
|
||||
|
@ -84,8 +85,8 @@ fn copy_cleaned_listing_files(from: PathBuf, to: PathBuf) -> Result<(), Box<dyn
|
|||
copy_cleaned_listing_files(item_path, output_item)?;
|
||||
}
|
||||
} else {
|
||||
// Don't copy output files
|
||||
if item_name != "output.txt" {
|
||||
// Don't copy output files or files that tell update-rustc.sh not to format
|
||||
if item_name != "output.txt" && item_name != "rustfmt-ignore" {
|
||||
let item_extension = item_path.extension();
|
||||
if item_extension.is_some() && item_extension.unwrap() == "rs" {
|
||||
copy_cleaned_rust_file(item_name, &item_path, &output_item)?;
|
||||
|
|
|
@ -6,7 +6,19 @@ set -eu
|
|||
echo 'Building book into `tmp/book-before` before updating...'
|
||||
mdbook build -d tmp/book-before
|
||||
|
||||
# TODO: Rustfmt all listings here
|
||||
# Rustfmt all listings
|
||||
echo 'Formatting all listings...'
|
||||
find -s listings -name Cargo.toml -print0 | while IFS= read -r -d '' f; do
|
||||
dir_to_fmt=$(dirname $f)
|
||||
|
||||
# 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.
|
||||
if [ ! -f "${dir_to_fmt}/rustfmt-ignore" ]; then
|
||||
cd $dir_to_fmt
|
||||
cargo fmt --all && true
|
||||
cd - > /dev/null
|
||||
fi
|
||||
done
|
||||
|
||||
# Get listings without anchor comments in tmp by compiling a release listings artifact
|
||||
echo 'Generate listings without anchor comments...'
|
||||
|
|
Loading…
Reference in New Issue