Răsfoiți Sursa

Display solang commit in help and verbose output

Signed-off-by: Sean <sean@mess.org>
Sean 6 ani în urmă
părinte
comite
ab8fe4ed9d
2 a modificat fișierele cu 11 adăugiri și 1 ștergeri
  1. 6 0
      build.rs
  2. 5 1
      src/main.rs

+ 6 - 0
build.rs

@@ -1,8 +1,14 @@
 extern crate lalrpop;
+use std::process::Command;
 
 fn main() {
     lalrpop::Configuration::new()
         .generate_in_source_tree()
         .process()
         .unwrap();
+
+    // note: add error checking yourself.
+    let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().unwrap();
+    let git_hash = String::from_utf8(output.stdout).unwrap();
+    println!("cargo:rustc-env=GIT_HASH={}", git_hash);
 }

+ 5 - 1
src/main.rs

@@ -47,7 +47,7 @@ pub struct JsonResult {
 
 fn main() {
     let matches = App::new("solang")
-        .version(env!("CARGO_PKG_VERSION"))
+        .version(&*format!("commit {}", env!("GIT_HASH")))
         .author(env!("CARGO_PKG_AUTHORS"))
         .about(env!("CARGO_PKG_DESCRIPTION"))
         .arg(
@@ -123,6 +123,10 @@ fn main() {
     };
     let verbose = matches.is_present("VERBOSE");
 
+    if verbose {
+        eprintln!("info: Solang commit {}", env!("GIT_HASH"));
+    }
+
     for filename in matches.values_of("INPUT").unwrap() {
         let mut f = File::open(&filename).expect("file not found");