Ver Fonte

darkirc: append commit hash to --version output

darkfi há 1 ano atrás
pai
commit
29d613fab3
3 ficheiros alterados com 24 adições e 2 exclusões
  1. 13 0
      bin/darkirc/build.rs
  2. 5 1
      bin/darkirc/src/main.rs
  3. 6 1
      src/lib.rs

+ 13 - 0
bin/darkirc/build.rs

@@ -16,7 +16,20 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+use std::process::Command;
+
 fn main() {
+    let output = Command::new("git")
+        .args(["rev-parse", "--short", "HEAD"])
+        .output();
+
+    if let Ok(output) = output {
+        if output.status.success() {
+            let commitish = String::from_utf8_lossy(&output.stdout);
+            println!("cargo:rustc-env=COMMITISH={}", commitish.trim());
+        }
+    }
+
     if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "android" {
         println!("cargo:rustc-link-search={}/sqlcipher", env!("CARGO_MANIFEST_DIR"));
     }

+ 5 - 1
bin/darkirc/src/main.rs

@@ -66,7 +66,11 @@ fn panic_hook(panic_info: &std::panic::PanicHookInfo) {
 
 #[derive(Clone, Debug, Deserialize, StructOpt, StructOptToml)]
 #[serde(default)]
-#[structopt(name = "darkirc", about = cli_desc!())]
+#[structopt(
+    name = "darkirc",
+    about = cli_desc!(),
+    version = concat!(env!("CARGO_PKG_VERSION"), "-", env!("COMMITISH"))
+)]
 struct Args {
     #[structopt(short, parse(from_occurrences))]
     /// Increase verbosity (-vvv supported)

+ 6 - 1
src/lib.rs

@@ -63,10 +63,15 @@ pub const ANSI_LOGO: &str = include_str!("../contrib/darkfi.ansi");
 #[macro_export]
 macro_rules! cli_desc {
     () => {{
+        let commitish = match option_env!("COMMITISH") {
+            Some(c) => &format!("-{}", c),
+            None => ""
+        };
         let desc = format!(
-            "{} {}\n{}\n{}",
+            "{} {}\n{}{}\n{}",
             env!("CARGO_PKG_NAME").to_string(),
             env!("CARGO_PKG_VERSION").to_string(),
+            commitish,
             env!("CARGO_PKG_DESCRIPTION").to_string(),
             darkfi::ANSI_LOGO,
         );