Skip to content

Commit 01d0d40

Browse files
authored
Merge pull request #2264 from virome/component-unavailable-on-toolchain-message
Add error message to indicate that a missing command is not available…
2 parents caed120 + 3a54ee8 commit 01d0d40

File tree

5 files changed

+85
-3
lines changed

5 files changed

+85
-3
lines changed

src/errors.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,14 @@ error_chain! {
308308
description("toolchain does not contain binary")
309309
display("'{}' is not installed for the toolchain '{}'{}", bin, t, install_msg(bin, t, *is_default))
310310
}
311+
BinaryProvidedByUnavailableComponent(component: String, bin: String, toolchain: String) {
312+
description("binary is provided by a component which is not available in current toolchain")
313+
display("the '{}' component which provides the command '{}' is not available for the '{}' toolchain", component, bin, toolchain)
314+
}
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+
}
311319
NeedMetadataUpgrade {
312320
description("rustup's metadata is out of date. run `rustup self upgrade-data`")
313321
}

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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::component_for_bin;
12
use crate::config::Cfg;
23
use crate::dist::dist::TargetTriple;
34
use crate::dist::dist::ToolchainDesc;
@@ -274,6 +275,38 @@ impl<'a> InstalledCommonToolchain<'a> {
274275
.and_then(|s| s.parse().ok())
275276
.unwrap_or(0);
276277
if recursion_count > env_var::RUST_RECURSION_COUNT_MAX - 1 {
278+
let binary_lossy: String = binary.to_string_lossy().into();
279+
if let Ok(distributable) = DistributableToolchain::new(self.0) {
280+
if let (Some(component_name), Ok(component_statuses), Ok(Some(manifest))) = (
281+
component_for_bin(&binary_lossy),
282+
distributable.list_components(),
283+
distributable.get_manifest(),
284+
) {
285+
let component_status = component_statuses
286+
.iter()
287+
.find(|cs| cs.component.short_name(&manifest) == component_name)
288+
.expect(&format!(
289+
"component {} should be in the manifest",
290+
component_name
291+
));
292+
if !component_status.available {
293+
return Err(ErrorKind::BinaryProvidedByUnavailableComponent(
294+
component_status.component.short_name(&manifest),
295+
binary_lossy,
296+
self.0.name.clone(),
297+
)
298+
.into());
299+
}
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+
}
308+
}
309+
}
277310
let defaults = self.0.cfg.get_default()?;
278311
return Err(ErrorKind::BinaryNotFound(
279312
binary.to_string_lossy().into(),

tests/cli-misc.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,30 @@ fn rls_exists_in_toolchain() {
445445
}
446446

447447
#[test]
448-
fn rls_does_not_exist_in_toolchain() {
448+
fn run_rls_when_not_available_in_toolchain() {
449+
clitools::setup(Scenario::UnavailableRls, &|config| {
450+
set_current_dist_date(config, "2015-01-01");
451+
expect_ok(config, &["rustup", "default", "nightly"]);
452+
expect_err(
453+
config,
454+
&["rls", "--version"],
455+
&format!(
456+
"the 'rls' component which provides the command 'rls{}' is not available for the 'nightly-{}' toolchain",
457+
EXE_SUFFIX,
458+
this_host_triple(),
459+
),
460+
);
461+
462+
set_current_dist_date(config, "2015-01-02");
463+
expect_ok(config, &["rustup", "update", "--no-self-update"]);
464+
expect_ok(config, &["rustup", "component", "add", "rls"]);
465+
466+
expect_ok(config, &["rls", "--version"]);
467+
});
468+
}
469+
470+
#[test]
471+
fn run_rls_when_not_installed() {
449472
setup(&|config| {
450473
expect_ok(config, &["rustup", "default", "stable"]);
451474
expect_err(
@@ -460,6 +483,23 @@ fn rls_does_not_exist_in_toolchain() {
460483
});
461484
}
462485

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+
463503
#[test]
464504
fn rename_rls_before() {
465505
clitools::setup(Scenario::ArchivesV2, &|config| {

tests/mock/clitools.rs

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

151152
copy_binary(&build_path, &rustup_path).unwrap();
152153
hard_link(&rustup_path, setup_path).unwrap();
153154
hard_link(&rustup_path, rustc_path).unwrap();
154155
hard_link(&rustup_path, cargo_path).unwrap();
155156
hard_link(&rustup_path, rls_path).unwrap();
157+
hard_link(&rustup_path, rust_lldb_path).unwrap();
156158

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

0 commit comments

Comments
 (0)