aboutsummaryrefslogtreecommitdiff
path: root/build.rs
diff options
context:
space:
mode:
authorDaniel García <[email protected]>2019-02-10 15:46:51 +0100
committerDaniel García <[email protected]>2019-02-10 16:02:46 +0100
commit28d1588e73e4ae66cfb9104fd8bf1b1b1de00147 (patch)
treef8ef69086c57fe23c0c33f2b05deb7cef45df3a3 /build.rs
parentf3b1a5ff3eae1bb0f3e5b0e3628177805a6c4dfb (diff)
downloadvaultwarden-28d1588e73e4ae66cfb9104fd8bf1b1b1de00147.tar.gz
vaultwarden-28d1588e73e4ae66cfb9104fd8bf1b1b1de00147.zip
Show version in admin panel
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/build.rs b/build.rs
index 1a77b27b..e8b4c9a7 100644
--- a/build.rs
+++ b/build.rs
@@ -6,6 +6,10 @@ fn main() {
fn run(args: &[&str]) -> Result<String, std::io::Error> {
let out = Command::new(args[0]).args(&args[1..]).output()?;
+ if !out.status.success() {
+ use std::io::{Error, ErrorKind};
+ return Err(Error::new(ErrorKind::Other, "Command not successful"));
+ }
Ok(String::from_utf8(out.stdout).unwrap().trim().to_string())
}
@@ -13,8 +17,10 @@ fn run(args: &[&str]) -> Result<String, std::io::Error> {
fn read_git_info() -> Result<(), std::io::Error> {
// The exact tag for the current commit, can be empty when
// the current commit doesn't have an associated tag
- let exact_tag = run(&["git", "describe", "--abbrev=0", "--tags", "--exact-match"])?;
- println!("cargo:rustc-env=GIT_EXACT_TAG={}", exact_tag);
+ let exact_tag = run(&["git", "describe", "--abbrev=0", "--tags", "--exact-match"]).ok();
+ if let Some(ref exact) = exact_tag {
+ println!("cargo:rustc-env=GIT_EXACT_TAG={}", exact);
+ }
// The last available tag, equal to exact_tag when
// the current commit is tagged
@@ -27,13 +33,25 @@ fn read_git_info() -> Result<(), std::io::Error> {
// The current git commit hash
let rev = run(&["git", "rev-parse", "HEAD"])?;
- let rev_short = rev.get(..12).unwrap_or_default();
+ let rev_short = rev.get(..8).unwrap_or_default();
println!("cargo:rustc-env=GIT_REV={}", rev_short);
+ // Combined version
+ let version = if let Some(exact) = exact_tag {
+ exact
+ } else if &branch != "master" {
+ format!("{}-{} ({})", last_tag, rev_short, branch)
+ } else {
+ format!("{}-{}", last_tag, rev_short)
+ };
+ println!("cargo:rustc-env=GIT_VERSION={}", version);
+
// To access these values, use:
// env!("GIT_EXACT_TAG")
// env!("GIT_LAST_TAG")
// env!("GIT_BRANCH")
// env!("GIT_REV")
+ // env!("GIT_VERSION")
+
Ok(())
}