Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #9 from runabove/hash
Browse files Browse the repository at this point in the history
Hash
  • Loading branch information
d33d33 committed Jan 2, 2017
2 parents e919c50 + 615851c commit 319ed02
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Cargo
# will have compiled files and executables
/target/
version.rs

# These are backup files generated by rustfmt
**/*.rs.bk
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[package]

name = "beamium"
version = "1.0.1"
authors = [ "d33d33 <kevin@d33d33.fr>" ]
version = "1.0.2"
authors = [ "d33d33 <kevin.georges@corp.ovh.com>" ]

build = "build.rs"

[dependencies]
clap = "2.19.2"
Expand Down
30 changes: 30 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::process::Command;
use std::path::Path;
use std::fs::File;
use std::io::prelude::*;

fn main() {
let output = Command::new("git")
.arg("rev-parse")
.arg("HEAD")
.output()
.expect("failed to execute process");

let hash = String::from_utf8_lossy(&output.stdout);
let content = format!("static COMMIT: &'static str = {:?};\n", hash.trim());

let path = Path::new("./src/version.rs");

if path.exists() {
let mut f = File::open(path).expect("fail to open result.rs");
let mut current = String::new();
f.read_to_string(&mut current).expect("fail to read result.rs");

if current == content {
return
}
};

let mut out = File::create(path).unwrap();
out.write(content.as_bytes()).unwrap();
}
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ mod router;
mod sink;
mod log;

include!("version.rs");

static mut SIGINT: bool = false;

extern "C" fn handle_sigint(_: i32) {
Expand All @@ -51,7 +53,7 @@ fn main() {
log::bootstrap();

let matches = App::new("beamium")
.version(env!("CARGO_PKG_VERSION"))
.version(&*format!("{} ({})", env!("CARGO_PKG_VERSION"), COMMIT))
.author("d33d33 <kevin@d33d33.fr>")
.about("Send Prometheus metrics to Warp10")
.args_from_usage("-c, --config=[FILE] 'Sets a custom config file'
Expand Down

0 comments on commit 319ed02

Please sign in to comment.