mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-28 07:30:57 +00:00
Add cargo dev sync
subcommand
Currently this only provides the feature to auto-update the nightly version in the `rust-toolchain` file and the `clippy_utils/README.md` file. The actual sync to and from the Rust repo will be added with the move to Josh.
This commit is contained in:
parent
9c8d9504ce
commit
66715532ab
5 changed files with 56 additions and 1 deletions
|
@ -6,6 +6,7 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
aho-corasick = "1.0"
|
aho-corasick = "1.0"
|
||||||
|
chrono = { version = "0.4.38", default-features = false, features = ["clock"] }
|
||||||
clap = { version = "4.4", features = ["derive"] }
|
clap = { version = "4.4", features = ["derive"] }
|
||||||
indoc = "1.0"
|
indoc = "1.0"
|
||||||
itertools = "0.12"
|
itertools = "0.12"
|
||||||
|
|
|
@ -20,5 +20,6 @@ pub mod lint;
|
||||||
pub mod new_lint;
|
pub mod new_lint;
|
||||||
pub mod serve;
|
pub mod serve;
|
||||||
pub mod setup;
|
pub mod setup;
|
||||||
|
pub mod sync;
|
||||||
pub mod update_lints;
|
pub mod update_lints;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#![warn(rust_2018_idioms, unused_lifetimes)]
|
#![warn(rust_2018_idioms, unused_lifetimes)]
|
||||||
|
|
||||||
use clap::{Args, Parser, Subcommand};
|
use clap::{Args, Parser, Subcommand};
|
||||||
use clippy_dev::{dogfood, fmt, lint, new_lint, serve, setup, update_lints, utils};
|
use clippy_dev::{dogfood, fmt, lint, new_lint, serve, setup, sync, update_lints, utils};
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -75,6 +75,9 @@ fn main() {
|
||||||
uplift,
|
uplift,
|
||||||
} => update_lints::rename(&old_name, new_name.as_ref().unwrap_or(&old_name), uplift),
|
} => update_lints::rename(&old_name, new_name.as_ref().unwrap_or(&old_name), uplift),
|
||||||
DevCommand::Deprecate { name, reason } => update_lints::deprecate(&name, &reason),
|
DevCommand::Deprecate { name, reason } => update_lints::deprecate(&name, &reason),
|
||||||
|
DevCommand::Sync(SyncCommand { subcommand }) => match subcommand {
|
||||||
|
SyncSubcommand::UpdateNightly => sync::update_nightly(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,6 +228,8 @@ enum DevCommand {
|
||||||
/// The reason for deprecation
|
/// The reason for deprecation
|
||||||
reason: String,
|
reason: String,
|
||||||
},
|
},
|
||||||
|
/// Sync between the rust repo and the Clippy repo
|
||||||
|
Sync(SyncCommand),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
|
@ -291,3 +296,16 @@ enum RemoveSubcommand {
|
||||||
/// Remove the tasks added with 'cargo dev setup vscode-tasks'
|
/// Remove the tasks added with 'cargo dev setup vscode-tasks'
|
||||||
VscodeTasks,
|
VscodeTasks,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Args)]
|
||||||
|
struct SyncCommand {
|
||||||
|
#[command(subcommand)]
|
||||||
|
subcommand: SyncSubcommand,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand)]
|
||||||
|
enum SyncSubcommand {
|
||||||
|
#[command(name = "update_nightly")]
|
||||||
|
/// Update nightly version in rust-toolchain and `clippy_utils`
|
||||||
|
UpdateNightly,
|
||||||
|
}
|
||||||
|
|
33
clippy_dev/src/sync.rs
Normal file
33
clippy_dev/src/sync.rs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
use std::fmt::Write;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use chrono::offset::Utc;
|
||||||
|
|
||||||
|
use crate::utils::{UpdateMode, replace_region_in_file};
|
||||||
|
|
||||||
|
pub fn update_nightly() {
|
||||||
|
// Update rust-toolchain nightly version
|
||||||
|
let date = Utc::now().format("%Y-%m-%d").to_string();
|
||||||
|
replace_region_in_file(
|
||||||
|
UpdateMode::Change,
|
||||||
|
Path::new("rust-toolchain"),
|
||||||
|
"# begin autogenerated nightly\n",
|
||||||
|
"# end autogenerated nightly",
|
||||||
|
|res| {
|
||||||
|
writeln!(res, "channel = \"nightly-{date}\"").unwrap();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Update clippy_utils nightly version
|
||||||
|
replace_region_in_file(
|
||||||
|
UpdateMode::Change,
|
||||||
|
Path::new("clippy_utils/README.md"),
|
||||||
|
"<!-- begin autogenerated nightly -->\n",
|
||||||
|
"<!-- end autogenerated nightly -->",
|
||||||
|
|res| {
|
||||||
|
writeln!(res, "```").unwrap();
|
||||||
|
writeln!(res, "nightly-{date}").unwrap();
|
||||||
|
writeln!(res, "```").unwrap();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
|
# begin autogenerated nightly
|
||||||
channel = "nightly-2024-11-14"
|
channel = "nightly-2024-11-14"
|
||||||
|
# end autogenerated nightly
|
||||||
components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]
|
components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]
|
||||||
profile = "minimal"
|
profile = "minimal"
|
||||||
|
|
Loading…
Reference in a new issue