Skip to content

Commit

Permalink
Merge pull request #2487 from jyn514/custom-component
Browse files Browse the repository at this point in the history
Give a better error message when a component isn't installed for a custom toolchain
  • Loading branch information
kinnison authored Sep 16, 2020
2 parents 1e0af0b + 39c23c5 commit 5d79406
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#![allow(clippy::large_enum_variant)]
#![allow(deprecated)] // because of `Error::description` deprecation in `error_chain`

use crate::component_for_bin;
use crate::dist::dist::Profile;
use crate::dist::manifest::{Component, Manifest};
use crate::dist::temp;
use crate::{component_for_bin, Toolchain};
use error_chain::error_chain;
use std::ffi::OsString;
use std::io::{self, Write};
Expand Down Expand Up @@ -444,6 +444,10 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: &
}

fn install_msg(bin: &str, toolchain: &str, is_default: bool) -> String {
if Toolchain::is_custom_name(toolchain) {
return "\nnote: this is a custom toolchain, which cannot use `rustup component add`\n\
help: if you built this toolchain from source, and used `rustup component link`, then you may be able to build the component with `x.py`".to_string();
}
match component_for_bin(bin) {
Some(c) => format!("\nTo install, run `rustup component add {}{}`", c, {
if is_default {
Expand Down
7 changes: 6 additions & 1 deletion src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,13 @@ impl<'a> Toolchain<'a> {

// Custom only
pub fn is_custom(&self) -> bool {
ToolchainDesc::from_str(&self.name).is_err()
Toolchain::is_custom_name(&self.name)
}

pub(crate) fn is_custom_name(name: &str) -> bool {
ToolchainDesc::from_str(name).is_err()
}

// Distributable only
pub fn is_tracking(&self) -> bool {
ToolchainDesc::from_str(&self.name)
Expand Down
8 changes: 2 additions & 6 deletions tests/cli-misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,10 @@ fn rustup_failed_path_search_toolchain() {
expect_ok(config, &["rustup", "default", "custom-2"]);

let broken = &["rustup", "run", "custom-1", "cargo-miri"];
expect_err(
config,
broken,
"rustup component add miri --toolchain custom-1",
);
expect_err(config, broken, "cannot use `rustup component add`");

let broken = &["rustup", "run", "custom-2", "cargo-miri"];
expect_err(config, broken, "rustup component add miri");
expect_err(config, broken, "cannot use `rustup component add`");

// Hardlink will be automatically cleaned up by test setup code
});
Expand Down

0 comments on commit 5d79406

Please sign in to comment.