Skip to content

Commit

Permalink
Josh preparations
Browse files Browse the repository at this point in the history
  • Loading branch information
flip1995 committed May 3, 2024
1 parent 537ab6c commit 5276923
Show file tree
Hide file tree
Showing 13 changed files with 392 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
@@ -1,6 +1,8 @@
[package]
name = "clippy"
# begin autogenerated version
version = "0.1.80"
# 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"
Expand Down
2 changes: 2 additions & 0 deletions clippy_config/Cargo.toml
@@ -1,6 +1,8 @@
[package]
name = "clippy_config"
# begin autogenerated version
version = "0.1.80"
# end autogenerated version
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
3 changes: 3 additions & 0 deletions clippy_dev/Cargo.toml
Expand Up @@ -6,12 +6,15 @@ edition = "2021"

[dependencies]
aho-corasick = "1.0"
chrono = { version = "0.4.38", default-features = false, features = ["clock"] }
clap = { version = "4.4", features = ["derive"] }
directories = "5"
indoc = "1.0"
itertools = "0.12"
opener = "0.6"
shell-escape = "0.1"
walkdir = "2.3"
xshell = "0.2"

[features]
deny-warnings = []
Expand Down
2 changes: 2 additions & 0 deletions clippy_dev/src/lib.rs
Expand Up @@ -24,8 +24,10 @@ 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;
pub mod update_lints;

#[cfg(not(windows))]
Expand Down
63 changes: 62 additions & 1 deletion clippy_dev/src/main.rs
Expand Up @@ -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, update_lints};
use clippy_dev::{dogfood, fmt, lint, new_lint, release, serve, setup, sync, update_lints};
use std::convert::Infallible;

fn main() {
Expand Down Expand Up @@ -75,6 +75,15 @@ fn main() {
uplift,
} => update_lints::rename(&old_name, new_name.as_ref().unwrap_or(&old_name), uplift),
DevCommand::Deprecate { name, reason } => update_lints::deprecate(&name, reason.as_deref()),
DevCommand::Sync(SyncCommand { subcommand }) => match subcommand {
SyncSubcommand::UpdateToolchain => sync::update_toolchain(),
SyncSubcommand::Pull { hash } => sync::rustc_pull(hash),
SyncSubcommand::Push { repo_path, user } => sync::rustc_push(repo_path, &user),
},
DevCommand::Release(ReleaseCommand { subcommand }) => match subcommand {
ReleaseSubcommand::UpdateVersion => release::update_version(),
ReleaseSubcommand::Commit { branch } => release::rustc_clippy_commit(branch),
},
}
}

Expand Down Expand Up @@ -225,6 +234,10 @@ enum DevCommand {
/// The reason for deprecation
reason: Option<String>,
},
/// Sync between the rust repo and the Clippy repo
Sync(SyncCommand),
/// Manage Clippy releases
Release(ReleaseCommand),
}

#[derive(Args)]
Expand Down Expand Up @@ -291,3 +304,51 @@ enum RemoveSubcommand {
/// Remove the tasks added with 'cargo dev setup vscode-tasks'
VscodeTasks,
}

#[derive(Args)]
struct SyncCommand {
#[command(subcommand)]
subcommand: SyncSubcommand,
}

#[derive(Subcommand)]
enum SyncSubcommand {
#[command(name = "update_toolchain")]
/// Update nightly toolchain in rust-toolchain file
UpdateToolchain,
/// Pull changes from rustc
Pull {
#[arg(long)]
/// The Rust hash of the commit to pull from
///
/// This should only be necessary, if there were breaking changes to `clippy_dev` itself,
/// i.e. breaking changes to `rustc_lexer`.
hash: Option<String>,
},
/// Push changes to rustc
Push {
/// The path to a rustc repo that will be used for pushing changes
repo_path: String,
#[arg(long)]
/// The GitHub username to use for pushing changes
user: String,
},
}

#[derive(Args)]
struct ReleaseCommand {
#[command(subcommand)]
subcommand: ReleaseSubcommand,
}

#[derive(Subcommand)]
enum ReleaseSubcommand {
#[command(name = "update_version")]
/// Update the version in the Cargo.toml files
UpdateVersion,
/// Print the Clippy commit in the rustc repo for the specified branch
Commit {
/// For which branch to print the commit
branch: release::Branch,
},
}
15 changes: 8 additions & 7 deletions clippy_dev/src/new_lint.rs
Expand Up @@ -185,8 +185,8 @@ fn to_camel_case(name: &str) -> String {
.collect()
}

pub(crate) fn get_stabilization_version() -> String {
fn parse_manifest(contents: &str) -> Option<String> {
pub(crate) fn clippy_version() -> (u32, u32) {
fn parse_manifest(contents: &str) -> Option<(u32, u32)> {
let version = contents
.lines()
.filter_map(|l| l.split_once('='))
Expand All @@ -195,16 +195,17 @@ pub(crate) fn get_stabilization_version() -> String {
return None;
};
let (minor, patch) = version.split_once('.')?;
Some(format!(
"{}.{}.0",
minor.parse::<u32>().ok()?,
patch.parse::<u32>().ok()?
))
Some((minor.parse().ok()?, patch.parse().ok()?))
}
let contents = fs::read_to_string("Cargo.toml").expect("Unable to read `Cargo.toml`");
parse_manifest(&contents).expect("Unable to find package version in `Cargo.toml`")
}

pub(crate) fn get_stabilization_version() -> String {
let (minor, patch) = clippy_version();
format!("{minor}.{patch}.0")
}

fn get_test_file_contents(lint_name: &str, msrv: bool) -> String {
let mut test = formatdoc!(
r#"
Expand Down
52 changes: 52 additions & 0 deletions clippy_dev/src/release.rs
@@ -0,0 +1,52 @@
use clap::ValueEnum;

use crate::new_lint::clippy_version;
use crate::update_lints::{replace_region_in_file, UpdateMode};

use std::fmt::{Display, Write};
use std::path::Path;

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 update_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(toolchain: Branch) {
todo!("{toolchain}");
}

0 comments on commit 5276923

Please sign in to comment.