1 //! Build configuration for Rust's release channels.
3 //! Implements the stable/beta/nightly channel distinctions by setting various
4 //! flags like the `unstable_features`, calculating variables like `release` and
5 //! `package_vers`, and otherwise indicating to the compiler what it should
6 //! print out as part of its version information.
9 use std::process::Command;
11 use build_helper::output;
26 pub fn new(ignore_git: bool, dir: &Path) -> GitInfo {
27 // See if this even begins to look like a git dir
28 if ignore_git || !dir.join(".git").exists() {
29 return GitInfo { inner: None };
32 // Make sure git commands work
33 match Command::new("git").arg("rev-parse").current_dir(dir).output() {
34 Ok(ref out) if out.status.success() => {}
35 _ => return GitInfo { inner: None },
38 // Ok, let's scrape some info
39 let ver_date = output(
45 .arg("--pretty=format:%cd"),
47 let ver_hash = output(Command::new("git").current_dir(dir).arg("rev-parse").arg("HEAD"));
48 let short_ver_hash = output(
49 Command::new("git").current_dir(dir).arg("rev-parse").arg("--short=9").arg("HEAD"),
53 commit_date: ver_date.trim().to_string(),
54 sha: ver_hash.trim().to_string(),
55 short_sha: short_ver_hash.trim().to_string(),
60 pub fn sha(&self) -> Option<&str> {
61 self.inner.as_ref().map(|s| &s.sha[..])
64 pub fn sha_short(&self) -> Option<&str> {
65 self.inner.as_ref().map(|s| &s.short_sha[..])
68 pub fn commit_date(&self) -> Option<&str> {
69 self.inner.as_ref().map(|s| &s.commit_date[..])
72 pub fn version(&self, build: &Build, num: &str) -> String {
73 let mut version = build.release(num);
74 if let Some(ref inner) = self.inner {
75 version.push_str(" (");
76 version.push_str(&inner.short_sha);
77 version.push_str(" ");
78 version.push_str(&inner.commit_date);
79 version.push_str(")");
84 pub fn is_git(&self) -> bool {