forked from cross-rs/cross
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
print version information when
-V
or --version
is issued
- Loading branch information
Jorge Aparicio
committed
Dec 26, 2016
1 parent
3b801f3
commit 8de4177
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::env; | ||
use std::error::Error; | ||
use std::fs::File; | ||
use std::io::Write; | ||
use std::path::PathBuf; | ||
use std::process::Command; | ||
|
||
struct Some {} | ||
|
||
impl<E> From<E> for Some | ||
where E: Error | ||
{ | ||
fn from(_: E) -> Some { | ||
Some {} | ||
} | ||
} | ||
|
||
fn main() { | ||
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
|
||
File::create(out_dir.join("commit-info.txt")) | ||
.unwrap() | ||
.write_all(commit_info().as_bytes()) | ||
.unwrap(); | ||
} | ||
|
||
fn commit_info() -> String { | ||
match (commit_hash(), commit_date()) { | ||
(Ok(hash), Ok(date)) => format!(" ({} {})", hash.trim(), date.trim()), | ||
_ => String::new(), | ||
} | ||
} | ||
|
||
fn commit_hash() -> Result<String, Some> { | ||
let output = Command::new("git").args(&["rev-parse", "--short", "HEAD"]) | ||
.output()?; | ||
|
||
if output.status.success() { | ||
Ok(String::from_utf8(output.stdout)?) | ||
} else { | ||
Err(Some {}) | ||
} | ||
} | ||
|
||
fn commit_date() -> Result<String, Some> { | ||
let output = Command::new("git") | ||
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"]) | ||
.output()?; | ||
|
||
if output.status.success() { | ||
Ok(String::from_utf8(output.stdout)?) | ||
} else { | ||
Err(Some {}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters