Skip to content

Commit 3a54ee8

Browse files
committed
proxies: Make it clear when a binary is not applicable to a given toolchain
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
1 parent 339765b commit 3a54ee8

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ error_chain! {
312312
description("binary is provided by a component which is not available in current toolchain")
313313
display("the '{}' component which provides the command '{}' is not available for the '{}' toolchain", component, bin, toolchain)
314314
}
315+
BinaryNotProvidedByComponent(component: String, bin: String, toolchain: String) {
316+
description("binary should be provided by component but isn't in current toolchain")
317+
display("the '{}' binary, normally provided by the '{}' component, is not applicable to the '{}' toolchain", bin, component, toolchain)
318+
}
315319
NeedMetadataUpgrade {
316320
description("rustup's metadata is out of date. run `rustup self upgrade-data`")
317321
}

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ fn component_for_bin(binary: &str) -> Option<&'static str> {
4141
match binary_prefix {
4242
"rustc" | "rustdoc" => Some("rustc"),
4343
"cargo" => Some("cargo"),
44-
"rust-lldb" => Some("lldb-preview"),
45-
"rust-gdb" => Some("gdb-preview"),
44+
"rust-lldb" | "rust-gdb" => Some("rustc"), // These are not always available
4645
"rls" => Some("rls"),
4746
"cargo-clippy" => Some("clippy"),
4847
"clippy-driver" => Some("clippy"),

src/toolchain.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,14 @@ impl<'a> InstalledCommonToolchain<'a> {
297297
)
298298
.into());
299299
}
300+
if component_status.installed {
301+
return Err(ErrorKind::BinaryNotProvidedByComponent(
302+
component_status.component.short_name(&manifest),
303+
binary_lossy,
304+
self.0.name.clone(),
305+
)
306+
.into());
307+
}
300308
}
301309
}
302310
let defaults = self.0.cfg.get_default()?;

tests/cli-misc.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,23 @@ fn run_rls_when_not_installed() {
483483
});
484484
}
485485

486+
#[test]
487+
fn run_rust_lldb_when_not_in_toolchain() {
488+
clitools::setup(Scenario::UnavailableRls, &|config| {
489+
set_current_dist_date(config, "2015-01-01");
490+
expect_ok(config, &["rustup", "default", "nightly"]);
491+
expect_err(
492+
config,
493+
&["rust-lldb", "--version"],
494+
&format!(
495+
"the 'rust-lldb{}' binary, normally provided by the 'rustc' component, is not applicable to the 'nightly-{}' toolchain",
496+
EXE_SUFFIX,
497+
this_host_triple(),
498+
),
499+
);
500+
});
501+
}
502+
486503
#[test]
487504
fn rename_rls_before() {
488505
clitools::setup(Scenario::ArchivesV2, &|config| {

tests/mock/clitools.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,14 @@ pub fn setup(s: Scenario, f: &dyn Fn(&mut Config)) {
133133
let rustc_path = config.exedir.join(format!("rustc{}", EXE_SUFFIX));
134134
let cargo_path = config.exedir.join(format!("cargo{}", EXE_SUFFIX));
135135
let rls_path = config.exedir.join(format!("rls{}", EXE_SUFFIX));
136+
let rust_lldb_path = config.exedir.join(format!("rust-lldb{}", EXE_SUFFIX));
136137

137138
copy_binary(&build_path, &rustup_path).unwrap();
138139
hard_link(&rustup_path, setup_path).unwrap();
139140
hard_link(&rustup_path, rustc_path).unwrap();
140141
hard_link(&rustup_path, cargo_path).unwrap();
141142
hard_link(&rustup_path, rls_path).unwrap();
143+
hard_link(&rustup_path, rust_lldb_path).unwrap();
142144

143145
// Make sure the host triple matches the build triple. Otherwise testing a 32-bit build of
144146
// rustup on a 64-bit machine will fail, because the tests do not have the host detection

0 commit comments

Comments
 (0)