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;
16 pub const CFG_RELEASE_NUM: &str = "1.42.0";
29 pub fn new(ignore_git: bool, dir: &Path) -> GitInfo {
30 // See if this even begins to look like a git dir
31 if ignore_git || !dir.join(".git").exists() {
32 return GitInfo { inner: None };
35 // Make sure git commands work
36 match Command::new("git").arg("rev-parse").current_dir(dir).output() {
37 Ok(ref out) if out.status.success() => {}
38 _ => return GitInfo { inner: None },
41 // Ok, let's scrape some info
42 let ver_date = output(
48 .arg("--pretty=format:%cd"),
50 let ver_hash = output(Command::new("git").current_dir(dir).arg("rev-parse").arg("HEAD"));
51 let short_ver_hash = output(
52 Command::new("git").current_dir(dir).arg("rev-parse").arg("--short=9").arg("HEAD"),
56 commit_date: ver_date.trim().to_string(),
57 sha: ver_hash.trim().to_string(),
58 short_sha: short_ver_hash.trim().to_string(),
63 pub fn sha(&self) -> Option<&str> {
64 self.inner.as_ref().map(|s| &s.sha[..])
67 pub fn sha_short(&self) -> Option<&str> {
68 self.inner.as_ref().map(|s| &s.short_sha[..])
71 pub fn commit_date(&self) -> Option<&str> {
72 self.inner.as_ref().map(|s| &s.commit_date[..])
75 pub fn version(&self, build: &Build, num: &str) -> String {
76 let mut version = build.release(num);
77 if let Some(ref inner) = self.inner {
78 version.push_str(" (");
79 version.push_str(&inner.short_sha);
80 version.push_str(" ");
81 version.push_str(&inner.commit_date);
82 version.push_str(")");
87 pub fn is_git(&self) -> bool {