-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verify that
rustc
is at least the version from rust-toolchain.toml
Issue: #5452
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const FILENAME: &'static str = "../rust-toolchain.toml"; | ||
const KEY_PATH: &'static str = "toolchain.channel"; | ||
|
||
fn get_expected_version() -> Result<version_check::Version, String> { | ||
let toml = std::fs::read_to_string(FILENAME) | ||
.map_err(|err| format!("{}: {}", FILENAME, err))? | ||
.parse::<toml::Value>() | ||
.map_err(|err| format!("{}: {}", FILENAME, err))?; | ||
let channel = toml | ||
.get("toolchain") | ||
.and_then(|value| value.get("channel")) | ||
.ok_or_else(|| format!("{}: {}: missing key", FILENAME, KEY_PATH))?; | ||
let channel = match channel { | ||
toml::Value::String(string) => string, | ||
value => { | ||
return Err(format!( | ||
"{}: {}: expected string but got {}", | ||
FILENAME, | ||
KEY_PATH, | ||
value.type_str() | ||
)) | ||
} | ||
}; | ||
version_check::Version::parse(&channel).ok_or_else(|| { | ||
format!("{}: {}: expected valid version string got ‘{}’", FILENAME, KEY_PATH, channel) | ||
}) | ||
} | ||
|
||
fn get_current_version() -> Result<version_check::Version, String> { | ||
version_check::Version::read().ok_or_else(|| String::from("rustc: unable to determine version")) | ||
} | ||
|
||
fn run() -> Result<(), String> { | ||
let expected = get_expected_version()?; | ||
let current = get_current_version()?; | ||
|
||
if current >= expected { | ||
Ok(()) | ||
} else { | ||
Err(format!("rust: expected at least version {} but got {}", expected, current)) | ||
} | ||
} | ||
|
||
fn main() { | ||
println!("cargo:rerun-if-changed=../rust-toolchain.toml"); | ||
if let Err(msg) = run() { | ||
eprintln!("{}", msg); | ||
std::process::exit(1); | ||
} | ||
} |