From fc1b8212843ab4da09fb584ac6b26523f457f012 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Sat, 4 May 2024 15:23:13 +0200 Subject: [PATCH] Implement release subcommand in clippy_dev This is a QoL improvement for doing releases. The `release bump_version` subcommand increments the version in all relevant `Cargo.toml` files. The `release commit` command will only work with the new Josh syncs. Until then the old way, using `git log` has to be used. --- Cargo.toml | 2 + clippy_config/Cargo.toml | 2 + clippy_dev/src/lib.rs | 1 + clippy_dev/src/main.rs | 28 ++++++++++++- clippy_dev/src/release.rs | 76 ++++++++++++++++++++++++++++++++++ clippy_lints/Cargo.toml | 2 + clippy_utils/Cargo.toml | 2 + declare_clippy_lint/Cargo.toml | 2 + rust-toolchain | 2 + 9 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 clippy_dev/src/release.rs diff --git a/Cargo.toml b/Cargo.toml index 437884990551..c717a0a231f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,8 @@ [package] name = "clippy" +# begin autogenerated version version = "0.1.81" +# end autogenerated version description = "A bunch of helpful lints to avoid common pitfalls in Rust" repository = "https://github.com/rust-lang/rust-clippy" readme = "README.md" diff --git a/clippy_config/Cargo.toml b/clippy_config/Cargo.toml index be0b048ac0c7..5244aa22fdec 100644 --- a/clippy_config/Cargo.toml +++ b/clippy_config/Cargo.toml @@ -1,6 +1,8 @@ [package] name = "clippy_config" +# begin autogenerated version version = "0.1.81" +# end autogenerated version edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index cf8c786d7291..2341ee8f3860 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -19,6 +19,7 @@ pub mod dogfood; pub mod fmt; pub mod lint; pub mod new_lint; +pub mod release; pub mod serve; pub mod setup; pub mod sync; diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs index 7d4a24511941..058c82944b08 100644 --- a/clippy_dev/src/main.rs +++ b/clippy_dev/src/main.rs @@ -3,7 +3,7 @@ #![warn(rust_2018_idioms, unused_lifetimes)] use clap::{Args, Parser, Subcommand}; -use clippy_dev::{dogfood, fmt, lint, new_lint, serve, setup, sync, update_lints, utils}; +use clippy_dev::{dogfood, fmt, lint, new_lint, release, serve, setup, sync, update_lints, utils}; use std::convert::Infallible; fn main() { @@ -84,6 +84,10 @@ fn main() { force, } => sync::rustc_push(repo_path, &user, &branch, force), }, + DevCommand::Release(ReleaseCommand { subcommand }) => match subcommand { + ReleaseSubcommand::BumpVersion => release::bump_version(), + ReleaseSubcommand::Commit { repo_path, branch } => release::rustc_clippy_commit(repo_path, branch), + }, } } @@ -236,6 +240,8 @@ enum DevCommand { }, /// Sync between the rust repo and the Clippy repo Sync(SyncCommand), + /// Manage Clippy releases + Release(ReleaseCommand), } #[derive(Args)] @@ -330,3 +336,23 @@ enum SyncSubcommand { force: bool, }, } + +#[derive(Args)] +struct ReleaseCommand { + #[command(subcommand)] + subcommand: ReleaseSubcommand, +} + +#[derive(Subcommand)] +enum ReleaseSubcommand { + #[command(name = "bump_version")] + /// Bump the version in the Cargo.toml files + BumpVersion, + /// Print the Clippy commit in the rustc repo for the specified branch + Commit { + /// The path to a rustc repo to look for the commit + repo_path: String, + /// For which branch to print the commit + branch: release::Branch, + }, +} diff --git a/clippy_dev/src/release.rs b/clippy_dev/src/release.rs new file mode 100644 index 000000000000..63f8a88bfa7d --- /dev/null +++ b/clippy_dev/src/release.rs @@ -0,0 +1,76 @@ +use std::fmt::{Display, Write}; +use std::path::Path; + +use crate::sync::PUSH_PR_DESCRIPTION; +use crate::utils::{clippy_version, replace_region_in_file, UpdateMode}; + +use clap::ValueEnum; +use xshell::{cmd, Shell}; + +const CARGO_TOML_FILES: [&str; 5] = [ + "clippy_config/Cargo.toml", + "clippy_lints/Cargo.toml", + "clippy_utils/Cargo.toml", + "declare_clippy_lint/Cargo.toml", + "Cargo.toml", +]; + +pub fn bump_version() { + let (minor, mut patch) = clippy_version(); + patch += 1; + for file in &CARGO_TOML_FILES { + replace_region_in_file( + UpdateMode::Change, + Path::new(file), + "# begin autogenerated version\n", + "# end autogenerated version", + |res| { + writeln!(res, "version = \"0.{minor}.{patch}\"").unwrap(); + }, + ); + } +} + +#[derive(ValueEnum, Copy, Clone)] +pub enum Branch { + Stable, + Beta, + Master, +} + +impl Display for Branch { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Branch::Stable => write!(f, "stable"), + Branch::Beta => write!(f, "beta"), + Branch::Master => write!(f, "master"), + } + } +} + +pub fn rustc_clippy_commit(rustc_path: String, branch: Branch) { + let sh = Shell::new().expect("failed to create shell"); + sh.change_dir(rustc_path); + + let base = branch.to_string(); + cmd!(sh, "git fetch https://github.com/rust-lang/rust {base}") + .run() + .expect("failed to fetch base commit"); + let last_rustup_commit = cmd!( + sh, + "git log -1 --merges --grep=\"{PUSH_PR_DESCRIPTION}\" FETCH_HEAD -- src/tools/clippy" + ) + .read() + .expect("failed to run git log"); + + let commit = last_rustup_commit + .lines() + .find(|c| c.contains("Sync from Clippy commit:")) + .expect("no commit found") + .trim() + .rsplit_once('@') + .expect("no commit hash found") + .1; + + println!("{commit}"); +} diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 5708ffba08fd..51b7381cfb46 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -1,6 +1,8 @@ [package] name = "clippy_lints" +# begin autogenerated version version = "0.1.81" +# end autogenerated version description = "A bunch of helpful lints to avoid common pitfalls in Rust" repository = "https://github.com/rust-lang/rust-clippy" readme = "README.md" diff --git a/clippy_utils/Cargo.toml b/clippy_utils/Cargo.toml index 6e53ff3ee6e9..186da716681b 100644 --- a/clippy_utils/Cargo.toml +++ b/clippy_utils/Cargo.toml @@ -1,6 +1,8 @@ [package] name = "clippy_utils" +# begin autogenerated version version = "0.1.81" +# end autogenerated version edition = "2021" publish = false diff --git a/declare_clippy_lint/Cargo.toml b/declare_clippy_lint/Cargo.toml index 86d945c14a58..74b5b4930c73 100644 --- a/declare_clippy_lint/Cargo.toml +++ b/declare_clippy_lint/Cargo.toml @@ -1,6 +1,8 @@ [package] name = "declare_clippy_lint" +# begin autogenerated version version = "0.1.81" +# end autogenerated version edition = "2021" publish = false diff --git a/rust-toolchain b/rust-toolchain index a61c22c59f98..ec1c9168b9a6 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,6 @@ [toolchain] +# begin autogenerated version channel = "nightly-2024-07-11" +# end autogenerated version components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"] profile = "minimal"