Skip to content

Commit 51bb655

Browse files
committed
Josh preparations
1 parent 537ab6c commit 51bb655

File tree

13 files changed

+390
-9
lines changed

13 files changed

+390
-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

+62-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,15 @@ 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::UpdateToolchain => sync::update_toolchain(),
80+
SyncSubcommand::Pull { hash } => sync::rustc_pull(hash),
81+
SyncSubcommand::Push { repo_path, user } => sync::rustc_push(repo_path, &user),
82+
},
83+
DevCommand::Release(ReleaseCommand { subcommand }) => match subcommand {
84+
ReleaseSubcommand::UpdateVersion => release::update_version(),
85+
ReleaseSubcommand::Commit { branch } => release::rustc_clippy_commit(branch),
86+
},
7887
}
7988
}
8089

@@ -225,6 +234,10 @@ enum DevCommand {
225234
/// The reason for deprecation
226235
reason: Option<String>,
227236
},
237+
/// Sync between the rust repo and the Clippy repo
238+
Sync(SyncCommand),
239+
/// Manage Clippy releases
240+
Release(ReleaseCommand),
228241
}
229242

230243
#[derive(Args)]
@@ -291,3 +304,51 @@ enum RemoveSubcommand {
291304
/// Remove the tasks added with 'cargo dev setup vscode-tasks'
292305
VscodeTasks,
293306
}
307+
308+
#[derive(Args)]
309+
struct SyncCommand {
310+
#[command(subcommand)]
311+
subcommand: SyncSubcommand,
312+
}
313+
314+
#[derive(Subcommand)]
315+
enum SyncSubcommand {
316+
#[command(name = "update_toolchain")]
317+
/// Update nightly toolchain in rust-toolchain file
318+
UpdateToolchain,
319+
/// Pull changes from rustc
320+
Pull {
321+
#[arg(long)]
322+
/// The Rust hash of the commit to pull from
323+
///
324+
/// This should only be necessary, if there were breaking changes to `clippy_dev` itself,
325+
/// i.e. breaking changes to `rustc_lexer`.
326+
hash: Option<String>,
327+
},
328+
/// Push changes to rustc
329+
Push {
330+
/// The path to a rustc repo that will be used for pushing changes
331+
repo_path: String,
332+
#[arg(long)]
333+
/// The GitHub username to use for pushing changes
334+
user: String,
335+
},
336+
}
337+
338+
#[derive(Args)]
339+
struct ReleaseCommand {
340+
#[command(subcommand)]
341+
subcommand: ReleaseSubcommand,
342+
}
343+
344+
#[derive(Subcommand)]
345+
enum ReleaseSubcommand {
346+
#[command(name = "update_version")]
347+
/// Update the version in the Cargo.toml files
348+
UpdateVersion,
349+
/// Print the Clippy commit in the rustc repo for the specified branch
350+
Commit {
351+
/// For which branch to print the commit
352+
branch: release::Branch,
353+
},
354+
}

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

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use clap::ValueEnum;
2+
3+
use crate::new_lint::clippy_version;
4+
use crate::update_lints::{replace_region_in_file, UpdateMode};
5+
6+
use std::fmt::{Display, Write};
7+
use std::path::Path;
8+
9+
const CARGO_TOML_FILES: [&str; 5] = [
10+
"clippy_config/Cargo.toml",
11+
"clippy_lints/Cargo.toml",
12+
"clippy_utils/Cargo.toml",
13+
"declare_clippy_lint/Cargo.toml",
14+
"Cargo.toml",
15+
];
16+
17+
pub fn update_version() {
18+
let (minor, mut patch) = clippy_version();
19+
patch += 1;
20+
for file in &CARGO_TOML_FILES {
21+
replace_region_in_file(
22+
UpdateMode::Change,
23+
Path::new(file),
24+
"# begin autogenerated version\n",
25+
"# end autogenerated version",
26+
|res| {
27+
writeln!(res, "version = \"0.{minor}.{patch}\"").unwrap();
28+
},
29+
);
30+
}
31+
}
32+
33+
#[derive(ValueEnum, Copy, Clone)]
34+
pub enum Branch {
35+
Stable,
36+
Beta,
37+
Master,
38+
}
39+
40+
impl Display for Branch {
41+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42+
match self {
43+
Branch::Stable => write!(f, "stable"),
44+
Branch::Beta => write!(f, "beta"),
45+
Branch::Master => write!(f, "master"),
46+
}
47+
}
48+
}
49+
50+
pub fn rustc_clippy_commit(toolchain: Branch) {
51+
todo!("{toolchain}");
52+
}

0 commit comments

Comments
 (0)