Skip to content

Commit

Permalink
build: include version number in final binary
Browse files Browse the repository at this point in the history
Use git to parse the tag information, and include it in the output of
`exclave --help`.

Signed-off-by: Sean Cross <sean@xobs.io>
  • Loading branch information
xobs committed Oct 29, 2018
1 parent d272679 commit 49287f8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions build.rs
@@ -0,0 +1,28 @@
use std::process::Command;

/// Same as `set_env`, but using `name` as environment variable.
///
/// You can, for example, override the `CARGO_PKG_VERSION` using in
/// your `build.rs` script:
///
/// ```
/// extern crate git_version;
/// fn main() { git_version::set_env_with_name("CARGO_PKG_VERSION"); }
/// ```
fn set_env_with_name(name: &str) {
let cmd = Command::new("git")
.args(&["describe", "--tags", "--dirty=-modified"])
.output()
.unwrap();
assert!(cmd.status.success());
let ver = std::str::from_utf8(&cmd.stdout[..]).unwrap().trim();
println!("cargo:rustc-env={}={}", name, ver);
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/index");
println!("cargo:rerun-if-changed=.git");
println!("cargo:rerun-if-env-changed={}", name);
}

fn main() {
set_env_with_name("GIT_VERSION");
}
3 changes: 2 additions & 1 deletion src/main.rs
Expand Up @@ -44,7 +44,8 @@ fn main() {
}).expect("Error setting Ctrl-C handler");

let matches = App::new("Exclave Testing System")
.version("1.0")
.version(env!("CARGO_PKG_VERSION"))
.long_version(env!("GIT_VERSION"))
.author("Sean Cross <sean@xobs.io>")
.about("Orchestrates the Common Factory Test Interface server")
.arg(
Expand Down

0 comments on commit 49287f8

Please sign in to comment.