Skip to content

Commit 306eccd

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 9ad3e7d commit 306eccd

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

clippy_dev/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ fn main() {
9797
},
9898
DevCommand::Release(ReleaseCommand { subcommand }) => match subcommand {
9999
ReleaseSubcommand::BumpVersion => release::bump_version(clippy.version),
100+
ReleaseSubcommand::Commit { repo_path, branch } => release::rustc_clippy_commit(repo_path, branch),
100101
},
101102
}
102103
}
@@ -366,4 +367,11 @@ enum ReleaseSubcommand {
366367
#[command(name = "bump_version")]
367368
/// Bump the version in the Cargo.toml files
368369
BumpVersion,
370+
/// Print the Clippy commit in the rustc repo for the specified branch
371+
Commit {
372+
/// The path to a rustc repo to look for the commit
373+
repo_path: String,
374+
/// For which branch to print the commit
375+
branch: release::Branch,
376+
},
369377
}

clippy_dev/src/release.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
use crate::sync::PUSH_PR_DESCRIPTION;
12
use crate::utils::{FileUpdater, UpdateStatus, Version, parse_cargo_package};
2-
use std::fmt::Write;
3+
4+
use std::fmt::{Display, Write};
5+
6+
use clap::ValueEnum;
7+
use xshell::{Shell, cmd};
38

49
static CARGO_TOML_FILES: &[&str] = &[
510
"clippy_config/Cargo.toml",
@@ -28,3 +33,47 @@ pub fn bump_version(mut version: Version) {
2833
});
2934
}
3035
}
36+
37+
#[derive(ValueEnum, Copy, Clone)]
38+
pub enum Branch {
39+
Stable,
40+
Beta,
41+
Master,
42+
}
43+
44+
impl Display for Branch {
45+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46+
match self {
47+
Branch::Stable => write!(f, "stable"),
48+
Branch::Beta => write!(f, "beta"),
49+
Branch::Master => write!(f, "master"),
50+
}
51+
}
52+
}
53+
54+
pub fn rustc_clippy_commit(rustc_path: String, branch: Branch) {
55+
let sh = Shell::new().expect("failed to create shell");
56+
sh.change_dir(rustc_path);
57+
58+
let base = branch.to_string();
59+
cmd!(sh, "git fetch https://github.com/rust-lang/rust {base}")
60+
.run()
61+
.expect("failed to fetch base commit");
62+
let last_rustup_commit = cmd!(
63+
sh,
64+
"git log -1 --merges --grep=\"{PUSH_PR_DESCRIPTION}\" FETCH_HEAD -- src/tools/clippy"
65+
)
66+
.read()
67+
.expect("failed to run git log");
68+
69+
let commit = last_rustup_commit
70+
.lines()
71+
.find(|c| c.contains("Sync from Clippy commit:"))
72+
.expect("no commit found")
73+
.trim()
74+
.rsplit_once('@')
75+
.expect("no commit hash found")
76+
.1;
77+
78+
println!("{commit}");
79+
}

0 commit comments

Comments
 (0)