Skip to content

Commit 058ae80

Browse files
committed
Add cargo dev setup toolchain --standalone
1 parent a8b1782 commit 058ae80

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

clippy_dev/src/main.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ fn main() {
5353
setup::git_hook::install_hook(force_override);
5454
}
5555
},
56-
SetupSubcommand::Toolchain { force, release, name } => setup::toolchain::create(force, release, &name),
56+
SetupSubcommand::Toolchain {
57+
standalone,
58+
force,
59+
release,
60+
name,
61+
} => setup::toolchain::create(standalone, force, release, &name),
5762
SetupSubcommand::VscodeTasks { remove, force_override } => {
5863
if remove {
5964
setup::vscode::remove_tasks();
@@ -267,14 +272,25 @@ enum SetupSubcommand {
267272
force_override: bool,
268273
},
269274
/// Install a rustup toolchain pointing to the local clippy build
275+
///
276+
/// This creates a toolchain with symlinks pointing at
277+
/// `target/.../{clippy-driver,cargo-clippy}`, rebuilds of the project will be reflected in the
278+
/// created toolchain unless `--standalone` is passed
270279
Toolchain {
280+
#[arg(long, short)]
281+
/// Create a standalone toolchain by copying the clippy binaries instead
282+
/// of symlinking them
283+
///
284+
/// Use this for example to create a toolchain, make a small change and then make another
285+
/// toolchain with a different name in order to easily compare the two
286+
standalone: bool,
271287
#[arg(long, short)]
272288
/// Override an existing toolchain
273289
force: bool,
274290
#[arg(long, short)]
275291
/// Point to --release clippy binary
276292
release: bool,
277-
#[arg(long, default_value = "clippy")]
293+
#[arg(long, short, default_value = "clippy")]
278294
/// Name of the toolchain
279295
name: String,
280296
},

clippy_dev/src/setup/toolchain.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ use std::env::current_dir;
33
use std::ffi::OsStr;
44
use std::fs;
55
use std::path::{Path, PathBuf};
6+
use std::process::Command;
67
use walkdir::WalkDir;
78

9+
use crate::utils::exit_if_err;
10+
811
use super::verify_inside_clippy_dir;
912

10-
pub fn create(force: bool, release: bool, name: &str) {
13+
pub fn create(standalone: bool, force: bool, release: bool, name: &str) {
1114
if !verify_inside_clippy_dir() {
1215
return;
1316
}
@@ -48,14 +51,22 @@ pub fn create(force: bool, release: bool, name: &str) {
4851
}
4952
}
5053

51-
symlink_bin("cargo-clippy", &dest, release);
52-
symlink_bin("clippy-driver", &dest, release);
54+
let status = Command::new("cargo")
55+
.arg("build")
56+
.args(release.then_some("--release"))
57+
.status();
58+
exit_if_err(status);
59+
60+
install_bin("cargo-clippy", &dest, standalone, release);
61+
install_bin("clippy-driver", &dest, standalone, release);
5362

5463
println!("Created toolchain {name}, use it in other projects with e.g. `cargo +{name} clippy`");
55-
println!("Note: This will need to be re-run whenever the Clippy `rust-toolchain` changes");
64+
if !standalone {
65+
println!("Note: This will need to be re-run whenever the Clippy `rust-toolchain` changes");
66+
}
5667
}
5768

58-
fn symlink_bin(bin: &str, dest: &Path, release: bool) {
69+
fn install_bin(bin: &str, dest: &Path, standalone: bool, release: bool) {
5970
#[cfg(windows)]
6071
use std::os::windows::fs::symlink_file as symlink;
6172

@@ -71,5 +82,9 @@ fn symlink_bin(bin: &str, dest: &Path, release: bool) {
7182
let mut dest = dest.to_path_buf();
7283
dest.extend(["bin", &file_name]);
7384

74-
symlink(src, dest).unwrap();
85+
if standalone {
86+
fs::copy(src, dest).unwrap();
87+
} else {
88+
symlink(src, dest).unwrap();
89+
}
7590
}

0 commit comments

Comments
 (0)