Merge pull request #2478 from csmoe/explict-version-info

Explict version info
This commit is contained in:
Nick Cameron 2018-02-21 20:41:20 +13:00 committed by GitHub
commit de2d53dfa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View File

@ -26,12 +26,20 @@ fn main() {
// Try to get hash and date of the last commit on a best effort basis. If anything goes wrong
// (git not installed or if this is not a git repository) just return an empty string.
fn commit_info() -> String {
match (commit_hash(), commit_date()) {
(Some(hash), Some(date)) => format!(" ({} {})", hash.trim_right(), date),
match (channel(), commit_hash(), commit_date()) {
(channel, Some(hash), Some(date)) => format!("{} ({} {})", channel, hash.trim_right(), date),
_ => String::new(),
}
}
fn channel() -> String {
if let Ok(channel) = env::var("CFG_RELEASE_CHANNEL") {
channel
} else {
"nightly".to_owned()
}
}
fn commit_hash() -> Option<String> {
Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])

View File

@ -386,11 +386,14 @@ fn print_usage_to_stdout(opts: &Options, reason: &str) {
}
fn print_version() {
println!(
"{}-nightly{}",
let version_info = format!(
"{}{}{}",
option_env!("CARGO_PKG_VERSION").unwrap_or("unknown"),
"-",
include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt"))
)
);
println!("rustfmt {}", version_info);
}
fn determine_operation(matches: &Matches) -> FmtResult<Operation> {