Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust-toolchain: Support local toolchain names in the override file #2141

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,18 @@ impl Cfg {
if let Ok(s) = utils::read_file("toolchain file", &toolchain_file) {
if let Some(s) = s.lines().next() {
let toolchain_name = s.trim();
dist::validate_channel_name(&toolchain_name).chain_err(|| {
format!(
"invalid channel name '{}' in '{}'",
toolchain_name,
toolchain_file.display()
)
})?;

let all_toolchains = self.list_toolchains()?;
if !all_toolchains.iter().any(|s| s == toolchain_name) {
// The given name is not resolvable as a toolchain, so
// instead check it's plausible for installation later
dist::validate_channel_name(&toolchain_name).chain_err(|| {
format!(
"invalid channel name '{}' in '{}'",
toolchain_name,
toolchain_file.display()
)
})?;
}
let reason = OverrideReason::ToolchainFile(toolchain_file);
return Ok(Some((toolchain_name.to_string(), reason)));
}
Expand Down
30 changes: 30 additions & 0 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,36 @@ fn bad_file_override() {
});
}

#[test]
fn valid_override_settings() {
setup(&|config| {
let cwd = config.current_dir();
let toolchain_file = cwd.join("rust-toolchain");
expect_ok(config, &["rustup", "default", "nightly"]);
raw::write_file(&toolchain_file, "nightly").unwrap();
expect_ok(config, &["rustc", "--version"]);
raw::write_file(&toolchain_file, for_host!("nightly-{}")).unwrap();
expect_ok(config, &["rustc", "--version"]);
let fullpath = config
.rustupdir
.clone()
.join("toolchains")
.join(for_host!("nightly-{}"));
expect_ok(
config,
&[
"rustup",
"toolchain",
"link",
"system",
&format!("{}", fullpath.display()),
],
);
raw::write_file(&toolchain_file, "system").unwrap();
expect_ok(config, &["rustc", "--version"]);
})
}

#[test]
fn file_override_with_target_info() {
setup(&|config| {
Expand Down