Skip to content

Commit

Permalink
Auto merge of #723 - lqd:unprefixed-shas, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Forbid unprefixed SHAs for toolchains

This PR forbids unprefixed SHAs for toolchain arguments, to avoid crater hanging when they appear.

I'm not sure this is fully valid though: I don't know if SHAs could appear in a `Toolchain`'s name (and `RustwideToolchain::dist()`) without being an error 😓. This commonly happens with `rustup-toolchain-install-master` but I don't know if a similar situation could arise within common crater usage.

CI will surely fail: some of the used dependencies are broken on nightly right now, and clippy emits warnings -- both issues are fixed in #722.

<sub>(this is [for](rust-lang/rust#122230 (comment)) `@oli-obk` and [for](rust-lang/rust#122502 (comment)) `@compiler-errors)</sub>`
  • Loading branch information
bors committed Mar 31, 2024
2 parents f2ebb4c + aedec6d commit f2a10b4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/toolchain.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::prelude::*;
use crate::utils;
use regex::Regex;
use rustwide::Toolchain as RustwideToolchain;
use std::fmt;
use std::str::FromStr;
Expand Down Expand Up @@ -102,6 +103,12 @@ pub enum ToolchainParseError {
InvalidSourceName(String),
#[error("invalid toolchain flag: {0}")]
InvalidFlag(String),
#[error("invalid toolchain SHA: {0} is missing a `try#` or `master#` prefix")]
PrefixMissing(String),
}

lazy_static! {
static ref TOOLCHAIN_SHA_RE: Regex = Regex::new(r"^[a-f0-9]{40}$").unwrap();
}

impl FromStr for Toolchain {
Expand Down Expand Up @@ -130,6 +137,10 @@ impl FromStr for Toolchain {
}
} else if raw_source.is_empty() {
return Err(ToolchainParseError::EmptyName);
} else if TOOLCHAIN_SHA_RE.is_match(raw_source) {
// A common user error is unprefixed SHAs for the `start` or `end` toolchains, check for
// these here.
return Err(ToolchainParseError::PrefixMissing(raw_source.to_string()));
} else {
RustwideToolchain::dist(raw_source)
};
Expand Down Expand Up @@ -348,5 +359,6 @@ mod tests {
assert!(Toolchain::from_str("stable+donotusethisflag=ever").is_err());
assert!(Toolchain::from_str("stable+patch=").is_err());
assert!(Toolchain::from_str("try#1234+target=").is_err());
assert!(Toolchain::from_str("0000000000000000000000000000000000000000").is_err());
}
}

0 comments on commit f2a10b4

Please sign in to comment.