Skip to content

Commit de2d53d

Browse files
authored
Merge pull request #2478 from csmoe/explict-version-info
Explict version info
2 parents 33e47dc + e87c2ca commit de2d53d

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

rustfmt-bin/build.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,20 @@ fn main() {
2626
// Try to get hash and date of the last commit on a best effort basis. If anything goes wrong
2727
// (git not installed or if this is not a git repository) just return an empty string.
2828
fn commit_info() -> String {
29-
match (commit_hash(), commit_date()) {
30-
(Some(hash), Some(date)) => format!(" ({} {})", hash.trim_right(), date),
29+
match (channel(), commit_hash(), commit_date()) {
30+
(channel, Some(hash), Some(date)) => format!("{} ({} {})", channel, hash.trim_right(), date),
3131
_ => String::new(),
3232
}
3333
}
3434

35+
fn channel() -> String {
36+
if let Ok(channel) = env::var("CFG_RELEASE_CHANNEL") {
37+
channel
38+
} else {
39+
"nightly".to_owned()
40+
}
41+
}
42+
3543
fn commit_hash() -> Option<String> {
3644
Command::new("git")
3745
.args(&["rev-parse", "--short", "HEAD"])

rustfmt-bin/src/main.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,14 @@ fn print_usage_to_stdout(opts: &Options, reason: &str) {
386386
}
387387

388388
fn print_version() {
389-
println!(
390-
"{}-nightly{}",
389+
let version_info = format!(
390+
"{}{}{}",
391391
option_env!("CARGO_PKG_VERSION").unwrap_or("unknown"),
392+
"-",
392393
include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt"))
393-
)
394+
);
395+
396+
println!("rustfmt {}", version_info);
394397
}
395398

396399
fn determine_operation(matches: &Matches) -> FmtResult<Operation> {

0 commit comments

Comments
 (0)