]> git.proxmox.com Git - rustc.git/blob - src/bootstrap/channel.rs
New upstream version 1.31.0~beta.4+dfsg1
[rustc.git] / src / bootstrap / channel.rs
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.
4 //
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.
10
11 //! Build configuration for Rust's release channels.
12 //!
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.
17
18 use std::path::Path;
19 use std::process::Command;
20
21 use build_helper::output;
22
23 use Build;
24 use config::Config;
25
26 // The version number
27 pub const CFG_RELEASE_NUM: &str = "1.31.0";
28
29 pub struct GitInfo {
30 inner: Option<Info>,
31 }
32
33 struct Info {
34 commit_date: String,
35 sha: String,
36 short_sha: String,
37 }
38
39 impl GitInfo {
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 }
44 }
45
46 // Make sure git commands work
47 let out = Command::new("git")
48 .arg("rev-parse")
49 .current_dir(dir)
50 .output()
51 .expect("failed to spawn git");
52 if !out.status.success() {
53 return GitInfo { inner: None }
54 }
55
56 // Ok, let's scrape some info
57 let ver_date = output(Command::new("git").current_dir(dir)
58 .arg("log").arg("-1")
59 .arg("--date=short")
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")
64 .current_dir(dir)
65 .arg("rev-parse")
66 .arg("--short=9")
67 .arg("HEAD"));
68 GitInfo {
69 inner: Some(Info {
70 commit_date: ver_date.trim().to_string(),
71 sha: ver_hash.trim().to_string(),
72 short_sha: short_ver_hash.trim().to_string(),
73 }),
74 }
75 }
76
77 pub fn sha(&self) -> Option<&str> {
78 self.inner.as_ref().map(|s| &s.sha[..])
79 }
80
81 pub fn sha_short(&self) -> Option<&str> {
82 self.inner.as_ref().map(|s| &s.short_sha[..])
83 }
84
85 pub fn commit_date(&self) -> Option<&str> {
86 self.inner.as_ref().map(|s| &s.commit_date[..])
87 }
88
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(")");
97 }
98 version
99 }
100
101 pub fn is_git(&self) -> bool {
102 self.inner.is_some()
103 }
104 }