Skip to content

Commit 13f01a7

Browse files
committed
Josh preparations
1 parent 537ab6c commit 13f01a7

File tree

13 files changed

+395
-9
lines changed

13 files changed

+395
-9
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/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ edition = "2021"
66

77
[dependencies]
88
aho-corasick = "1.0"
9+
chrono = { version = "0.4.38", default-features = false, features = ["clock"] }
910
clap = { version = "4.4", features = ["derive"] }
11+
directories = "5"
1012
indoc = "1.0"
1113
itertools = "0.12"
1214
opener = "0.6"
1315
shell-escape = "0.1"
1416
walkdir = "2.3"
17+
xshell = "0.2"
1518

1619
[features]
1720
deny-warnings = []

clippy_dev/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ pub mod dogfood;
2424
pub mod fmt;
2525
pub mod lint;
2626
pub mod new_lint;
27+
pub mod release;
2728
pub mod serve;
2829
pub mod setup;
30+
pub mod sync;
2931
pub mod update_lints;
3032

3133
#[cfg(not(windows))]

clippy_dev/src/main.rs

+56-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, update_lints};
6+
use clippy_dev::{dogfood, fmt, lint, new_lint, release, serve, setup, sync, update_lints};
77
use std::convert::Infallible;
88

99
fn main() {
@@ -75,6 +75,14 @@ fn main() {
7575
uplift,
7676
} => update_lints::rename(&old_name, new_name.as_ref().unwrap_or(&old_name), uplift),
7777
DevCommand::Deprecate { name, reason } => update_lints::deprecate(&name, reason.as_deref()),
78+
DevCommand::Sync(SyncCommand { subcommand }) => match subcommand {
79+
SyncSubcommand::Pull => sync::rustc_pull(),
80+
SyncSubcommand::Push { repo_path, user, force } => sync::rustc_push(repo_path, &user, force),
81+
},
82+
DevCommand::Release(ReleaseCommand { subcommand }) => match subcommand {
83+
ReleaseSubcommand::BumpVersion => release::bump_version(),
84+
ReleaseSubcommand::Commit { repo_path, branch } => release::rustc_clippy_commit(repo_path, branch),
85+
},
7886
}
7987
}
8088

@@ -225,6 +233,10 @@ enum DevCommand {
225233
/// The reason for deprecation
226234
reason: Option<String>,
227235
},
236+
/// Sync between the rust repo and the Clippy repo
237+
Sync(SyncCommand),
238+
/// Manage Clippy releases
239+
Release(ReleaseCommand),
228240
}
229241

230242
#[derive(Args)]
@@ -291,3 +303,46 @@ enum RemoveSubcommand {
291303
/// Remove the tasks added with 'cargo dev setup vscode-tasks'
292304
VscodeTasks,
293305
}
306+
307+
#[derive(Args)]
308+
struct SyncCommand {
309+
#[command(subcommand)]
310+
subcommand: SyncSubcommand,
311+
}
312+
313+
#[derive(Subcommand)]
314+
enum SyncSubcommand {
315+
/// Pull changes from rustc and update the toolchain
316+
Pull,
317+
/// Push changes to rustc
318+
Push {
319+
/// The path to a rustc repo that will be used for pushing changes
320+
repo_path: String,
321+
#[arg(long)]
322+
/// The GitHub username to use for pushing changes
323+
user: String,
324+
#[arg(long, short)]
325+
/// Force push changes
326+
force: bool,
327+
},
328+
}
329+
330+
#[derive(Args)]
331+
struct ReleaseCommand {
332+
#[command(subcommand)]
333+
subcommand: ReleaseSubcommand,
334+
}
335+
336+
#[derive(Subcommand)]
337+
enum ReleaseSubcommand {
338+
#[command(name = "bump_version")]
339+
/// Bump the version in the Cargo.toml files
340+
BumpVersion,
341+
/// Print the Clippy commit in the rustc repo for the specified branch
342+
Commit {
343+
/// The path to a rustc repo to look for the commit
344+
repo_path: String,
345+
/// For which branch to print the commit
346+
branch: release::Branch,
347+
},
348+
}

clippy_dev/src/new_lint.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ fn to_camel_case(name: &str) -> String {
185185
.collect()
186186
}
187187

188-
pub(crate) fn get_stabilization_version() -> String {
189-
fn parse_manifest(contents: &str) -> Option<String> {
188+
pub(crate) fn clippy_version() -> (u32, u32) {
189+
fn parse_manifest(contents: &str) -> Option<(u32, u32)> {
190190
let version = contents
191191
.lines()
192192
.filter_map(|l| l.split_once('='))
@@ -195,16 +195,17 @@ pub(crate) fn get_stabilization_version() -> String {
195195
return None;
196196
};
197197
let (minor, patch) = version.split_once('.')?;
198-
Some(format!(
199-
"{}.{}.0",
200-
minor.parse::<u32>().ok()?,
201-
patch.parse::<u32>().ok()?
202-
))
198+
Some((minor.parse().ok()?, patch.parse().ok()?))
203199
}
204200
let contents = fs::read_to_string("Cargo.toml").expect("Unable to read `Cargo.toml`");
205201
parse_manifest(&contents).expect("Unable to find package version in `Cargo.toml`")
206202
}
207203

204+
pub(crate) fn get_stabilization_version() -> String {
205+
let (minor, patch) = clippy_version();
206+
format!("{minor}.{patch}.0")
207+
}
208+
208209
fn get_test_file_contents(lint_name: &str, msrv: bool) -> String {
209210
let mut test = formatdoc!(
210211
r#"

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::new_lint::clippy_version;
5+
use crate::update_lints::{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=\"Sync from Clippy commit:\" 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+
}

0 commit comments

Comments
 (0)