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

Edition maintenance: scripting the updates for future work #4243

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion ADMIN_TASKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ occasional maintenance tasks.
## Update the `edition` in all listings

To update the `edition = "[year]"` metadata in all the listings' `Cargo.toml`s,
run the `./tools/update-editions.sh` script and commit the changes.
run the `./tools/update-editions.sh` script. Check the diff to make sure it
looks reasonable, and in particular check whether the updates necessitate any
changes to the text. Then commit the changes.

## Update the `edition` in mdBook config

Expand Down
8 changes: 0 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = [ "listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new", "listings/ch11-writing-automated-tests/listing-11-01","packages/tools"]
members = ["packages/tools"]
default-members = ["packages/tools"]
resolver = "2"
exclude = [
Expand Down
13 changes: 12 additions & 1 deletion tools/update-editions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@

set -eu

# So that we can do this in a single pass, check *here* if there are any “dirty”
# files from Git, and bail if so.
git diff --quiet || { echo "Git working directory is not clean"; exit 1; }

OLD_EDITION=2021
NEW_EDITION=2024

find listings/** -name "Cargo.toml" -exec sed -i '' "s/edition = \"$OLD_EDITION\"/edition = \"$NEW_EDITION\"/g" '{}' \;
# Start by preparing all listings for the edition.
find listings -name "Cargo.toml" -exec cargo fix --allow-dirty --edition --manifest-path '{}' \;

# Update the edition itself
find listings -name "Cargo.toml" -exec sed -i '' "s/edition = \"$OLD_EDITION\"/edition = \"$NEW_EDITION\"/g" '{}' \;

# Update all id
find listings -name "Cargo.toml" -exec cargo fix --allow-dirty --edition-idioms --manifest-path {} \;