Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display more information for non-release releases
- Loading branch information
Showing
4 changed files
with
75 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,59 @@ | ||
/// The version string isn’t the simplest: we want to show the version, | ||
/// current Git hash, and compilation date when building *debug* versions, but | ||
/// just the version for *release* versions so the builds are reproducible. | ||
/// | ||
/// This script generates the string from the environment variables that Cargo | ||
/// adds (http://doc.crates.io/environment-variables.html) and runs `git` to | ||
/// get the SHA1 hash. It then writes the string into a file, which exa then | ||
/// includes at build-time. | ||
/// | ||
/// - https://stackoverflow.com/q/43753491/3484614 | ||
/// - https://crates.io/crates/vergen | ||
|
||
extern crate datetime; | ||
use std::io::Result as IOResult; | ||
use std::env; | ||
|
||
fn git_hash() -> String { | ||
use std::process::Command; | ||
|
||
String::from_utf8_lossy( | ||
&Command::new("git") | ||
.args(&["rev-parse", "--short", "HEAD"]) | ||
.output().unwrap() | ||
.stdout).trim().to_string() | ||
} | ||
|
||
fn main() { | ||
write_statics().unwrap(); | ||
} | ||
|
||
fn is_development_version() -> bool { | ||
env::var("PROFILE").unwrap() == "debug" | ||
} | ||
|
||
fn cargo_version() -> String { | ||
env::var("CARGO_PKG_VERSION").unwrap() | ||
} | ||
|
||
fn build_date() -> String { | ||
use datetime::{LocalDateTime, ISO}; | ||
|
||
let now = LocalDateTime::now(); | ||
format!("{}", now.date().iso()) | ||
} | ||
|
||
fn write_statics() -> IOResult<()> { | ||
use std::fs::File; | ||
use std::io::Write; | ||
use std::path::PathBuf; | ||
|
||
let ver = match is_development_version() { | ||
true => format!("exa v{} ({} built on {})", cargo_version(), git_hash(), build_date()), | ||
false => format!("exa v{}", cargo_version()), | ||
}; | ||
|
||
let out = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
let mut f = File::create(&out.join("version_string.txt"))?; | ||
write!(f, "{:?}", ver) | ||
} |
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