]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/channel.rs
bump nightly to 1.37.0
[rust.git] / src / bootstrap / channel.rs
1 //! Build configuration for Rust's release channels.
2 //!
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.
7
8 use std::path::Path;
9 use std::process::Command;
10
11 use build_helper::output;
12
13 use crate::Build;
14
15 // The version number
16 pub const CFG_RELEASE_NUM: &str = "1.37.0";
17
18 pub struct GitInfo {
19     inner: Option<Info>,
20 }
21
22 struct Info {
23     commit_date: String,
24     sha: String,
25     short_sha: String,
26 }
27
28 impl GitInfo {
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 }
33         }
34
35         // Make sure git commands work
36         match Command::new("git")
37             .arg("rev-parse")
38             .current_dir(dir)
39             .output()
40         {
41             Ok(ref out) if out.status.success() => {}
42             _ => return GitInfo { inner: None },
43         }
44
45         // Ok, let's scrape some info
46         let ver_date = output(Command::new("git").current_dir(dir)
47                                       .arg("log").arg("-1")
48                                       .arg("--date=short")
49                                       .arg("--pretty=format:%cd"));
50         let ver_hash = output(Command::new("git").current_dir(dir)
51                                       .arg("rev-parse").arg("HEAD"));
52         let short_ver_hash = output(Command::new("git")
53                                             .current_dir(dir)
54                                             .arg("rev-parse")
55                                             .arg("--short=9")
56                                             .arg("HEAD"));
57         GitInfo {
58             inner: Some(Info {
59                 commit_date: ver_date.trim().to_string(),
60                 sha: ver_hash.trim().to_string(),
61                 short_sha: short_ver_hash.trim().to_string(),
62             }),
63         }
64     }
65
66     pub fn sha(&self) -> Option<&str> {
67         self.inner.as_ref().map(|s| &s.sha[..])
68     }
69
70     pub fn sha_short(&self) -> Option<&str> {
71         self.inner.as_ref().map(|s| &s.short_sha[..])
72     }
73
74     pub fn commit_date(&self) -> Option<&str> {
75         self.inner.as_ref().map(|s| &s.commit_date[..])
76     }
77
78     pub fn version(&self, build: &Build, num: &str) -> String {
79         let mut version = build.release(num);
80         if let Some(ref inner) = self.inner {
81             version.push_str(" (");
82             version.push_str(&inner.short_sha);
83             version.push_str(" ");
84             version.push_str(&inner.commit_date);
85             version.push_str(")");
86         }
87         version
88     }
89
90     pub fn is_git(&self) -> bool {
91         self.inner.is_some()
92     }
93 }