]>
git.proxmox.com Git - rustc.git/blob - src/bootstrap/channel.rs
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 crate::util
::output
;
15 /// This is not a git repository.
17 /// This is a git repository.
18 /// If the info should be used (`ignore_git` is false), this will be
19 /// `Some`, otherwise it will be `None`.
20 Present(Option
<Info
>),
30 pub fn new(ignore_git
: bool
, dir
: &Path
) -> GitInfo
{
31 // See if this even begins to look like a git dir
32 if !dir
.join(".git").exists() {
33 return GitInfo
::Absent
;
36 // Make sure git commands work
37 match Command
::new("git").arg("rev-parse").current_dir(dir
).output() {
38 Ok(ref out
) if out
.status
.success() => {}
39 _
=> return GitInfo
::Absent
,
42 // If we're ignoring the git info, we don't actually need to collect it, just make sure this
43 // was a git repo in the first place.
45 return GitInfo
::Present(None
);
48 // Ok, let's scrape some info
49 let ver_date
= output(
55 .arg("--pretty=format:%cd"),
57 let ver_hash
= output(Command
::new("git").current_dir(dir
).arg("rev-parse").arg("HEAD"));
58 let short_ver_hash
= output(
59 Command
::new("git").current_dir(dir
).arg("rev-parse").arg("--short=9").arg("HEAD"),
61 GitInfo
::Present(Some(Info
{
62 commit_date
: ver_date
.trim().to_string(),
63 sha
: ver_hash
.trim().to_string(),
64 short_sha
: short_ver_hash
.trim().to_string(),
68 fn info(&self) -> Option
<&Info
> {
70 GitInfo
::Present(info
) => info
.as_ref(),
71 GitInfo
::Absent
=> None
,
75 pub fn sha(&self) -> Option
<&str> {
76 self.info().map(|s
| &s
.sha
[..])
79 pub fn sha_short(&self) -> Option
<&str> {
80 self.info().map(|s
| &s
.short_sha
[..])
83 pub fn commit_date(&self) -> Option
<&str> {
84 self.info().map(|s
| &s
.commit_date
[..])
87 pub fn version(&self, build
: &Build
, num
: &str) -> String
{
88 let mut version
= build
.release(num
);
89 if let Some(ref inner
) = self.info() {
90 version
.push_str(" (");
91 version
.push_str(&inner
.short_sha
);
93 version
.push_str(&inner
.commit_date
);
99 pub fn is_git(&self) -> bool
{
101 GitInfo
::Absent
=> false,
102 GitInfo
::Present(_
) => true,