Skip to content

Commit

Permalink
warn toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
frbimo committed Oct 22, 2020
1 parent 1863453 commit 64abf6f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ impl<'a> InstallMethod<'a> {
));
}

match self {
InstallMethod::Dist { desc, .. } => {
let host_arch = dist::TargetTriple::from_host_or_build();
let target_triple = desc.target.clone();
if host_arch.ne(&target_triple) {
(toolchain.cfg().notify_handler)(RootNotification::UnmatchToolchain(
&toolchain.name(),
));
(toolchain.cfg().notify_handler)(RootNotification::SuggestTarget(
&target_triple.to_string(),
));
}
}
_ => (),
};

let status = match (updated, previous_version) {
(true, None) => UpdateStatus::Installed,
(true, Some(v)) => UpdateStatus::Updated(v),
Expand Down
9 changes: 8 additions & 1 deletion src/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub enum Notification<'a> {
UpgradeRemovesToolchains,
MissingFileDuringSelfUninstall(PathBuf),
PlainVerboseMessage(&'a str),
UnmatchToolchain(&'a str),
SuggestTarget(&'a str),
}

impl<'a> From<crate::dist::Notification<'a>> for Notification<'a> {
Expand Down Expand Up @@ -77,7 +79,10 @@ impl<'a> Notification<'a> {
| UpgradingMetadata(_, _)
| MetadataUpgradeNotNeeded(_) => NotificationLevel::Info,
NonFatalError(_) => NotificationLevel::Error,
UpgradeRemovesToolchains | MissingFileDuringSelfUninstall(_) => NotificationLevel::Warn,
UpgradeRemovesToolchains
| MissingFileDuringSelfUninstall(_)
| UnmatchToolchain(_)
| SuggestTarget(_) => NotificationLevel::Warn,
}
}
}
Expand Down Expand Up @@ -130,6 +135,8 @@ impl<'a> Display for Notification<'a> {
p.display()
),
PlainVerboseMessage(r) => write!(f, "{}", r),
UnmatchToolchain(name) => write!(f, "toolchain '{}' may not be able to run on this system.", name),
SuggestTarget(t)=>write!(f,"If you meant to build software to target that platform, perhaps try `rustup target add {}` instead?",t)
}
}
}
22 changes: 22 additions & 0 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1940,3 +1940,25 @@ fn check_host_goes_away() {
);
})
}

#[test]
fn warn_on_unmatch_build() {
clitools::setup(Scenario::MultiHost, &|config| {
let arch = clitools::MULTI_ARCH1;
expect_stderr_ok(
config,
&[
"rustup",
"toolchain",
"install",
&format!("nightly-{}", arch),
"--no-self-update",
],
&format!(
r"warning: toolchain 'nightly-{0}' may not be able to run on this system.
warning: If you meant to build software to target that platform, perhaps try `rustup target add {0}` instead?",
arch,
),
);
});
}

0 comments on commit 64abf6f

Please sign in to comment.