summaryrefslogtreecommitdiff
path: root/vendor/autocfg/src/version.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/autocfg/src/version.rs
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/autocfg/src/version.rs')
-rw-r--r--vendor/autocfg/src/version.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/vendor/autocfg/src/version.rs b/vendor/autocfg/src/version.rs
new file mode 100644
index 0000000..378c21e
--- /dev/null
+++ b/vendor/autocfg/src/version.rs
@@ -0,0 +1,60 @@
+use std::path::Path;
+use std::process::Command;
+use std::str;
+
+use super::{error, Error};
+
+/// A version structure for making relative comparisons.
+#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
+pub struct Version {
+ major: usize,
+ minor: usize,
+ patch: usize,
+}
+
+impl Version {
+ /// Creates a `Version` instance for a specific `major.minor.patch` version.
+ pub fn new(major: usize, minor: usize, patch: usize) -> Self {
+ Version {
+ major: major,
+ minor: minor,
+ patch: patch,
+ }
+ }
+
+ pub fn from_rustc(rustc: &Path) -> Result<Self, Error> {
+ // Get rustc's verbose version
+ let output = try!(Command::new(rustc)
+ .args(&["--version", "--verbose"])
+ .output()
+ .map_err(error::from_io));
+ if !output.status.success() {
+ return Err(error::from_str("could not execute rustc"));
+ }
+ let output = try!(str::from_utf8(&output.stdout).map_err(error::from_utf8));
+
+ // Find the release line in the verbose version output.
+ let release = match output.lines().find(|line| line.starts_with("release: ")) {
+ Some(line) => &line["release: ".len()..],
+ None => return Err(error::from_str("could not find rustc release")),
+ };
+
+ // Strip off any extra channel info, e.g. "-beta.N", "-nightly"
+ let version = match release.find('-') {
+ Some(i) => &release[..i],
+ None => release,
+ };
+
+ // Split the version into semver components.
+ let mut iter = version.splitn(3, '.');
+ let major = try!(iter.next().ok_or(error::from_str("missing major version")));
+ let minor = try!(iter.next().ok_or(error::from_str("missing minor version")));
+ let patch = try!(iter.next().ok_or(error::from_str("missing patch version")));
+
+ Ok(Version::new(
+ try!(major.parse().map_err(error::from_num)),
+ try!(minor.parse().map_err(error::from_num)),
+ try!(patch.parse().map_err(error::from_num)),
+ ))
+ }
+}