Skip to content

Commit

Permalink
rust-toolchain: Support local toolchain names in the override file
Browse files Browse the repository at this point in the history
The `rust-toolchain` override file was limited to valid toolchain
names.  This commit weakens that slightly to permit *any* string so
long as it's a local toolchain name.  If it's not then it has to
be a valid channelish toolchain name instead.

This fixes rust-lang#1745

Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
  • Loading branch information
kinnison committed Dec 3, 2019
1 parent 4f6ae53 commit 5f6317e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
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

0 comments on commit 5f6317e

Please sign in to comment.