Skip to content

Commit d7266e8

Browse files
committed
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.
1 parent c612049 commit d7266e8

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

Diff for: clippy_dev/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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"] }
1011
indoc = "1.0"
1112
itertools = "0.12"

Diff for: clippy_dev/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ pub mod lint;
2020
pub mod new_lint;
2121
pub mod serve;
2222
pub mod setup;
23+
pub mod sync;
2324
pub mod update_lints;
2425
pub mod utils;

Diff for: clippy_dev/src/main.rs

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

99
fn main() {
@@ -75,6 +75,9 @@ 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),
78+
DevCommand::Sync(SyncCommand { subcommand }) => match subcommand {
79+
SyncSubcommand::UpdateNightly => sync::update_nightly(),
80+
},
7881
}
7982
}
8083

@@ -225,6 +228,8 @@ enum DevCommand {
225228
/// The reason for deprecation
226229
reason: String,
227230
},
231+
/// Sync between the rust repo and the Clippy repo
232+
Sync(SyncCommand),
228233
}
229234

230235
#[derive(Args)]
@@ -291,3 +296,16 @@ enum RemoveSubcommand {
291296
/// Remove the tasks added with 'cargo dev setup vscode-tasks'
292297
VscodeTasks,
293298
}
299+
300+
#[derive(Args)]
301+
struct SyncCommand {
302+
#[command(subcommand)]
303+
subcommand: SyncSubcommand,
304+
}
305+
306+
#[derive(Subcommand)]
307+
enum SyncSubcommand {
308+
#[command(name = "update_nightly")]
309+
/// Update nightly version in rust-toolchain and `clippy_utils`
310+
UpdateNightly,
311+
}

Diff for: clippy_dev/src/sync.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use std::fmt::Write;
2+
use std::path::Path;
3+
4+
use chrono::offset::Utc;
5+
6+
use crate::utils::{UpdateMode, replace_region_in_file};
7+
8+
pub fn update_nightly() {
9+
// Update rust-toolchain nightly version
10+
let date = Utc::now().format("%Y-%m-%d").to_string();
11+
replace_region_in_file(
12+
UpdateMode::Change,
13+
Path::new("rust-toolchain"),
14+
"# begin autogenerated nightly\n",
15+
"# end autogenerated nightly",
16+
|res| {
17+
writeln!(res, "channel = \"nightly-{date}\"").unwrap();
18+
},
19+
);
20+
21+
// Update clippy_utils nightly version
22+
replace_region_in_file(
23+
UpdateMode::Change,
24+
Path::new("clippy_utils/README.md"),
25+
"<!-- begin autogenerated nightly -->\n",
26+
"<!-- end autogenerated nightly -->",
27+
|res| {
28+
writeln!(res, "```").unwrap();
29+
writeln!(res, "nightly-{date}").unwrap();
30+
writeln!(res, "```").unwrap();
31+
},
32+
);
33+
}

0 commit comments

Comments
 (0)