Skip to content

Commit 7335cfc

Browse files
committed
improve the external clippy usage
Signed-off-by: onur-ozkan <[email protected]>
1 parent 4fe847a commit 7335cfc

File tree

4 files changed

+15
-52
lines changed

4 files changed

+15
-52
lines changed

config.example.toml

+2-7
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,10 @@
233233
# Instead of downloading the src/stage0 version of cargo-clippy specified,
234234
# use this cargo-clippy binary instead as the stage0 snapshot cargo-clippy.
235235
#
236-
# Note that this option must be used together with `clippy-driver` below.
236+
# Note that this option should be used together with `rustc` option above,
237+
# otherwise clippy will most likely fail due to toolchain conflict.
237238
#cargo-clippy = "/path/to/cargo-clippy"
238239

239-
# Instead of downloading the src/stage0 version of clippy-driver specified,
240-
# use this clippy-driver binary instead as the stage0 snapshot clippy-driver.
241-
#
242-
# Note that this option must be used together with `cargo-clippy` above.
243-
#clippy-driver = "/path/to/clippy-driver"
244-
245240
# Whether to build documentation by default. If false, rustdoc and
246241
# friends will still be compiled but they will not be used to generate any
247242
# documentation.

src/bootstrap/src/core/build_steps/tool.rs

-29
Original file line numberDiff line numberDiff line change
@@ -1148,32 +1148,3 @@ impl<'a> Builder<'a> {
11481148
cmd
11491149
}
11501150
}
1151-
1152-
pub(crate) fn install_external_stage0_clippy(builder: &Builder<'_>) -> PathBuf {
1153-
if builder.config.dry_run() {
1154-
return PathBuf::default();
1155-
}
1156-
1157-
builder.info("Installing external clippy to stage0 sysroot.");
1158-
1159-
let (Some(external_cargo_clippy), Some(external_clippy_driver)) =
1160-
(&builder.config.external_cargo_clippy, &builder.config.external_clippy_driver)
1161-
else {
1162-
panic!("`build.cargo-clippy` and `build.clippy-driver` must be configured together.");
1163-
};
1164-
1165-
let host = builder.config.build;
1166-
let bindir = builder.out.join(host.triple).join("stage0/bin");
1167-
t!(fs::create_dir_all(&bindir));
1168-
1169-
let cargo_clippy_destination = bindir.join(exe("cargo-clippy", host));
1170-
let _ = fs::remove_file(&cargo_clippy_destination);
1171-
builder.copy_link(external_cargo_clippy, &cargo_clippy_destination);
1172-
1173-
let clippy_driver_destination = bindir.join(exe("clippy-driver", host));
1174-
let _ = fs::remove_file(&clippy_driver_destination);
1175-
builder.copy_link(external_clippy_driver, &clippy_driver_destination);
1176-
1177-
assert!(cargo_clippy_destination.exists());
1178-
cargo_clippy_destination
1179-
}

src/bootstrap/src/core/builder.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1298,12 +1298,11 @@ impl<'a> Builder<'a> {
12981298

12991299
pub fn cargo_clippy_cmd(&self, run_compiler: Compiler) -> BootstrapCommand {
13001300
if run_compiler.stage == 0 {
1301-
let cargo_clippy = if self.config.external_cargo_clippy.is_some() {
1302-
tool::install_external_stage0_clippy(self)
1303-
} else {
1304-
// `ensure(Clippy { stage: 0 })` *builds* clippy with stage0, it doesn't use the beta clippy.
1305-
self.build.config.download_clippy()
1306-
};
1301+
let cargo_clippy = self
1302+
.config
1303+
.initial_cargo_clippy
1304+
.clone()
1305+
.unwrap_or_else(|| self.build.config.download_clippy());
13071306

13081307
let mut cmd = command(cargo_clippy);
13091308
cmd.env("CARGO", &self.initial_cargo);

src/bootstrap/src/core/config/config.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ pub struct Config {
336336
// These are either the stage0 downloaded binaries or the locally installed ones.
337337
pub initial_cargo: PathBuf,
338338
pub initial_rustc: PathBuf,
339+
pub initial_cargo_clippy: Option<PathBuf>,
339340

340-
pub external_cargo_clippy: Option<PathBuf>,
341341
pub external_clippy_driver: Option<PathBuf>,
342342

343343
#[cfg(not(test))]
@@ -830,7 +830,6 @@ define_config! {
830830
rustc: Option<PathBuf> = "rustc",
831831
rustfmt: Option<PathBuf> = "rustfmt",
832832
cargo_clippy: Option<PathBuf> = "cargo-clippy",
833-
clippy_driver: Option<PathBuf> = "clippy-driver",
834833
docs: Option<bool> = "docs",
835834
compiler_docs: Option<bool> = "compiler-docs",
836835
library_docs_private_items: Option<bool> = "library-docs-private-items",
@@ -1426,7 +1425,6 @@ impl Config {
14261425
rustc,
14271426
rustfmt,
14281427
cargo_clippy,
1429-
clippy_driver,
14301428
docs,
14311429
compiler_docs,
14321430
library_docs_private_items,
@@ -1479,6 +1477,12 @@ impl Config {
14791477
config.out = absolute(&config.out).expect("can't make empty path absolute");
14801478
}
14811479

1480+
if cargo_clippy.is_some() && rustc.is_none() {
1481+
println!(
1482+
"WARNING: Using `build.cargo-clippy` without `build.rustc` usually fails due to toolchain conflict."
1483+
);
1484+
}
1485+
14821486
config.initial_rustc = if let Some(rustc) = rustc {
14831487
if !flags.skip_stage0_validation {
14841488
config.check_stage0_version(&rustc, "rustc");
@@ -1509,13 +1513,7 @@ impl Config {
15091513
.join(exe("cargo", config.build))
15101514
};
15111515

1512-
assert_eq!(
1513-
cargo_clippy.is_some(),
1514-
clippy_driver.is_some(),
1515-
"`build.cargo-clippy` and `build.clippy-driver` must be configured together."
1516-
);
1517-
config.external_cargo_clippy = cargo_clippy;
1518-
config.external_clippy_driver = clippy_driver;
1516+
config.initial_cargo_clippy = cargo_clippy;
15191517

15201518
// NOTE: it's important this comes *after* we set `initial_rustc` just above.
15211519
if config.dry_run() {

0 commit comments

Comments
 (0)