Skip to content

feat: support for parsing beta versions with tags in the toolchain #3858

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

Merged
merged 3 commits into from
Jun 4, 2024
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
22 changes: 21 additions & 1 deletion src/dist/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ impl FromStr for ParsedToolchainDesc {
"beta",
"stable",
// Allow from 1.0.0 through to 9.999.99 with optional patch version
r"\d{1}\.\d{1,3}(?:\.\d{1,2})?",
// and optional beta tag
r"\d{1}\.\d{1,3}(?:\.\d{1,2})?(?:-beta(?:\.\d{1,2})?)?",
]
.join("|")
))
Expand Down Expand Up @@ -1185,6 +1186,25 @@ mod tests {
("1.6", ("1.6.0", None, None)),
("1.7", ("1.7.0", None, None)),
("1.8", ("1.8.0", None, None)),
// channels with beta tags
("0.0.0-beta", ("0.0.0-beta", None, None)),
("0.0.0-beta.1", ("0.0.0-beta.1", None, None)),
(
"0.0.0-beta.1-0000-00-00",
("0.0.0-beta.1", Some("0000-00-00"), None),
),
(
"0.0.0-beta.1-anything",
("0.0.0-beta.1", None, Some("anything")),
),
(
"0.0.0-beta-anything",
("0.0.0-beta", None, Some("anything")),
),
(
"0.0.0-beta.1-0000-00-00-any-other-thing",
("0.0.0-beta.1", Some("0000-00-00"), Some("any-other-thing")),
),
];

for (input, (channel, date, target)) in success_cases {
Expand Down
19 changes: 19 additions & 0 deletions src/test/mock/clitools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pub enum Scenario {
SimpleV1,
/// One date, v2 manifests, MULTI_ARCH1 host
MultiHost,
/// One date, v2 manifests, beta with tag
BetaTag,
/// Two dates, v2 manifests, everything unavailable in second date.
Unavailable,
/// Two dates, v2 manifests, RLS unavailable in first date, restored on second.
Expand Down Expand Up @@ -139,6 +141,7 @@ impl ConstState {
Scenario::ArchivesV2 => RwLock::new(None),
Scenario::ArchivesV2_2015_01_01 => RwLock::new(None),
Scenario::ArchivesV2TwoVersions => RwLock::new(None),
Scenario::BetaTag => RwLock::new(None),
Scenario::Empty => RwLock::new(None),
Scenario::Full => RwLock::new(None),
Scenario::HostGoesMissingBefore => RwLock::new(None),
Expand Down Expand Up @@ -921,6 +924,14 @@ impl Release {
Release::new("beta", version, date, version)
}

fn beta_with_tag(tag: Option<&str>, version: &str, date: &str) -> Self {
let channel = match tag {
Some(tag) => format!("{version}-beta.{tag}"),
None => format!("{version}-beta"),
};
Release::new(&channel, version, date, version)
}

fn with_rls(mut self, status: RlsStatus) -> Self {
self.rls = status;
self
Expand Down Expand Up @@ -1093,6 +1104,13 @@ fn create_mock_dist_server(path: &Path, s: Scenario) {
Release::beta("1.2.0", "2015-01-02").multi_arch(),
Release::stable("1.1.0", "2015-01-02").multi_arch(),
],
Scenario::BetaTag => vec![
Release::beta("1.78.0", "2024-03-19"),
Release::beta_with_tag(None, "1.78.0", "2024-03-19"),
Release::beta("1.79.0", "2024-05-03"),
Release::beta_with_tag(Some("1"), "1.79.0", "2024-04-29"),
Release::beta_with_tag(Some("2"), "1.79.0", "2024-05-03"),
],
Scenario::HostGoesMissingBefore => {
vec![Release::new("nightly", "1.3.0", "2019-12-09", "1")]
}
Expand All @@ -1119,6 +1137,7 @@ fn create_mock_dist_server(path: &Path, s: Scenario) {
| Scenario::ArchivesV2
| Scenario::ArchivesV2_2015_01_01
| Scenario::ArchivesV2TwoVersions
| Scenario::BetaTag
| Scenario::MultiHost
| Scenario::Unavailable
| Scenario::UnavailableRls
Expand Down
12 changes: 12 additions & 0 deletions tests/suite/cli_misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,18 @@ fn install_unavailable_platform() {
});
}

// issue #1329
#[test]
fn install_beta_with_tag() {
clitools::test(Scenario::BetaTag, &|config| {
config.expect_ok(&["rustup", "default", "1.78.0-beta"]);
config.expect_stdout_ok(&["rustc", "--version"], "1.78.0-beta");

config.expect_ok(&["rustup", "default", "1.79.0-beta.2"]);
config.expect_stdout_ok(&["rustc", "--version"], "1.79.0-beta.2");
})
}

#[test]
fn update_nightly_even_with_incompat() {
clitools::test(Scenario::MissingComponent, &|config| {
Expand Down
Loading