|
| 1 | +use std::fmt::{Display, Write}; |
| 2 | +use std::path::Path; |
| 3 | + |
| 4 | +use crate::sync::PUSH_PR_DESCRIPTION; |
| 5 | +use crate::utils::{clippy_version, 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=\"{PUSH_PR_DESCRIPTION}\" 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