1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Build configuration for Rust's release channels.
13 //! Implements the stable/beta/nightly channel distinctions by setting various
14 //! flags like the `unstable_features`, calculating variables like `release` and
15 //! `package_vers`, and otherwise indicating to the compiler what it should
16 //! print out as part of its version information.
19 use std::process::Command;
21 use build_helper::output;
27 pub const CFG_RELEASE_NUM: &str = "1.31.0";
40 pub fn new(config: &Config, dir: &Path) -> GitInfo {
41 // See if this even begins to look like a git dir
42 if config.ignore_git || !dir.join(".git").exists() {
43 return GitInfo { inner: None }
46 // Make sure git commands work
47 let out = Command::new("git")
51 .expect("failed to spawn git");
52 if !out.status.success() {
53 return GitInfo { inner: None }
56 // Ok, let's scrape some info
57 let ver_date = output(Command::new("git").current_dir(dir)
60 .arg("--pretty=format:%cd"));
61 let ver_hash = output(Command::new("git").current_dir(dir)
62 .arg("rev-parse").arg("HEAD"));
63 let short_ver_hash = output(Command::new("git")
70 commit_date: ver_date.trim().to_string(),
71 sha: ver_hash.trim().to_string(),
72 short_sha: short_ver_hash.trim().to_string(),
77 pub fn sha(&self) -> Option<&str> {
78 self.inner.as_ref().map(|s| &s.sha[..])
81 pub fn sha_short(&self) -> Option<&str> {
82 self.inner.as_ref().map(|s| &s.short_sha[..])
85 pub fn commit_date(&self) -> Option<&str> {
86 self.inner.as_ref().map(|s| &s.commit_date[..])
89 pub fn version(&self, build: &Build, num: &str) -> String {
90 let mut version = build.release(num);
91 if let Some(ref inner) = self.inner {
92 version.push_str(" (");
93 version.push_str(&inner.short_sha);
94 version.push_str(" ");
95 version.push_str(&inner.commit_date);
96 version.push_str(")");
101 pub fn is_git(&self) -> bool {