2015-11-20 00:20:12 +01:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2016-05-03 00:16:15 +02:00
|
|
|
//! Build configuration for Rust's release channels.
|
|
|
|
//!
|
|
|
|
//! Implements the stable/beta/nightly channel distinctions by setting various
|
|
|
|
//! flags like the `unstable_features`, calculating variables like `release` and
|
|
|
|
//! `package_vers`, and otherwise indicating to the compiler what it should
|
|
|
|
//! print out as part of its version information.
|
|
|
|
|
2017-02-16 00:57:06 +01:00
|
|
|
use std::path::Path;
|
2015-11-20 00:20:12 +01:00
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
use build_helper::output;
|
|
|
|
|
2016-07-06 06:58:20 +02:00
|
|
|
use Build;
|
2017-08-03 18:53:56 +02:00
|
|
|
use config::Config;
|
2015-11-20 00:20:12 +01:00
|
|
|
|
2017-01-27 23:48:48 +01:00
|
|
|
// The version number
|
2017-11-26 23:04:40 +01:00
|
|
|
pub const CFG_RELEASE_NUM: &str = "1.24.0";
|
2017-01-27 23:48:48 +01:00
|
|
|
|
|
|
|
// An optional number to put after the label, e.g. '.2' -> '-beta.2'
|
|
|
|
// Be sure to make this starts with a dot to conform to semver pre-release
|
|
|
|
// versions (section 9)
|
2017-06-24 13:42:38 +02:00
|
|
|
pub const CFG_PRERELEASE_VERSION: &str = ".1";
|
2015-11-20 00:20:12 +01:00
|
|
|
|
2017-02-16 00:57:06 +01:00
|
|
|
pub struct GitInfo {
|
|
|
|
inner: Option<Info>,
|
|
|
|
}
|
2017-01-21 02:03:06 +01:00
|
|
|
|
2017-02-16 00:57:06 +01:00
|
|
|
struct Info {
|
|
|
|
commit_date: String,
|
|
|
|
sha: String,
|
|
|
|
short_sha: String,
|
|
|
|
}
|
2015-11-20 00:20:12 +01:00
|
|
|
|
2017-02-16 00:57:06 +01:00
|
|
|
impl GitInfo {
|
2017-08-03 18:53:56 +02:00
|
|
|
pub fn new(config: &Config, dir: &Path) -> GitInfo {
|
2017-03-12 03:46:31 +01:00
|
|
|
// See if this even begins to look like a git dir
|
2017-08-03 18:53:56 +02:00
|
|
|
if config.ignore_git || !dir.join(".git").exists() {
|
2017-02-16 00:57:06 +01:00
|
|
|
return GitInfo { inner: None }
|
|
|
|
}
|
2017-03-12 03:46:31 +01:00
|
|
|
|
|
|
|
// Make sure git commands work
|
|
|
|
let out = Command::new("git")
|
|
|
|
.arg("rev-parse")
|
|
|
|
.current_dir(dir)
|
|
|
|
.output()
|
|
|
|
.expect("failed to spawn git");
|
|
|
|
if !out.status.success() {
|
|
|
|
return GitInfo { inner: None }
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ok, let's scrape some info
|
2017-02-16 00:57:06 +01:00
|
|
|
let ver_date = output(Command::new("git").current_dir(dir)
|
2015-11-20 00:20:12 +01:00
|
|
|
.arg("log").arg("-1")
|
|
|
|
.arg("--date=short")
|
|
|
|
.arg("--pretty=format:%cd"));
|
2017-02-16 00:57:06 +01:00
|
|
|
let ver_hash = output(Command::new("git").current_dir(dir)
|
2015-11-20 00:20:12 +01:00
|
|
|
.arg("rev-parse").arg("HEAD"));
|
|
|
|
let short_ver_hash = output(Command::new("git")
|
2017-02-16 00:57:06 +01:00
|
|
|
.current_dir(dir)
|
2015-11-20 00:20:12 +01:00
|
|
|
.arg("rev-parse")
|
|
|
|
.arg("--short=9")
|
|
|
|
.arg("HEAD"));
|
2017-02-16 00:57:06 +01:00
|
|
|
GitInfo {
|
|
|
|
inner: Some(Info {
|
|
|
|
commit_date: ver_date.trim().to_string(),
|
|
|
|
sha: ver_hash.trim().to_string(),
|
|
|
|
short_sha: short_ver_hash.trim().to_string(),
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sha(&self) -> Option<&str> {
|
|
|
|
self.inner.as_ref().map(|s| &s.sha[..])
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sha_short(&self) -> Option<&str> {
|
|
|
|
self.inner.as_ref().map(|s| &s.short_sha[..])
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn commit_date(&self) -> Option<&str> {
|
|
|
|
self.inner.as_ref().map(|s| &s.commit_date[..])
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn version(&self, build: &Build, num: &str) -> String {
|
|
|
|
let mut version = build.release(num);
|
|
|
|
if let Some(ref inner) = self.inner {
|
|
|
|
version.push_str(" (");
|
|
|
|
version.push_str(&inner.short_sha);
|
|
|
|
version.push_str(" ");
|
|
|
|
version.push_str(&inner.commit_date);
|
|
|
|
version.push_str(")");
|
|
|
|
}
|
2017-06-27 17:51:26 +02:00
|
|
|
version
|
2015-11-20 00:20:12 +01:00
|
|
|
}
|
2017-06-27 21:34:26 +02:00
|
|
|
|
|
|
|
pub fn is_git(&self) -> bool {
|
|
|
|
self.inner.is_some()
|
|
|
|
}
|
2015-11-20 00:20:12 +01:00
|
|
|
}
|