Skip to content

Commit bf327eb

Browse files
committed
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.
1 parent 8652a93 commit bf327eb

File tree

9 files changed

+116
-1
lines changed

9 files changed

+116
-1
lines changed

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[package]
22
name = "clippy"
3+
# begin autogenerated version
34
version = "0.1.80"
5+
# end autogenerated version
46
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
57
repository = "https://github.com/rust-lang/rust-clippy"
68
readme = "README.md"

clippy_config/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[package]
22
name = "clippy_config"
3+
# begin autogenerated version
34
version = "0.1.80"
5+
# end autogenerated version
46
edition = "2021"
57

68
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

clippy_dev/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub mod dogfood;
2020
pub mod fmt;
2121
pub mod lint;
2222
pub mod new_lint;
23+
pub mod release;
2324
pub mod serve;
2425
pub mod setup;
2526
pub mod sync;

clippy_dev/src/main.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![warn(rust_2018_idioms, unused_lifetimes)]
44

55
use clap::{Args, Parser, Subcommand};
6-
use clippy_dev::{dogfood, fmt, lint, new_lint, serve, setup, sync, update_lints, utils};
6+
use clippy_dev::{dogfood, fmt, lint, new_lint, release, serve, setup, sync, update_lints, utils};
77
use std::convert::Infallible;
88

99
fn main() {
@@ -84,6 +84,10 @@ fn main() {
8484
force,
8585
} => sync::rustc_push(repo_path, &user, &branch, force),
8686
},
87+
DevCommand::Release(ReleaseCommand { subcommand }) => match subcommand {
88+
ReleaseSubcommand::BumpVersion => release::bump_version(),
89+
ReleaseSubcommand::Commit { repo_path, branch } => release::rustc_clippy_commit(repo_path, branch),
90+
},
8791
}
8892
}
8993

@@ -236,6 +240,8 @@ enum DevCommand {
236240
},
237241
/// Sync between the rust repo and the Clippy repo
238242
Sync(SyncCommand),
243+
/// Manage Clippy releases
244+
Release(ReleaseCommand),
239245
}
240246

241247
#[derive(Args)]
@@ -330,3 +336,23 @@ enum SyncSubcommand {
330336
force: bool,
331337
},
332338
}
339+
340+
#[derive(Args)]
341+
struct ReleaseCommand {
342+
#[command(subcommand)]
343+
subcommand: ReleaseSubcommand,
344+
}
345+
346+
#[derive(Subcommand)]
347+
enum ReleaseSubcommand {
348+
#[command(name = "bump_version")]
349+
/// Bump the version in the Cargo.toml files
350+
BumpVersion,
351+
/// Print the Clippy commit in the rustc repo for the specified branch
352+
Commit {
353+
/// The path to a rustc repo to look for the commit
354+
repo_path: String,
355+
/// For which branch to print the commit
356+
branch: release::Branch,
357+
},
358+
}

clippy_dev/src/release.rs

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use std::fmt::{Display, Write};
2+
use std::path::Path;
3+
4+
use crate::sync::PUSH_PR_DESCRIPTION;
5+
use crate::utils::{clippy_version, replace_region_in_file, UpdateMode};
6+
7+
use clap::ValueEnum;
8+
use xshell::{cmd, Shell};
9+
10+
const CARGO_TOML_FILES: [&str; 5] = [
11+
"clippy_config/Cargo.toml",
12+
"clippy_lints/Cargo.toml",
13+
"clippy_utils/Cargo.toml",
14+
"declare_clippy_lint/Cargo.toml",
15+
"Cargo.toml",
16+
];
17+
18+
pub fn bump_version() {
19+
let (minor, mut patch) = clippy_version();
20+
patch += 1;
21+
for file in &CARGO_TOML_FILES {
22+
replace_region_in_file(
23+
UpdateMode::Change,
24+
Path::new(file),
25+
"# begin autogenerated version\n",
26+
"# end autogenerated version",
27+
|res| {
28+
writeln!(res, "version = \"0.{minor}.{patch}\"").unwrap();
29+
},
30+
);
31+
}
32+
}
33+
34+
#[derive(ValueEnum, Copy, Clone)]
35+
pub enum Branch {
36+
Stable,
37+
Beta,
38+
Master,
39+
}
40+
41+
impl Display for Branch {
42+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43+
match self {
44+
Branch::Stable => write!(f, "stable"),
45+
Branch::Beta => write!(f, "beta"),
46+
Branch::Master => write!(f, "master"),
47+
}
48+
}
49+
}
50+
51+
pub fn rustc_clippy_commit(rustc_path: String, branch: Branch) {
52+
let sh = Shell::new().expect("failed to create shell");
53+
sh.change_dir(rustc_path);
54+
55+
let base = branch.to_string();
56+
cmd!(sh, "git fetch https://github.com/rust-lang/rust {base}")
57+
.run()
58+
.expect("failed to fetch base commit");
59+
let last_rustup_commit = cmd!(
60+
sh,
61+
"git log -1 --merges --grep=\"{PUSH_PR_DESCRIPTION}\" FETCH_HEAD -- src/tools/clippy"
62+
)
63+
.read()
64+
.expect("failed to run git log");
65+
66+
let commit = last_rustup_commit
67+
.lines()
68+
.find(|c| c.contains("Sync from Clippy commit:"))
69+
.expect("no commit found")
70+
.trim()
71+
.rsplit_once('@')
72+
.expect("no commit hash found")
73+
.1;
74+
75+
println!("{commit}");
76+
}

clippy_lints/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[package]
22
name = "clippy_lints"
3+
# begin autogenerated version
34
version = "0.1.80"
5+
# end autogenerated version
46
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
57
repository = "https://github.com/rust-lang/rust-clippy"
68
readme = "README.md"

clippy_utils/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[package]
22
name = "clippy_utils"
3+
# begin autogenerated version
34
version = "0.1.80"
5+
# end autogenerated version
46
edition = "2021"
57
publish = false
68

declare_clippy_lint/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[package]
22
name = "declare_clippy_lint"
3+
# begin autogenerated version
34
version = "0.1.80"
5+
# end autogenerated version
46
edition = "2021"
57
publish = false
68

rust-toolchain

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
[toolchain]
2+
# begin autogenerated version
23
channel = "nightly-2024-05-02"
4+
# end autogenerated version
35
components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]

0 commit comments

Comments
 (0)